From 9d02e054f582b15dd4ab0ba13db1d1f3cb48baa4 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Thu, 11 May 2023 19:37:17 +0200 Subject: [PATCH] Added brightness range check to brightness webserver set feature. Added a reset function to the timing control module. Fixed the pwm test feature by adding tc reset function call. --- firmware/config.h | 4 ++-- firmware/firmware.ino | 18 ++++++++++++++---- firmware/timing_control.ino | 8 +++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/firmware/config.h b/firmware/config.h index d925ab8..40795f4 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -18,7 +18,7 @@ #define EEPROM_LAST_STATE_ADDRESS 4 // the first "last state" information for the first light #define EEPROM_TIMING_DATA_ADDRESS (EEPROM_LAST_STATE_ADDRESS + LIGHTS_COUNT) // Stored data date per light ELE_USED; HH; MM; CH1; CH2; CH3; CH4; -#define BRI_MOD_STEPS_PER_SEC 5 +#define BRI_MOD_STEPS_PER_SEC 10 #define TIME_CHECK_INTERVAL_MS (60000UL) // 60 second interval #define TIME_LIGHTENGINE_INTERVAL_MS (1000UL / BRI_MOD_STEPS_PER_SEC) // BRI_MOD_STEPS_PER_SEC steps per second to in-/decrease the brightness @@ -33,4 +33,4 @@ #define BRI_TO_PWM_FACTOR 1.0 // 24V-0V = 24V range #define PWM_TEST_INTERVA_MS 1000 -#define TEST_PWM_CHG_CNT 5 +#define TEST_PWM_CHG_CNT 5 diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 885bab6..36c6819 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -78,10 +78,10 @@ uint8_t test_pwm_state = TEST_PWM_STATE_INIT; bool light_state[LIGHTS_COUNT]; bool in_transition; -int default_transitiontime = 4; // 4 seconds +int default_transitiontime = 4; // 4 = 4 seconds -int transitiontime[LIGHTS_COUNT]; -int bri[LIGHTS_COUNT]; +uint16_t transitiontime[LIGHTS_COUNT]; +uint16_t bri[LIGHTS_COUNT]; uint16_t current_pwm[LIGHTS_COUNT]; float step_level[LIGHTS_COUNT]; @@ -637,7 +637,15 @@ void init_webserver() if (server.hasArg("bri" + (String)light)) { - bri[light] = (int)server.arg("bri" + (String)light).toInt(); + int tmp = (int)server.arg("bri" + (String)light).toInt(); + + if (tmp > 255) + { + tmp = 255; + } else if (tmp < 0) { + tmp = 0; + } + bri[light] = tmp; Serial.print("Brightness "); Serial.print(light); Serial.print(" set to "); @@ -1124,6 +1132,7 @@ void test_pwm_main() test_pwm = false; tc_enabled = tc_enabled_old; + for (uint8_t i = 0; i < LIGHTS_COUNT; i++) { light_state[i] = false; @@ -1134,6 +1143,7 @@ void test_pwm_main() process_lightdata(i, transitiontime[i]); } + tc_reset(); tc_update_main(); // load the tc if required test_pwm_state = TEST_PWM_STATE_INIT; diff --git a/firmware/timing_control.ino b/firmware/timing_control.ino index 83f9c07..521382a 100644 --- a/firmware/timing_control.ino +++ b/firmware/timing_control.ino @@ -25,6 +25,8 @@ bool tc_testOngoing = false; uint32_t tc_last_check = 60000; +uint8_t current_target_data_block = 255; + WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, MY_NTP_SERVER); @@ -126,6 +128,11 @@ void tc_init() //********************************// +void tc_reset() +{ + current_target_data_block = 255; +} + void tc_update_loop() { static uint8_t last_min_check = 255; @@ -146,7 +153,6 @@ void tc_update_loop() void tc_update_main() { - static uint8_t current_target_data_block = 255; uint8_t target_data_block = 255; if (tc_enabled == TIMING_CONTROL_DISABLED)