Browse Source

struct for treppe parameters ->eeprom

tags/v1.0.0
Dominik Bartsch 3 years ago
parent
commit
42a927e383
2 changed files with 26 additions and 19 deletions
  1. 14
    12
      lib/treppe/treppe.cpp
  2. 12
    7
      lib/treppe/treppe.h

+ 14
- 12
lib/treppe/treppe.cpp View File

else else
dimmer->stufe = stufen - 1; dimmer->stufe = stufen - 1;


dimmer->ticks = time_per_stair / INT_TIME; // [ms]
dimmer->ticks = parameters.time_per_stair / INT_TIME; // [ms]
} }
else { // DIM_LDR else { // DIM_LDR
dimmer->ticks = time_ldr / INT_TIME; // [ms]
dimmer->ticks = parameters.time_ldr / INT_TIME; // [ms]
} }


if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN) if (fsm_outputs.dimmrichtung == DR_AUFDIMMEN)
// follow up: averaging over many samples? // follow up: averaging over many samples?
float ldr = read_ldr(); float ldr = read_ldr();


if (ldr < ldr_schwelle) {
if (ldr < parameters.ldr_schwelle) {
active = 1; active = 1;
} }
if (ldr > ldr_schwelle + LDR_HYS) {
if (ldr > parameters.ldr_schwelle + LDR_HYS) {
active = 0; active = 0;
} }
return active; return active;
fsm_outputs.status == ST_ABDIMMEN_RUNTER ) fsm_outputs.status == ST_ABDIMMEN_RUNTER )
{ {
if(fsm_pend.anim_beendet) if(fsm_pend.anim_beendet)
start_animation(&dimmer_stufen, DIM_STUFEN, active_pwm, idle_pwm_ist);
start_animation(&dimmer_stufen, DIM_STUFEN, parameters.active_pwm, idle_pwm_ist);
else else
fsm_pend.anim_beendet = dimmer_tick(&dimmer_stufen, DIM_STUFEN); fsm_pend.anim_beendet = dimmer_tick(&dimmer_stufen, DIM_STUFEN);
} }


void Treppe::set_idle_prozent(const int prozent) void Treppe::set_idle_prozent(const int prozent)
{ {
uint16_t new_pwm = active_pwm * prozent / 100;
// future use: parameters.idle_max_pwm
uint16_t new_pwm = parameters.active_pwm * prozent / 100;
set_idle_pwm_max(new_pwm); set_idle_pwm_max(new_pwm);
} }


void Treppe::set_idle_pwm_max(const uint16_t new_pwm) void Treppe::set_idle_pwm_max(const uint16_t new_pwm)
{ {
if(new_pwm > active_pwm) {
idle_pwm_soll = active_pwm;
// future use: parameters.idle_max_pwm
if(new_pwm > parameters.active_pwm) {
idle_pwm_soll = parameters.active_pwm;
} else { } else {
idle_pwm_soll = new_pwm; idle_pwm_soll = new_pwm;
} }


void Treppe::set_active_pwm(uint16_t _active_pwm) void Treppe::set_active_pwm(uint16_t _active_pwm)
{ {
active_pwm = _active_pwm;
Serial.printf("Treppe: active_pwm=%d\n", active_pwm);
parameters.active_pwm = _active_pwm;
Serial.printf("Treppe: active_pwm=%d\n", parameters.active_pwm);
} }
void Treppe::set_time_per_stair(uint16_t _time_per_stair) void Treppe::set_time_per_stair(uint16_t _time_per_stair)
{ {
time_per_stair = _time_per_stair;
Serial.printf("Treppe: time_per_stair=%d\n", time_per_stair);
parameters.time_per_stair = _time_per_stair;
Serial.printf("Treppe: time_per_stair=%d\n", parameters.time_per_stair);
} }

+ 12
- 7
lib/treppe/treppe.h View File

class Treppe { class Treppe {
private: private:
const uint8_t stufen; const uint8_t stufen;
const uint16_t time_ldr = 500;
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
uint16_t idle_pwm_max = 100;
uint16_t idle_pwm_ist = idle_pwm_max;
uint16_t idle_pwm_soll = 0;
uint16_t active_pwm = 2000;


uint16_t ldr_schwelle = 2; // activation value for FSM [lx]
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 = 2; // activation value for FSM [lx]
};
stairway_param_t parameters;

uint16_t idle_pwm_ist = parameters.idle_pwm_max;
uint16_t idle_pwm_soll = 0;
struct fsm_pending_inputs_t { struct fsm_pending_inputs_t {
bool anim_beendet = true; bool anim_beendet = true;
bool sensor_unten = false; bool sensor_unten = false;

Loading…
Cancel
Save