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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef __TREPPE_H
  2. #define __TREPPE_H
  3. #include "FSMTreppe3/FSMTreppe3.h"
  4. #include "PCA9685.h"
  5. // #define LDRDEBUG // comment in to override LDR measurement
  6. #define LDR_HYS 1 // Hysteresis for switching off FSM [lux]
  7. #define SENSOR_OBEN 16
  8. #define SENSOR_UNTEN 12
  9. #define OE 14
  10. #define INT_TIME 20 // interrupt intervall [ms]
  11. class Treppe {
  12. private:
  13. const uint8_t stufen;
  14. const uint16_t time_ldr = 300;
  15. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  16. uint16_t idle_pwm_max = 100;
  17. uint16_t idle_pwm_ist = 0;
  18. uint16_t idle_pwm_soll = 0;
  19. uint16_t active_pwm = 700;
  20. uint16_t ldr_schwelle = 2; // activation value for FSM [lx]
  21. bool anim_beendet = true;
  22. struct dimmer_stufe_t {
  23. uint8_t stufe = 0;
  24. uint16_t ticks = 0;
  25. uint16_t tick = 0;
  26. float delta_pwm = 0.0;
  27. float pwm = 0.0;
  28. uint16_t start_pwm = 0;
  29. uint16_t ziel_pwm = 0;
  30. };
  31. dimmer_stufe_t dimmer_stufe;
  32. struct dimmer_ldr_t {
  33. uint16_t ticks = 0;
  34. uint16_t tick = 0;
  35. float delta_pwm = 0.0;
  36. float pwm = 0.0;
  37. uint16_t start_pwm = 0;
  38. uint16_t ziel_pwm = 0;
  39. };
  40. dimmer_ldr_t dimmer_ldr;
  41. // initialize with i2c-Address 0, use Wire Library
  42. PCA9685 pwmController;
  43. FSMTreppeModelClass FSMTreppe_Obj;
  44. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  45. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  46. enum fsm_status_t {
  47. ST_INAKTIV_LDR =0,
  48. ST_AUFDIMMEN_LDR =1,
  49. ST_ABDIMMEN_LDR =2,
  50. ST_RUHEZUSTAND =3,
  51. ST_AUFDIMMEN_HOCH =4,
  52. ST_WARTEN_HOCH =5,
  53. ST_ABDIMMEN_HOCH =6,
  54. ST_AUFDIMMEN_RUNTER =7,
  55. ST_WARTEN_RUNTER =8,
  56. ST_ABDIMMEN_RUNTER =9
  57. };
  58. enum fsm_laufrichtung_t {
  59. LR_RUNTER=0,
  60. LR_HOCH=1
  61. };
  62. enum fsm_dimmrichtung_t {
  63. DR_ABDIMMEN=0,
  64. DR_AUFDIMMEN=1
  65. };
  66. /* DIMM */
  67. bool dimm_stufe(uint8_t stufe);
  68. bool dimm_treppe();
  69. void anim_tick();
  70. void start_animation();
  71. void berechne_dimmer();
  72. void print_state_on_change();
  73. /* LDR */
  74. bool read_sensor(int sensor);
  75. float read_ldr();
  76. bool check_ldr();
  77. public:
  78. Treppe(uint8_t _stufen) : stufen(_stufen){
  79. FSMTreppe_Obj.initialize();
  80. berechne_dimmer();
  81. }
  82. ~Treppe() {
  83. FSMTreppe_Obj.terminate();
  84. }
  85. void setup();
  86. void task(); // call periodically
  87. // Parameter section
  88. void set_idle_prozent(int prozent);
  89. void set_idle_pwm_max(const uint16_t new_pwm);
  90. void activate_idle_pwm(bool active);
  91. void set_active_pwm(uint16_t _active_pwm);
  92. void set_time_per_stair(uint16_t _time_per_stair);
  93. };
  94. #endif // __TREPPE_H