ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

treppe.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef __TREPPE_H
  2. #define __TREPPE_H
  3. #include "FSMTreppe3/FSMTreppe3.h"
  4. #include "PCA9685.h"
  5. #include <EEPROM.h>
  6. //#define LDRDEBUG // comment in to override LDR measurement
  7. #define LDR_HYS 8 // Hysteresis for switching off FSM [lux]
  8. #define SENSOR_OBEN 16
  9. #define SENSOR_UNTEN 12
  10. #define OE 14
  11. #define INT_TIME 20 // interrupt intervall [ms]
  12. #define TIME_MS_MAX 5000 // maximum time for animation [ms]
  13. enum vorgabe_typ_t { VORGABE_PROZENT = 0, VORGABE_12BIT = 1 };
  14. #define EEP_START_ADDR 100 // define Start Address for "EEPROM" storage -> depends on size of "wifi_data"!
  15. class Treppe {
  16. private:
  17. const uint8_t stufen;
  18. struct stairway_param_t {
  19. uint16_t time_ldr = 500;
  20. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  21. uint16_t idle_pwm_max = 100;
  22. uint16_t active_pwm = 2000;
  23. uint16_t ldr_schwelle = 30; // activation value for FSM [lx]
  24. };
  25. stairway_param_t param;
  26. stairway_param_t param_pend; // zwischenspeicher änderungen
  27. bool param_changed = false;
  28. uint16_t idle_pwm_ist = param.idle_pwm_max;
  29. uint16_t idle_pwm_soll = 0;
  30. struct fsm_pending_inputs_t {
  31. bool anim_beendet = true;
  32. bool sensor_unten = false;
  33. bool last_s_unten = false;
  34. bool web_ctrl_s_unten = false;
  35. bool sensor_oben = false;
  36. bool last_s_oben = false;
  37. bool web_ctrl_s_oben = false;
  38. bool ldr_changed = false;
  39. };
  40. fsm_pending_inputs_t fsm_pend;
  41. struct dimmer_t {
  42. uint8_t stufe = 0;
  43. uint16_t ticks = 0;
  44. uint16_t tick = 0;
  45. float delta_pwm = 0.0;
  46. float pwm = 0.0;
  47. uint16_t start_pwm = 0;
  48. uint16_t ziel_pwm = 0;
  49. };
  50. enum dimmer_type_t { DIM_STUFEN = 0, DIM_LDR = 1 };
  51. dimmer_t dimmer_stufen;
  52. dimmer_t dimmer_ldr;
  53. // initialize with i2c-Address 0, use Wire Library
  54. PCA9685 pwmController;
  55. FSMTreppeModelClass FSMTreppe_Obj;
  56. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  57. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  58. enum fsm_status_t {
  59. ST_INAKTIV_LDR = 0,
  60. ST_AUFDIMMEN_LDR = 1,
  61. ST_ABDIMMEN_LDR = 2,
  62. ST_RUHEZUSTAND = 3,
  63. ST_AUFDIMMEN_HOCH = 4,
  64. ST_WARTEN_HOCH = 5,
  65. ST_ABDIMMEN_HOCH = 6,
  66. ST_AUFDIMMEN_RUNTER = 7,
  67. ST_WARTEN_RUNTER = 8,
  68. ST_ABDIMMEN_RUNTER = 9
  69. };
  70. enum fsm_laufrichtung_t { LR_RUNTER = 0, LR_HOCH = 1 };
  71. enum fsm_dimmrichtung_t { DR_ABDIMMEN = 0, DR_AUFDIMMEN = 1 };
  72. void read_sensors();
  73. void print_state_on_change();
  74. /* DIMM */
  75. bool dimmer_tick(dimmer_t *dimmer, bool dim_type);
  76. void start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
  77. uint16_t off_pwm);
  78. /* LDR */
  79. bool read_sensor(int sensor);
  80. float read_ldr();
  81. bool check_ldr();
  82. public:
  83. Treppe(uint8_t _stufen) : stufen(_stufen) { FSMTreppe_Obj.initialize(); }
  84. ~Treppe() { FSMTreppe_Obj.terminate(); }
  85. void setup();
  86. void task(); // call periodically
  87. // Parameter section
  88. void save_param_to_eeprom();
  89. void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  90. void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  91. void set_time_ldr(const uint16_t value);
  92. void set_time_per_stair(const uint16_t value);
  93. void set_ldr_schwelle(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  94. void overwrite_sensors(bool s_oben, bool s_unten);
  95. };
  96. #endif // __TREPPE_H