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

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 1 // 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 = 2; // activation value for FSM [lx]
  24. };
  25. stairway_param_t parameters;
  26. uint16_t idle_pwm_ist = parameters.idle_pwm_max;
  27. uint16_t idle_pwm_soll = 0;
  28. struct fsm_pending_inputs_t {
  29. bool anim_beendet = true;
  30. bool sensor_unten = false;
  31. bool sensor_oben = false;
  32. bool ldr_changed = false;
  33. };
  34. fsm_pending_inputs_t fsm_pend;
  35. struct dimmer_t {
  36. uint8_t stufe = 0;
  37. uint16_t ticks = 0;
  38. uint16_t tick = 0;
  39. float delta_pwm = 0.0;
  40. float pwm = 0.0;
  41. uint16_t start_pwm = 0;
  42. uint16_t ziel_pwm = 0;
  43. };
  44. enum dimmer_type_t { DIM_STUFEN = 0, DIM_LDR = 1 };
  45. dimmer_t dimmer_stufen;
  46. dimmer_t dimmer_ldr;
  47. // initialize with i2c-Address 0, use Wire Library
  48. PCA9685 pwmController;
  49. FSMTreppeModelClass FSMTreppe_Obj;
  50. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  51. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  52. enum fsm_status_t {
  53. ST_INAKTIV_LDR = 0,
  54. ST_AUFDIMMEN_LDR = 1,
  55. ST_ABDIMMEN_LDR = 2,
  56. ST_RUHEZUSTAND = 3,
  57. ST_AUFDIMMEN_HOCH = 4,
  58. ST_WARTEN_HOCH = 5,
  59. ST_ABDIMMEN_HOCH = 6,
  60. ST_AUFDIMMEN_RUNTER = 7,
  61. ST_WARTEN_RUNTER = 8,
  62. ST_ABDIMMEN_RUNTER = 9
  63. };
  64. enum fsm_laufrichtung_t { LR_RUNTER = 0, LR_HOCH = 1 };
  65. enum fsm_dimmrichtung_t { DR_ABDIMMEN = 0, DR_AUFDIMMEN = 1 };
  66. /* DIMM */
  67. // bool dimmer(dimmer_t* dimmer, bool dim_type);
  68. bool dimmer_tick(dimmer_t *dimmer, bool dim_type);
  69. void start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
  70. uint16_t off_pwm);
  71. // void berechne_dimmer(dimmer_t* dimmer, bool dim_type);
  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) { FSMTreppe_Obj.initialize(); }
  79. ~Treppe() { FSMTreppe_Obj.terminate(); }
  80. void setup();
  81. void task(); // call periodically
  82. // Parameter section
  83. void saveParam();
  84. void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  85. void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  86. void set_time_ldr(const uint16_t value);
  87. void set_time_per_stair(const uint16_t value);
  88. void set_ldr_schwelle(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
  89. };
  90. #endif // __TREPPE_H