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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef __TREPPE_H
  2. #define __TREPPE_H
  3. #include "FSMTreppe2/FSMTreppe2.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. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  15. uint16_t idle_pwm = 100;
  16. uint16_t idle_pwm_internal = 0;
  17. uint16_t active_pwm = 700;
  18. uint16_t ldr_schwelle = 2; // activation value for FSM [lx]
  19. uint16_t start_pwm = 0;
  20. uint16_t ziel_pwm = 0;
  21. bool anim_beendet = true;
  22. uint8_t stufe = 0;
  23. uint16_t current_tick = 0;
  24. float current_pwm = 0.0;
  25. uint16_t ticks_pro_stufe = 0;
  26. float differenz_pwm_pro_tick = 0.0;
  27. // initialize with i2c-Address 0, use Wire Library
  28. PCA9685 pwmController;
  29. FSMTreppeModelClass FSMTreppe_Obj;
  30. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  31. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  32. enum fsm_status_t {
  33. // 2.0
  34. ST_INAKTIV_LDR =0,
  35. ST_RUHEZUSTAND =1,
  36. ST_AUFDIMMEN_HOCH =2,
  37. ST_WARTEN_HOCH =3,
  38. ST_ABDIMMEN_HOCH =4,
  39. ST_AUFDIMMEN_RUNTER =5,
  40. ST_WARTEN_RUNTER =6,
  41. ST_ABDIMMEN_RUNTER =7
  42. // 3.0
  43. // ST_INAKTIV_LDR =0,
  44. // ST_AUFDIMMEN_LDR =1,
  45. // ST_ABDIMMEN_LDR =2,
  46. // ST_RUHEZUSTAND =3,
  47. // ST_AUFDIMMEN_HOCH =4,
  48. // ST_WARTEN_HOCH =5,
  49. // ST_ABDIMMEN_HOCH =6,
  50. // ST_AUFDIMMEN_RUNTER =7,
  51. // ST_WARTEN_RUNTER =8,
  52. // ST_ABDIMMEN_RUNTER =9
  53. };
  54. enum fsm_laufrichtung_t {
  55. LR_RUNTER=0,
  56. LR_HOCH=1
  57. };
  58. enum fsm_dimmrichtung_t {
  59. DR_ABDIMMEN=0,
  60. DR_AUFDIMMEN=1
  61. };
  62. /* DIMM */
  63. bool dimm_stufe(uint8_t stufe);
  64. bool dimm_treppe();
  65. void anim_tick();
  66. void start_animation();
  67. void berechne_dimmer();
  68. void print_state_on_change();
  69. /* LDR */
  70. bool read_sensor(int sensor);
  71. float read_ldr();
  72. bool check_ldr();
  73. public:
  74. Treppe(uint8_t _stufen) : stufen(_stufen){
  75. FSMTreppe_Obj.initialize();
  76. berechne_dimmer();
  77. }
  78. ~Treppe() {
  79. FSMTreppe_Obj.terminate();
  80. }
  81. void setup();
  82. void task(); // call periodically
  83. // Parameter section
  84. void set_idle_prozent(int prozent);
  85. void set_idle_pwm(uint16_t _idle_pwm);
  86. void activate_idle_pwm(bool active);
  87. void set_active_pwm(uint16_t _active_pwm);
  88. void set_time_per_stair(uint16_t _time_per_stair);
  89. };
  90. #endif // __TREPPE_H