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.8KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 = 500;
  15. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  16. uint16_t idle_pwm_max = 100;
  17. uint16_t idle_pwm_ist = idle_pwm_max;
  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. struct fsm_pending_inputs_t {
  22. bool anim_beendet = true;
  23. bool sensor_unten = false;
  24. bool sensor_oben = false;
  25. bool ldr_changed = false;
  26. };
  27. fsm_pending_inputs_t fsm_pend;
  28. struct dimmer_t {
  29. uint8_t stufe = 0;
  30. uint16_t ticks = 0;
  31. uint16_t tick = 0;
  32. float delta_pwm = 0.0;
  33. float pwm = 0.0;
  34. uint16_t start_pwm = 0;
  35. uint16_t ziel_pwm = 0;
  36. };
  37. enum dimmer_type_t {
  38. DIM_STUFEN=0,
  39. DIM_LDR=1
  40. };
  41. dimmer_t dimmer_stufen;
  42. dimmer_t dimmer_ldr;
  43. // initialize with i2c-Address 0, use Wire Library
  44. PCA9685 pwmController;
  45. FSMTreppeModelClass FSMTreppe_Obj;
  46. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  47. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  48. enum fsm_status_t {
  49. ST_INAKTIV_LDR =0,
  50. ST_AUFDIMMEN_LDR =1,
  51. ST_ABDIMMEN_LDR =2,
  52. ST_RUHEZUSTAND =3,
  53. ST_AUFDIMMEN_HOCH =4,
  54. ST_WARTEN_HOCH =5,
  55. ST_ABDIMMEN_HOCH =6,
  56. ST_AUFDIMMEN_RUNTER =7,
  57. ST_WARTEN_RUNTER =8,
  58. ST_ABDIMMEN_RUNTER =9
  59. };
  60. enum fsm_laufrichtung_t {
  61. LR_RUNTER=0,
  62. LR_HOCH=1
  63. };
  64. enum fsm_dimmrichtung_t {
  65. DR_ABDIMMEN=0,
  66. DR_AUFDIMMEN=1
  67. };
  68. /* DIMM */
  69. // bool dimmer(dimmer_t* dimmer, bool dim_type);
  70. bool dimmer_tick(dimmer_t* dimmer, bool dim_type);
  71. void start_animation(dimmer_t* dimmer, bool dim_type,
  72. uint16_t on_pwm, uint16_t off_pwm);
  73. // void berechne_dimmer(dimmer_t* dimmer, bool dim_type);
  74. void print_state_on_change();
  75. /* LDR */
  76. bool read_sensor(int sensor);
  77. float read_ldr();
  78. bool check_ldr();
  79. public:
  80. Treppe(uint8_t _stufen) : stufen(_stufen){
  81. FSMTreppe_Obj.initialize();
  82. }
  83. ~Treppe() {
  84. FSMTreppe_Obj.terminate();
  85. }
  86. void setup();
  87. void task(); // call periodically
  88. // Parameter section
  89. void set_idle_prozent(int prozent);
  90. void set_idle_pwm_max(const uint16_t new_pwm);
  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