|
|
|
|
|
|
|
|
dimmer->stufe = stufen - 1; |
|
|
dimmer->stufe = stufen - 1; |
|
|
|
|
|
|
|
|
dimmer->ticks = param.time_per_stair / INT_TIME; // [ms] |
|
|
dimmer->ticks = param.time_per_stair / INT_TIME; // [ms] |
|
|
} else { // DIM_LDR |
|
|
|
|
|
|
|
|
} else { // DIM_LDR |
|
|
dimmer->ticks = param.time_ldr / INT_TIME; // [ms] |
|
|
dimmer->ticks = param.time_ldr / INT_TIME; // [ms] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
E(LDR) = 6526.5 / (R(LDR)^2) |
|
|
E(LDR) = 6526.5 / (R(LDR)^2) |
|
|
ldr_value = E(LDR) |
|
|
ldr_value = E(LDR) |
|
|
*/ |
|
|
*/ |
|
|
//float ldr_ohm = 37280.00 / analogRead(A0); |
|
|
|
|
|
float voltage = analogRead(A0)*0.0036; |
|
|
|
|
|
float ldr_ohm = 40.57*(3.3-voltage)/voltage; |
|
|
|
|
|
|
|
|
// float ldr_ohm = 37280.00 / analogRead(A0); |
|
|
|
|
|
float voltage = analogRead(A0) * 0.0036; |
|
|
|
|
|
float ldr_ohm = 40.57 * (3.3 - voltage) / voltage; |
|
|
float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm); |
|
|
float ldr_value = 6526.6 / (ldr_ohm * ldr_ohm); |
|
|
#ifdef LDRDEBUG |
|
|
|
|
|
Serial.printf("Ohm: %f lux: %f Comp: %d\n", ldr_ohm,ldr_value, param.ldr_schwelle); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#ifdef LDRDEBUG |
|
|
|
|
|
Serial.printf("Ohm: %f lux: %f Comp: %d\n", ldr_ohm, ldr_value, |
|
|
|
|
|
param.ldr_schwelle); |
|
|
|
|
|
#endif |
|
|
return ldr_value; |
|
|
return ldr_value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t active = 0; |
|
|
static uint8_t active = 0; |
|
|
|
|
|
|
|
|
#ifdef LDRDEBUG |
|
|
#ifdef LDRDEBUG |
|
|
//return true; |
|
|
|
|
|
|
|
|
// return true; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// follow up: averaging over many samples? |
|
|
// follow up: averaging over many samples? |
|
|
|
|
|
|
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (fsm_outputs.status == ST_RUHEZUSTAND || |
|
|
|
|
|
fsm_outputs.status == ST_INAKTIV_LDR){ |
|
|
|
|
|
if (param_changed) { |
|
|
|
|
|
param_changed = false; |
|
|
|
|
|
param = param_pend; |
|
|
|
|
|
save_param_to_eeprom(); |
|
|
|
|
|
Serial.printf("Parameter Change applied!\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (fsm_outputs.status == ST_RUHEZUSTAND || |
|
|
|
|
|
fsm_outputs.status == ST_INAKTIV_LDR) { |
|
|
|
|
|
if (param_changed) { |
|
|
|
|
|
param_changed = false; |
|
|
|
|
|
param = param_pend; |
|
|
|
|
|
save_param_to_eeprom(); |
|
|
|
|
|
Serial.printf("Parameter Change applied!\n"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifdef DEBUG_TIMING |
|
|
#ifdef DEBUG_TIMING |
|
|
|
|
|
|
|
|
void Treppe::save_param_to_eeprom() { |
|
|
void Treppe::save_param_to_eeprom() { |
|
|
EEPROM.put(EEP_START_ADDR, |
|
|
EEPROM.put(EEP_START_ADDR, |
|
|
param); // copy Parameters so "EEPROM"-section in RAM |
|
|
param); // copy Parameters so "EEPROM"-section in RAM |
|
|
EEPROM.commit(); // write "EEPROM"-section to flash |
|
|
|
|
|
|
|
|
EEPROM.commit(); // write "EEPROM"-section to flash |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Treppe::set_idle_pwm_max(const uint16_t value, |
|
|
void Treppe::set_idle_pwm_max(const uint16_t value, |
|
|
|
|
|
|
|
|
// ?! |
|
|
// ?! |
|
|
param_pend.ldr_schwelle = 10 * value / 100; |
|
|
param_pend.ldr_schwelle = 10 * value / 100; |
|
|
} else if (vorgabe_typ == VORGABE_12BIT) { |
|
|
} else if (vorgabe_typ == VORGABE_12BIT) { |
|
|
param_pend.ldr_schwelle = value; |
|
|
|
|
|
|
|
|
param_pend.ldr_schwelle = value; |
|
|
} |
|
|
} |
|
|
param_changed = true; |
|
|
param_changed = true; |
|
|
|
|
|
|
|
|
Serial.printf("Treppe: ldr_schwelle=%d\n", param_pend.ldr_schwelle); |
|
|
Serial.printf("Treppe: ldr_schwelle=%d\n", param_pend.ldr_schwelle); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Treppe::param_to_json(char *json_str, size_t sz) { |
|
|
|
|
|
snprintf(json_str, sz, "{\n\ |
|
|
|
|
|
\"time_ldr\": %d,\n\ |
|
|
|
|
|
\"time_per_stair\": %d,\n\ |
|
|
|
|
|
\"idle_pwm_max\": %d,\n\ |
|
|
|
|
|
\"active_pwm\": %d,\n\ |
|
|
|
|
|
\"ldr_schwelle\": %d\n}\n", |
|
|
|
|
|
param.time_ldr, param.time_per_stair, param.idle_pwm_max, |
|
|
|
|
|
param.active_pwm, param.ldr_schwelle); |
|
|
} |
|
|
} |