|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #ifndef __TREPPE_H
- #define __TREPPE_H
-
- #include "FSMTreppe3/FSMTreppe3.h"
- #include "PCA9685.h"
- #include <EEPROM.h>
-
- //#define LDRDEBUG // comment in to override LDR measurement
- #define LDR_HYS 8 // Hysteresis for switching off FSM [lux]
-
- #define SENSOR_OBEN 16
- #define SENSOR_UNTEN 12
- #define OE 14
-
- #define INT_TIME 20 // interrupt intervall [ms]
- #define TIME_MS_MAX 5000 // maximum time for animation [ms]
-
- enum vorgabe_typ_t { VORGABE_PROZENT = 0, VORGABE_12BIT = 1 };
-
- #define EEP_START_ADDR 100 // define Start Address for "EEPROM" storage -> depends on size of "wifi_data"!
-
- class Treppe {
- private:
- const uint8_t stufen;
-
- struct stairway_param_t {
- uint16_t time_ldr = 500;
- uint16_t time_per_stair = 300; // dimmtime per stair [ms]
- uint16_t idle_pwm_max = 100;
- uint16_t active_pwm = 2000;
- uint16_t ldr_schwelle = 30; // activation value for FSM [lx]
- };
- stairway_param_t param;
- stairway_param_t param_pend; // zwischenspeicher änderungen
- bool param_changed = false;
-
- uint16_t idle_pwm_ist = param.idle_pwm_max;
- uint16_t idle_pwm_soll = 0;
-
- struct fsm_pending_inputs_t {
- bool anim_beendet = true;
- bool sensor_unten = false;
- bool last_s_unten = false;
- bool web_ctrl_s_unten = false;
- bool sensor_oben = false;
- bool last_s_oben = false;
- bool web_ctrl_s_oben = false;
- bool ldr_changed = false;
- };
- fsm_pending_inputs_t fsm_pend;
-
- struct dimmer_t {
- uint8_t stufe = 0;
- uint16_t ticks = 0;
- uint16_t tick = 0;
-
- float delta_pwm = 0.0;
- float pwm = 0.0;
- uint16_t start_pwm = 0;
- uint16_t ziel_pwm = 0;
- };
- enum dimmer_type_t { DIM_STUFEN = 0, DIM_LDR = 1 };
- dimmer_t dimmer_stufen;
- dimmer_t dimmer_ldr;
-
- // initialize with i2c-Address 0, use Wire Library
- PCA9685 pwmController;
- FSMTreppeModelClass FSMTreppe_Obj;
- FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
- FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
- enum fsm_status_t {
- ST_INAKTIV_LDR = 0,
- ST_AUFDIMMEN_LDR = 1,
- ST_ABDIMMEN_LDR = 2,
- ST_RUHEZUSTAND = 3,
- ST_AUFDIMMEN_HOCH = 4,
- ST_WARTEN_HOCH = 5,
- ST_ABDIMMEN_HOCH = 6,
- ST_AUFDIMMEN_RUNTER = 7,
- ST_WARTEN_RUNTER = 8,
- ST_ABDIMMEN_RUNTER = 9
- };
- enum fsm_laufrichtung_t { LR_RUNTER = 0, LR_HOCH = 1 };
- enum fsm_dimmrichtung_t { DR_ABDIMMEN = 0, DR_AUFDIMMEN = 1 };
-
- void read_sensors();
- void print_state_on_change();
-
- /* DIMM */
- bool dimmer_tick(dimmer_t *dimmer, bool dim_type);
- void start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
- uint16_t off_pwm);
-
- /* LDR */
- bool read_sensor(int sensor);
- float read_ldr();
- bool check_ldr();
-
- public:
- Treppe(uint8_t _stufen) : stufen(_stufen) { FSMTreppe_Obj.initialize(); }
- ~Treppe() { FSMTreppe_Obj.terminate(); }
-
- void setup();
- void task(); // call periodically
-
- // Parameter section
- void save_param_to_eeprom();
- void param_to_json(char* json_str, size_t sz);
-
- void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
- void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
-
- void set_time_ldr(const uint16_t value);
- void set_time_per_stair(const uint16_t value);
- void set_ldr_schwelle(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
-
- void overwrite_sensors(bool s_oben, bool s_unten);
- };
-
- #endif // __TREPPE_H
|