change read sensors, trigger via web possible, modify js to fetch with HTTP_POST
This commit is contained in:
+33
-29
@@ -27,8 +27,7 @@ bool Treppe::dimmer_tick(dimmer_t *dimmer, bool dim_type) {
|
||||
Serial.printf("DIM_LDR: start: %d, ziel: %d\n", dimmer->start_pwm,
|
||||
dimmer->ziel_pwm);
|
||||
return true;
|
||||
} else // DIM_STUFEN
|
||||
{
|
||||
} else { // DIM_STUFEN
|
||||
Serial.printf("DIM_STUFEN: stufe: %d, start: %d, ziel: %d\n",
|
||||
dimmer->stufe, dimmer->start_pwm, dimmer->ziel_pwm);
|
||||
|
||||
@@ -36,8 +35,7 @@ bool Treppe::dimmer_tick(dimmer_t *dimmer, bool dim_type) {
|
||||
if (dimmer->stufe >= stufen - 1)
|
||||
return true;
|
||||
dimmer->stufe++;
|
||||
} else // LR_RUNTER
|
||||
{
|
||||
} else { // LR_RUNTER
|
||||
if (dimmer->stufe <= 0)
|
||||
return true;
|
||||
dimmer->stufe--;
|
||||
@@ -108,33 +106,38 @@ void Treppe::print_state_on_change() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Treppe::read_sensor(int sensor) {
|
||||
void Treppe::overwrite_sensors(bool s_oben, bool s_unten) {
|
||||
fsm_pend.web_ctrl_s_oben = s_oben;
|
||||
fsm_pend.web_ctrl_s_unten = s_unten;
|
||||
}
|
||||
|
||||
/*
|
||||
reads sensors with edge detection
|
||||
void Treppe::read_sensors() {
|
||||
const bool s_oben = digitalRead(SENSOR_OBEN);
|
||||
const bool s_unten = digitalRead(SENSOR_UNTEN);
|
||||
|
||||
returns true if motion was detected
|
||||
returns false if no motion was detected
|
||||
returns false if motion was detected, but state did not change back to not
|
||||
detected
|
||||
*/
|
||||
uint8_t pegel = digitalRead(sensor);
|
||||
static uint8_t pegel_alt[2] = {0, 0};
|
||||
fsm_pend.sensor_oben = false;
|
||||
fsm_pend.sensor_unten = false;
|
||||
|
||||
uint8_t index = 0;
|
||||
if (sensor == SENSOR_OBEN)
|
||||
index = 0;
|
||||
else
|
||||
index = 1;
|
||||
// rising trigger => 1 cycle true !
|
||||
if (s_oben && !fsm_pend.last_s_oben) {
|
||||
fsm_pend.sensor_oben = true;
|
||||
}
|
||||
if (s_unten && !fsm_pend.last_s_unten) {
|
||||
fsm_pend.sensor_unten = true;
|
||||
}
|
||||
|
||||
if (pegel == 1 && pegel_alt[index] == 0) {
|
||||
pegel_alt[index] = pegel;
|
||||
return true;
|
||||
} else {
|
||||
pegel_alt[index] = pegel;
|
||||
return false;
|
||||
fsm_pend.last_s_oben = s_oben;
|
||||
fsm_pend.last_s_unten = s_unten;
|
||||
|
||||
// check for manipulation over webserver
|
||||
if(fsm_pend.web_ctrl_s_oben) {
|
||||
fsm_pend.sensor_oben = true;
|
||||
fsm_pend.web_ctrl_s_oben = false;
|
||||
}
|
||||
if(fsm_pend.web_ctrl_s_unten) {
|
||||
fsm_pend.sensor_unten = true;
|
||||
fsm_pend.web_ctrl_s_unten = false;
|
||||
}
|
||||
// return static_cast<bool>(pegel);
|
||||
}
|
||||
|
||||
float Treppe::read_ldr() {
|
||||
@@ -201,7 +204,6 @@ void Treppe::task() {
|
||||
|
||||
// TODO wenn LDR geändert => idle_pwm_soll anpassen
|
||||
// fsm_pend.ldr_changed = true;
|
||||
|
||||
fsm_inputs.ldr_schwelle = check_ldr();
|
||||
|
||||
#ifdef DEBUG_TIMING
|
||||
@@ -210,8 +212,10 @@ void Treppe::task() {
|
||||
m = micros();
|
||||
#endif
|
||||
|
||||
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
||||
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
|
||||
read_sensors();
|
||||
fsm_inputs.sensor_oben = fsm_pend.sensor_oben;
|
||||
fsm_inputs.sensor_unten = fsm_pend.sensor_unten;
|
||||
|
||||
fsm_inputs.anim_beendet = fsm_pend.anim_beendet;
|
||||
|
||||
#ifdef DEBUG_TIMING
|
||||
|
||||
+9
-3
@@ -38,7 +38,11 @@ private:
|
||||
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;
|
||||
@@ -77,13 +81,13 @@ private:
|
||||
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(dimmer_t* dimmer, bool dim_type);
|
||||
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);
|
||||
// void berechne_dimmer(dimmer_t* dimmer, bool dim_type);
|
||||
void print_state_on_change();
|
||||
|
||||
/* LDR */
|
||||
bool read_sensor(int sensor);
|
||||
@@ -105,6 +109,8 @@ public:
|
||||
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
|
||||
Reference in New Issue
Block a user