ESP8266_Treppenlicht/lib/treppe/treppe.h

84 lines
2.1 KiB
C
Raw Normal View History

2021-06-23 19:23:31 +00:00
#pragma once
2021-07-03 15:46:31 +00:00
#include "FSMTreppe2/FSMTreppe2.h"
2021-06-23 19:23:31 +00:00
#include "PCA9685.h"
// #define LDRDEBUG // comment in to override LDR measurement
#define LDR_HYS 5.0 // Hysteresis for switching off FSM [lux]
#define SENSOR_OBEN 2
#define SENSOR_UNTEN 12
2021-06-28 13:47:10 +00:00
#define OE 14
2021-06-25 17:23:02 +00:00
2021-07-03 09:21:18 +00:00
#define INT_TIME 20 // interrupt intervall [ms]
2021-06-25 17:23:02 +00:00
2021-06-23 19:23:31 +00:00
class Treppe {
2021-06-25 02:53:06 +00:00
private:
const uint8_t stufen;
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
2021-07-03 16:10:30 +00:00
uint16_t idle_brightness = 0;
uint16_t active_brightness = 500;
2021-06-23 19:23:31 +00:00
uint16_t ldr_schwelle = 7; // activation value for FSM [lx]
uint16_t start_pwm = 0;
uint16_t ziel_pwm = 0;
bool anim_beendet = true;
uint8_t stufe = 0;
uint16_t current_tick = 0;
float current_pwm = 0.0;
uint16_t ticks_pro_stufe = 0;
2021-06-25 02:53:06 +00:00
float differenz_pwm_pro_tick = 0.0;
bool dimm_stufe(uint8_t stufe);
void anim_tick();
void start_animation();
void berechne_dimmer();
2021-06-25 19:10:07 +00:00
// 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;
void print_state_on_change();
2021-07-03 16:10:30 +00:00
enum fsm_status_t {
ST_INAKTIV_LDR =0,
ST_RUHEZUSTAND =1,
ST_AUFDIMMEN_HOCH =2,
ST_WARTEN_HOCH =3,
ST_ABDIMMEN_HOCH =4,
ST_AUFDIMMEN_RUNTER =5,
ST_WARTEN_RUNTER =6,
ST_ABDIMMEN_RUNTER =7
};
enum fsm_laufrichtung_t {
LR_RUNTER=0,
LR_HOCH=1
};
enum fsm_dimmrichtung_t {
DR_ABDIMMEN=0,
DR_AUFDIMMEN=1
};
bool read_sensor(int sensor);
float read_ldr();
bool check_ldr();
2021-06-25 02:53:06 +00:00
public:
Treppe(uint8_t _stufen) : stufen(_stufen){
FSMTreppe_Obj.initialize();
berechne_dimmer();
2021-06-25 02:53:06 +00:00
}
~Treppe() {
FSMTreppe_Obj.terminate();
}
2021-06-25 16:35:16 +00:00
2021-06-23 19:23:31 +00:00
void setup();
2021-06-25 19:10:07 +00:00
void task(); // call periodically
2021-06-23 19:23:31 +00:00
// Parameter section
void set_idle_pwm(uint16_t _idle_brightness);
void set_active_pwm(uint16_t _active_brightness);
void set_time_per_stair(uint16_t _time_per_stair);
2021-06-23 19:23:31 +00:00
};