changed pwm setters and httpserver call
This commit is contained in:
parent
42a927e383
commit
ad21d73fbb
@ -42,9 +42,19 @@ void HTTPServer::start_apps() {
|
|||||||
if (args()) {
|
if (args()) {
|
||||||
for (int i = 0; i < args() - 1; i++) {
|
for (int i = 0; i < args() - 1; i++) {
|
||||||
Serial.printf("%s=%s\n", argName(i).c_str(), arg(i).c_str());
|
Serial.printf("%s=%s\n", argName(i).c_str(), arg(i).c_str());
|
||||||
if (argName(i).equals("range_idl_pwm")) {
|
|
||||||
treppe->set_idle_prozent(arg(i).toInt());
|
if (argName(i).equals("range_act_pwm")) {
|
||||||
|
treppe->set_active_pwm(arg(i).toInt(), VORGABE_PROZENT);
|
||||||
}
|
}
|
||||||
|
else if (argName(i).equals("range_idl_pwm")) {
|
||||||
|
treppe->set_idle_pwm_max(arg(i).toInt(), VORGABE_PROZENT);
|
||||||
|
}
|
||||||
|
else if (argName(i).equals("range_tim_sta")) {
|
||||||
|
}
|
||||||
|
else if (argName(i).equals("range_tim_on")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
send(200, "text/plain", "accepted");
|
send(200, "text/plain", "accepted");
|
||||||
|
@ -5,42 +5,38 @@
|
|||||||
- dimmer_tick: increment pwm jeden tick, bis anim beendet
|
- dimmer_tick: increment pwm jeden tick, bis anim beendet
|
||||||
- return: fsm_pend.anim_beendet
|
- return: fsm_pend.anim_beendet
|
||||||
*/
|
*/
|
||||||
bool Treppe::dimmer_tick(dimmer_t* dimmer, bool dim_type)
|
bool Treppe::dimmer_tick(dimmer_t *dimmer, bool dim_type) {
|
||||||
{
|
|
||||||
dimmer->pwm += dimmer->delta_pwm;
|
dimmer->pwm += dimmer->delta_pwm;
|
||||||
Serial.printf("%.0f", dimmer->pwm);
|
Serial.printf("%.0f", dimmer->pwm);
|
||||||
|
|
||||||
if(dim_type == DIM_STUFEN) {
|
if (dim_type == DIM_STUFEN) {
|
||||||
pwmController.setChannelPWM(dimmer->stufe, static_cast<uint16_t>(dimmer->pwm));
|
pwmController.setChannelPWM(dimmer->stufe,
|
||||||
|
static_cast<uint16_t>(dimmer->pwm));
|
||||||
} else { // DIM_LDR
|
} else { // DIM_LDR
|
||||||
pwmController.setAllChannelsPWM(static_cast<uint16_t>(dimmer->pwm));
|
pwmController.setAllChannelsPWM(static_cast<uint16_t>(dimmer->pwm));
|
||||||
}
|
}
|
||||||
|
|
||||||
dimmer->tick++;
|
dimmer->tick++;
|
||||||
if (dimmer->tick < dimmer->ticks)
|
if (dimmer->tick < dimmer->ticks) {
|
||||||
{
|
|
||||||
Serial.print("-");
|
Serial.print("-");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
|
||||||
if(dim_type == DIM_LDR) {
|
if (dim_type == DIM_LDR) {
|
||||||
Serial.printf("DIM_LDR: start: %d, ziel: %d\n",
|
Serial.printf("DIM_LDR: start: %d, ziel: %d\n", dimmer->start_pwm,
|
||||||
dimmer->start_pwm, dimmer->ziel_pwm);
|
dimmer->ziel_pwm);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else // DIM_STUFEN
|
||||||
else // DIM_STUFEN
|
|
||||||
{
|
{
|
||||||
Serial.printf("DIM_STUFEN: stufe: %d, start: %d, ziel: %d\n",
|
Serial.printf("DIM_STUFEN: stufe: %d, start: %d, ziel: %d\n",
|
||||||
dimmer->stufe, dimmer->start_pwm, dimmer->ziel_pwm);
|
dimmer->stufe, dimmer->start_pwm, dimmer->ziel_pwm);
|
||||||
|
|
||||||
if (fsm_outputs.laufrichtung == LR_HOCH)
|
if (fsm_outputs.laufrichtung == LR_HOCH) {
|
||||||
{
|
|
||||||
if (dimmer->stufe >= stufen - 1)
|
if (dimmer->stufe >= stufen - 1)
|
||||||
return true;
|
return true;
|
||||||
dimmer->stufe++;
|
dimmer->stufe++;
|
||||||
}
|
} else // LR_RUNTER
|
||||||
else // LR_RUNTER
|
|
||||||
{
|
{
|
||||||
if (dimmer->stufe <= 0)
|
if (dimmer->stufe <= 0)
|
||||||
return true;
|
return true;
|
||||||
@ -53,58 +49,49 @@ bool Treppe::dimmer_tick(dimmer_t* dimmer, bool dim_type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// startbedingunen für animation
|
// startbedingunen für animation
|
||||||
void Treppe::start_animation( dimmer_t* dimmer, bool dim_type,
|
void Treppe::start_animation(dimmer_t *dimmer, bool dim_type, uint16_t on_pwm,
|
||||||
uint16_t on_pwm, uint16_t off_pwm)
|
uint16_t off_pwm) {
|
||||||
{
|
|
||||||
fsm_pend.anim_beendet = false;
|
fsm_pend.anim_beendet = false;
|
||||||
|
|
||||||
if(dim_type == DIM_STUFEN) {
|
if (dim_type == DIM_STUFEN) {
|
||||||
if (fsm_outputs.laufrichtung == LR_HOCH)
|
if (fsm_outputs.laufrichtung == LR_HOCH)
|
||||||
dimmer->stufe = 0;
|
dimmer->stufe = 0;
|
||||||
else
|
else
|
||||||
dimmer->stufe = stufen - 1;
|
dimmer->stufe = stufen - 1;
|
||||||
|
|
||||||
dimmer->ticks = parameters.time_per_stair / INT_TIME; // [ms]
|
dimmer->ticks = parameters.time_per_stair / INT_TIME; // [ms]
|
||||||
}
|
} else { // DIM_LDR
|
||||||
else { // DIM_LDR
|
dimmer->ticks = parameters.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) {
|
||||||
{
|
|
||||||
dimmer->start_pwm = off_pwm;
|
dimmer->start_pwm = off_pwm;
|
||||||
dimmer->ziel_pwm = on_pwm;
|
dimmer->ziel_pwm = on_pwm;
|
||||||
dimmer->delta_pwm = (float)(on_pwm - off_pwm)
|
dimmer->delta_pwm = (float)(on_pwm - off_pwm) / (float)dimmer->ticks;
|
||||||
/ (float)dimmer->ticks;
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dimmer->start_pwm = on_pwm;
|
dimmer->start_pwm = on_pwm;
|
||||||
dimmer->ziel_pwm = off_pwm;
|
dimmer->ziel_pwm = off_pwm;
|
||||||
dimmer->delta_pwm = (float)(off_pwm - on_pwm)
|
dimmer->delta_pwm = (float)(off_pwm - on_pwm) / (float)dimmer->ticks;
|
||||||
/ (float)dimmer->ticks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dimmer->tick = 0;
|
dimmer->tick = 0;
|
||||||
dimmer->pwm = dimmer->start_pwm;
|
dimmer->pwm = dimmer->start_pwm;
|
||||||
|
|
||||||
Serial.printf("stufe %d, ticks %d, delta %f, start %d, ziel %d\n",
|
Serial.printf("stufe %d, ticks %d, delta %f, start %d, ziel %d\n",
|
||||||
dimmer->stufe, dimmer->ticks, dimmer->delta_pwm, dimmer->start_pwm, dimmer->ziel_pwm);
|
dimmer->stufe, dimmer->ticks, dimmer->delta_pwm,
|
||||||
|
dimmer->start_pwm, dimmer->ziel_pwm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::print_state_on_change()
|
void Treppe::print_state_on_change() {
|
||||||
{
|
|
||||||
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
||||||
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
||||||
if (
|
if (fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
||||||
fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
|
||||||
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
||||||
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
||||||
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle ||
|
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle ||
|
||||||
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
||||||
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
||||||
fsm_outputs.status != last_out.status)
|
fsm_outputs.status != last_out.status) {
|
||||||
{
|
|
||||||
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
||||||
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
||||||
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
||||||
@ -114,22 +101,22 @@ void Treppe::print_state_on_change()
|
|||||||
last_out.status = fsm_outputs.status;
|
last_out.status = fsm_outputs.status;
|
||||||
|
|
||||||
Serial.printf("FSM IN: s_u: %d, s_o: %d, a_b: %d, l_s: %d => ",
|
Serial.printf("FSM IN: s_u: %d, s_o: %d, a_b: %d, l_s: %d => ",
|
||||||
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten,
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten,
|
||||||
fsm_inputs.anim_beendet, fsm_inputs.ldr_schwelle);
|
fsm_inputs.anim_beendet, fsm_inputs.ldr_schwelle);
|
||||||
Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n", fsm_outputs.laufrichtung,
|
||||||
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
|
fsm_outputs.dimmrichtung, fsm_outputs.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Treppe::read_sensor(int sensor)
|
bool Treppe::read_sensor(int sensor) {
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
reads sensors with edge detection
|
reads sensors with edge detection
|
||||||
|
|
||||||
returns true if motion was detected
|
returns true if motion was detected
|
||||||
returns false if no 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
|
returns false if motion was detected, but state did not change back to not
|
||||||
|
detected
|
||||||
*/
|
*/
|
||||||
uint8_t pegel = digitalRead(sensor);
|
uint8_t pegel = digitalRead(sensor);
|
||||||
static uint8_t pegel_alt[2] = {0, 0};
|
static uint8_t pegel_alt[2] = {0, 0};
|
||||||
@ -140,22 +127,18 @@ bool Treppe::read_sensor(int sensor)
|
|||||||
else
|
else
|
||||||
index = 1;
|
index = 1;
|
||||||
|
|
||||||
if (pegel == 1 && pegel_alt[index] == 0)
|
if (pegel == 1 && pegel_alt[index] == 0) {
|
||||||
{
|
|
||||||
pegel_alt[index] = pegel;
|
pegel_alt[index] = pegel;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pegel_alt[index] = pegel;
|
pegel_alt[index] = pegel;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//return static_cast<bool>(pegel);
|
// return static_cast<bool>(pegel);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Treppe::read_ldr()
|
float Treppe::read_ldr() {
|
||||||
{
|
/*
|
||||||
/*
|
|
||||||
Reads Illuminance in Lux
|
Reads Illuminance in Lux
|
||||||
|
|
||||||
FUTURE USE : show current Illuminance on Webserver in order to calibrate
|
FUTURE USE : show current Illuminance on Webserver in order to calibrate
|
||||||
@ -169,7 +152,7 @@ float Treppe::read_ldr()
|
|||||||
= analogRead(A0) * (R13+R14)/(R14*1023.00)
|
= analogRead(A0) * (R13+R14)/(R14*1023.00)
|
||||||
= analogRead(A0) * (220k+82k)/(82k*1023.00)
|
= analogRead(A0) * (220k+82k)/(82k*1023.00)
|
||||||
= analogRead(A0) * 0.0036
|
= analogRead(A0) * 0.0036
|
||||||
|
|
||||||
Voltage Divider 2 (LDR, R1 || (R13+R14))
|
Voltage Divider 2 (LDR, R1 || (R13+R14))
|
||||||
R1 = 47k, R13+R14 = 302k -> R1||(R13+R14) = 40,67k
|
R1 = 47k, R13+R14 = 302k -> R1||(R13+R14) = 40,67k
|
||||||
Vcc/V(in1) = R(LDR) / (R1||(R13+R14))
|
Vcc/V(in1) = R(LDR) / (R1||(R13+R14))
|
||||||
@ -187,12 +170,11 @@ float Treppe::read_ldr()
|
|||||||
ldr_value = E(LDR)
|
ldr_value = E(LDR)
|
||||||
*/
|
*/
|
||||||
float ldr_ohm = 37280.00 / analogRead(A0);
|
float ldr_ohm = 37280.00 / analogRead(A0);
|
||||||
float ldr_value = 6526.6/(ldr_ohm*ldr_ohm);
|
float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm);
|
||||||
return ldr_value;
|
return ldr_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Treppe::check_ldr()
|
bool Treppe::check_ldr() {
|
||||||
{
|
|
||||||
static uint8_t active = 0;
|
static uint8_t active = 0;
|
||||||
|
|
||||||
#ifdef LDRDEBUG
|
#ifdef LDRDEBUG
|
||||||
@ -212,18 +194,20 @@ bool Treppe::check_ldr()
|
|||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::task()
|
void Treppe::task() {
|
||||||
{
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
uint32_t m=micros();
|
uint32_t m = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO wenn LDR geändert => idle_pwm_soll anpassen
|
||||||
|
// fsm_pend.ldr_changed = true;
|
||||||
|
|
||||||
fsm_inputs.ldr_schwelle = check_ldr();
|
fsm_inputs.ldr_schwelle = check_ldr();
|
||||||
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
Serial.print("1:");
|
Serial.print("1:");
|
||||||
Serial.println(micros()-m);
|
Serial.println(micros() - m);
|
||||||
m=micros();
|
m = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
||||||
@ -232,8 +216,8 @@ void Treppe::task()
|
|||||||
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
Serial.print("2:");
|
Serial.print("2:");
|
||||||
Serial.println(micros()-m);
|
Serial.println(micros() - m);
|
||||||
m=micros();
|
m = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
||||||
@ -242,66 +226,60 @@ void Treppe::task()
|
|||||||
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
Serial.print("3:");
|
Serial.print("3:");
|
||||||
Serial.println(micros()-m);
|
Serial.println(micros() - m);
|
||||||
m=micros();
|
m = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
print_state_on_change();
|
print_state_on_change();
|
||||||
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
Serial.print("4:");
|
Serial.print("4:");
|
||||||
Serial.println(micros()-m);
|
Serial.println(micros() - m);
|
||||||
m=micros();
|
m = micros();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( fsm_outputs.status == ST_AUFDIMMEN_HOCH ||
|
if (fsm_outputs.status == ST_AUFDIMMEN_HOCH ||
|
||||||
fsm_outputs.status == ST_ABDIMMEN_HOCH ||
|
fsm_outputs.status == ST_ABDIMMEN_HOCH ||
|
||||||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER ||
|
fsm_outputs.status == ST_AUFDIMMEN_RUNTER ||
|
||||||
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, parameters.active_pwm,
|
||||||
start_animation(&dimmer_stufen, DIM_STUFEN, parameters.active_pwm, idle_pwm_ist);
|
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);
|
||||||
}
|
} else if (fsm_outputs.status == ST_AUFDIMMEN_LDR ||
|
||||||
else if ( fsm_outputs.status == ST_AUFDIMMEN_LDR ||
|
fsm_outputs.status == ST_ABDIMMEN_LDR) {
|
||||||
fsm_outputs.status == ST_ABDIMMEN_LDR )
|
if (fsm_pend.anim_beendet)
|
||||||
{
|
|
||||||
if(fsm_pend.anim_beendet)
|
|
||||||
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_ist, 0);
|
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_ist, 0);
|
||||||
else
|
else
|
||||||
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
||||||
}
|
} else if (fsm_outputs.status == ST_RUHEZUSTAND) {
|
||||||
else if ( fsm_outputs.status == ST_RUHEZUSTAND )
|
if (fsm_pend.ldr_changed) {
|
||||||
{
|
|
||||||
if ( fsm_pend.ldr_changed ) {
|
|
||||||
fsm_pend.ldr_changed = false;
|
fsm_pend.ldr_changed = false;
|
||||||
fsm_outputs.dimmrichtung = DR_AUFDIMMEN;
|
fsm_outputs.dimmrichtung = DR_AUFDIMMEN;
|
||||||
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_soll, idle_pwm_ist);
|
start_animation(&dimmer_ldr, DIM_LDR, idle_pwm_soll, idle_pwm_ist);
|
||||||
idle_pwm_ist = idle_pwm_soll;
|
idle_pwm_ist = idle_pwm_soll;
|
||||||
}
|
}
|
||||||
if(!fsm_pend.anim_beendet) {
|
if (!fsm_pend.anim_beendet) {
|
||||||
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
fsm_pend.anim_beendet = dimmer_tick(&dimmer_ldr, DIM_LDR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_TIMING
|
#ifdef DEBUG_TIMING
|
||||||
Serial.print("5:");
|
Serial.print("5:");
|
||||||
Serial.println(micros()-m);
|
Serial.println(micros() - m);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::setup()
|
void Treppe::setup() {
|
||||||
{
|
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
||||||
pwmController.init(PCA9685_PhaseBalancer_None);
|
pwmController.init(PCA9685_PhaseBalancer_None);
|
||||||
//pwmController.init(PCA9685_PhaseBalancer_Linear);
|
// pwmController.init(PCA9685_PhaseBalancer_Linear);
|
||||||
pwmController.setPWMFrequency(100);
|
pwmController.setPWMFrequency(100);
|
||||||
//pwmController.setAllChannelsPWM(idle_pwm);
|
// pwmController.setAllChannelsPWM(idle_pwm);
|
||||||
|
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
pinMode(0, OUTPUT);
|
pinMode(0, OUTPUT);
|
||||||
@ -317,33 +295,39 @@ void Treppe::setup()
|
|||||||
Serial.printf("Treppe: stufen=%d\n", stufen);
|
Serial.printf("Treppe: stufen=%d\n", stufen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::set_idle_prozent(const int prozent)
|
void Treppe::set_idle_pwm_max(const uint16_t value,
|
||||||
{
|
const vorgabe_typ_t vorgabe_typ) {
|
||||||
// future use: parameters.idle_max_pwm
|
if (vorgabe_typ == VORGABE_PROZENT) {
|
||||||
uint16_t new_pwm = parameters.active_pwm * prozent / 100;
|
parameters.idle_pwm_max = parameters.active_pwm * value / 100;
|
||||||
set_idle_pwm_max(new_pwm);
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
}
|
parameters.idle_pwm_max = value;
|
||||||
|
|
||||||
void Treppe::set_idle_pwm_max(const uint16_t new_pwm)
|
|
||||||
{
|
|
||||||
// future use: parameters.idle_max_pwm
|
|
||||||
if(new_pwm > parameters.active_pwm) {
|
|
||||||
idle_pwm_soll = parameters.active_pwm;
|
|
||||||
} else {
|
|
||||||
idle_pwm_soll = new_pwm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("Treppe: idle_pwm_soll=%d\n", idle_pwm_soll);
|
if (parameters.idle_pwm_max > parameters.active_pwm) {
|
||||||
fsm_pend.ldr_changed = true;
|
parameters.idle_pwm_max = parameters.active_pwm;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("Treppe: parameters.idle_pwm_max=%d\n",
|
||||||
|
parameters.idle_pwm_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::set_active_pwm(uint16_t _active_pwm)
|
void Treppe::set_active_pwm(const uint16_t value,
|
||||||
{
|
const vorgabe_typ_t vorgabe_typ) {
|
||||||
parameters.active_pwm = _active_pwm;
|
|
||||||
Serial.printf("Treppe: active_pwm=%d\n", parameters.active_pwm);
|
if (vorgabe_typ == VORGABE_PROZENT) {
|
||||||
|
parameters.active_pwm = 4095 * value / 100;
|
||||||
|
} else if (vorgabe_typ == VORGABE_12BIT) {
|
||||||
|
parameters.active_pwm = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameters.active_pwm > 4095) {
|
||||||
|
parameters.idle_pwm_max = 4095;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("Treppe: parameters.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) {
|
||||||
parameters.time_per_stair = _time_per_stair;
|
parameters.time_per_stair = _time_per_stair;
|
||||||
Serial.printf("Treppe: time_per_stair=%d\n", parameters.time_per_stair);
|
Serial.printf("Treppe: time_per_stair=%d\n", parameters.time_per_stair);
|
||||||
}
|
}
|
@ -4,110 +4,99 @@
|
|||||||
#include "FSMTreppe3/FSMTreppe3.h"
|
#include "FSMTreppe3/FSMTreppe3.h"
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
|
|
||||||
// #define LDRDEBUG // comment in to override LDR measurement
|
// #define LDRDEBUG // comment in to override LDR measurement
|
||||||
#define LDR_HYS 1 // Hysteresis for switching off FSM [lux]
|
#define LDR_HYS 1 // Hysteresis for switching off FSM [lux]
|
||||||
|
|
||||||
#define SENSOR_OBEN 16
|
#define SENSOR_OBEN 16
|
||||||
#define SENSOR_UNTEN 12
|
#define SENSOR_UNTEN 12
|
||||||
#define OE 14
|
#define OE 14
|
||||||
|
|
||||||
#define INT_TIME 20 // interrupt intervall [ms]
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
|
|
||||||
|
enum vorgabe_typ_t { VORGABE_PROZENT = 0, VORGABE_12BIT = 1 };
|
||||||
|
|
||||||
class Treppe {
|
class Treppe {
|
||||||
private:
|
private:
|
||||||
const uint8_t stufen;
|
const uint8_t stufen;
|
||||||
|
|
||||||
struct stairway_param_t {
|
struct stairway_param_t {
|
||||||
uint16_t time_ldr = 500;
|
uint16_t time_ldr = 500;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
uint16_t idle_pwm_max = 100;
|
uint16_t idle_pwm_max = 100;
|
||||||
uint16_t active_pwm = 2000;
|
uint16_t active_pwm = 2000;
|
||||||
uint16_t ldr_schwelle = 2; // activation value for FSM [lx]
|
uint16_t ldr_schwelle = 2; // activation value for FSM [lx]
|
||||||
};
|
};
|
||||||
stairway_param_t parameters;
|
stairway_param_t parameters;
|
||||||
|
|
||||||
uint16_t idle_pwm_ist = parameters.idle_pwm_max;
|
uint16_t idle_pwm_ist = parameters.idle_pwm_max;
|
||||||
uint16_t idle_pwm_soll = 0;
|
uint16_t idle_pwm_soll = 0;
|
||||||
|
|
||||||
struct fsm_pending_inputs_t {
|
|
||||||
bool anim_beendet = true;
|
|
||||||
bool sensor_unten = false;
|
|
||||||
bool sensor_oben = false;
|
|
||||||
bool ldr_changed = false;
|
|
||||||
};
|
|
||||||
fsm_pending_inputs_t fsm_pend;
|
|
||||||
|
|
||||||
struct dimmer_t {
|
struct fsm_pending_inputs_t {
|
||||||
uint8_t stufe = 0;
|
bool anim_beendet = true;
|
||||||
uint16_t ticks = 0;
|
bool sensor_unten = false;
|
||||||
uint16_t tick = 0;
|
bool sensor_oben = false;
|
||||||
|
bool ldr_changed = false;
|
||||||
|
};
|
||||||
|
fsm_pending_inputs_t fsm_pend;
|
||||||
|
|
||||||
float delta_pwm = 0.0;
|
struct dimmer_t {
|
||||||
float pwm = 0.0;
|
uint8_t stufe = 0;
|
||||||
uint16_t start_pwm = 0;
|
uint16_t ticks = 0;
|
||||||
uint16_t ziel_pwm = 0;
|
uint16_t tick = 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
|
|
||||||
};
|
|
||||||
|
|
||||||
/* DIMM */
|
float delta_pwm = 0.0;
|
||||||
// bool dimmer(dimmer_t* dimmer, bool dim_type);
|
float pwm = 0.0;
|
||||||
bool dimmer_tick(dimmer_t* dimmer, bool dim_type);
|
uint16_t start_pwm = 0;
|
||||||
void start_animation(dimmer_t* dimmer, bool dim_type,
|
uint16_t ziel_pwm = 0;
|
||||||
uint16_t on_pwm, uint16_t off_pwm);
|
};
|
||||||
// void berechne_dimmer(dimmer_t* dimmer, bool dim_type);
|
enum dimmer_type_t { DIM_STUFEN = 0, DIM_LDR = 1 };
|
||||||
void print_state_on_change();
|
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 };
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
float read_ldr();
|
||||||
|
bool check_ldr();
|
||||||
|
|
||||||
/* LDR */
|
|
||||||
bool read_sensor(int sensor);
|
|
||||||
float read_ldr();
|
|
||||||
bool check_ldr();
|
|
||||||
public:
|
public:
|
||||||
Treppe(uint8_t _stufen) : stufen(_stufen){
|
Treppe(uint8_t _stufen) : stufen(_stufen) { FSMTreppe_Obj.initialize(); }
|
||||||
FSMTreppe_Obj.initialize();
|
~Treppe() { FSMTreppe_Obj.terminate(); }
|
||||||
}
|
|
||||||
~Treppe() {
|
|
||||||
FSMTreppe_Obj.terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void task(); // call periodically
|
void task(); // call periodically
|
||||||
|
|
||||||
// Parameter section
|
// Parameter section
|
||||||
void set_idle_prozent(int prozent);
|
void set_idle_pwm_max(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||||
void set_idle_pwm_max(const uint16_t new_pwm);
|
void set_active_pwm(const uint16_t value, const vorgabe_typ_t vorgabe_typ);
|
||||||
void set_active_pwm(uint16_t _active_pwm);
|
void set_time_per_stair(uint16_t _time_per_stair);
|
||||||
void set_time_per_stair(uint16_t _time_per_stair);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __TREPPE_H
|
#endif // __TREPPE_H
|
Loading…
x
Reference in New Issue
Block a user