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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "FSMTreppe/FSMTreppe2.h"
  3. #include "PCA9685.h"
  4. #define SENSOR_OBEN 2
  5. #define SENSOR_UNTEN 12
  6. #define OE 14
  7. #define INT_TIME 20 // interrupt intervall [ms]
  8. class Treppe {
  9. private:
  10. uint8_t stairs;
  11. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  12. uint16_t idle_brightness = 100;
  13. uint16_t active_brightness = 300;
  14. uint8_t direction = 0;
  15. uint8_t switch_direction = 0;
  16. uint8_t state = 0;
  17. uint8_t switch_state = 0;
  18. bool finish = 1;
  19. // alternative
  20. uint32_t tick = 0;
  21. uint32_t stufe = 0;
  22. uint8_t an_aus = 0;
  23. uint32_t ticks_treppe = 0;
  24. uint32_t ticks_pro_stufe = 0;
  25. float differenz_pwm_pro_tick = 0.0;
  26. // alternative
  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. void print_state_on_change();
  33. const uint8_t FSMTreppe_IN_animation_down = 1U;
  34. const uint8_t FSMTreppe_IN_animation_up = 2U;
  35. const uint8_t FSMTreppe_IN_idle = 3U;
  36. uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
  37. void ledsequence();
  38. void rampe();
  39. bool read_sensor(int sensor) {
  40. int pegel = digitalRead(sensor);
  41. return static_cast<bool>(pegel);
  42. }
  43. public:
  44. Treppe(uint8_t _stairs) : stairs(_stairs){
  45. FSMTreppe_Obj.initialize();
  46. ticks_pro_stufe = time_per_stair / 20; // [ms]
  47. ticks_treppe = ticks_pro_stufe * stairs;
  48. differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
  49. / (float) ticks_pro_stufe;
  50. }
  51. ~Treppe() {
  52. FSMTreppe_Obj.terminate();
  53. }
  54. void setup();
  55. void task(); // call periodically
  56. // Parameter section
  57. uint16_t setIdle(uint16_t _idle_brightness);
  58. uint16_t setActive(uint16_t _active_brightness);
  59. uint16_t setTime(uint16_t _time_per_stair);
  60. void setTick(uint32_t _tick) {
  61. tick = _tick;
  62. Serial.printf("Treppe: Tick: %u!\n", tick);
  63. }
  64. uint32_t getTicks() {
  65. return ticks_treppe;
  66. }
  67. // Runtime Parameter section
  68. void setDirection(uint8_t _direction);
  69. void setState(uint8_t _state);
  70. void setAnAus(uint8_t _an_aus) {
  71. an_aus = _an_aus;
  72. }
  73. uint8_t getState() { return state;};
  74. uint8_t getFinished() { return finish;};
  75. uint8_t getDirection() {return direction;};
  76. };