Use global struct

This commit is contained in:
Theo Arends 2020-10-29 16:16:34 +01:00
parent 4c6fa325ac
commit 8a703adf84
10 changed files with 30 additions and 30 deletions

View File

@ -683,10 +683,10 @@ void CmndSleep(void)
{ {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 251)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 251)) {
Settings.sleep = XdrvMailbox.payload; Settings.sleep = XdrvMailbox.payload;
ssleep = XdrvMailbox.payload; TasmotaGlobal.sleep = XdrvMailbox.payload;
WiFiSetSleepMode(); WiFiSetSleepMode();
} }
Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.sleep, ssleep); Response_P(S_JSON_COMMAND_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, Settings.sleep, TasmotaGlobal.sleep);
} }

View File

@ -397,7 +397,7 @@ void FLOG::stopRecording(void){
if(k%128 == 0){ // give control to the system every x iteration, TODO: This will fail, when record/entry-size is not 8 if(k%128 == 0){ // give control to the system every x iteration, TODO: This will fail, when record/entry-size is not 8
// DEBUG_SENSOR_LOG(PSTR("FLOG: now loop(), %u bytes left"), Flog->bytes_left); // DEBUG_SENSOR_LOG(PSTR("FLOG: now loop(), %u bytes left"), Flog->bytes_left);
OsWatchLoop(); OsWatchLoop();
delay(ssleep); delay(TasmotaGlobal.sleep);
} }
k+=size; k+=size;
if(bytes_left>7){ if(bytes_left>7){
@ -416,7 +416,7 @@ void FLOG::stopRecording(void){
_readSector(next_sector); _readSector(next_sector);
bytes_left = sector.header.buf_pointer - sizeof(sector.header); bytes_left = sector.header.buf_pointer - sizeof(sector.header);
OsWatchLoop(); OsWatchLoop();
delay(ssleep); delay(TasmotaGlobal.sleep);
} }
running_download = false; running_download = false;
// Callback 3: create a footer or simply finish the download with an empty payload // Callback 3: create a footer or simply finish the download with an empty payload

View File

@ -669,7 +669,7 @@ void MqttShowState(void)
ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"), ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"),
ESP_getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep ESP_getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep
ssleep, TasmotaGlobal.loop_load_avg, MqttConnectCount()); TasmotaGlobal.sleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
for (uint32_t i = 1; i <= devices_present; i++) { for (uint32_t i = 1; i <= devices_present; i++) {
#ifdef USE_LIGHT #ifdef USE_LIGHT

View File

@ -153,7 +153,7 @@ void WiFiSetSleepMode(void)
*/ */
// Sleep explanation: https://github.com/esp8266/Arduino/blob/3f0c601cfe81439ce17e9bd5d28994a7ed144482/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp#L255 // Sleep explanation: https://github.com/esp8266/Arduino/blob/3f0c601cfe81439ce17e9bd5d28994a7ed144482/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp#L255
if (ssleep && Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep if (TasmotaGlobal.sleep && Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep
WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times
} else { } else {
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default) WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)

View File

@ -118,10 +118,10 @@ struct {
uint8_t state_250mS; // State 250msecond per second flag uint8_t state_250mS; // State 250msecond per second flag
uint8_t latching_relay_pulse; // Latching relay pulse timer uint8_t latching_relay_pulse; // Latching relay pulse timer
uint8_t active_device; // Active device in ExecuteCommandPower uint8_t active_device; // Active device in ExecuteCommandPower
uint8_t sleep; // Current copy of Settings.sleep
} TasmotaGlobal; } TasmotaGlobal;
uint8_t ssleep; // Current copy of Settings.sleep
uint8_t leds_present = 0; // Max number of LED supported uint8_t leds_present = 0; // Max number of LED supported
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off)) uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))
uint8_t led_power = 0; // LED power state uint8_t led_power = 0; // LED power state
@ -235,7 +235,7 @@ void setup(void) {
syslog_level = Settings.syslog_level; syslog_level = Settings.syslog_level;
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
TasmotaGlobal.save_data_counter = Settings.save_data; TasmotaGlobal.save_data_counter = Settings.save_data;
ssleep = Settings.sleep; TasmotaGlobal.sleep = Settings.sleep;
#ifndef USE_EMULATION #ifndef USE_EMULATION
Settings.flag2.emulation = 0; Settings.flag2.emulation = 0;
#else #else
@ -416,10 +416,10 @@ void loop(void) {
if (Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep if (Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep
// yield(); // yield == delay(0), delay contains yield, auto yield in loop // yield(); // yield == delay(0), delay contains yield, auto yield in loop
SleepDelay(ssleep); // https://github.com/esp8266/Arduino/issues/2021 SleepDelay(TasmotaGlobal.sleep); // https://github.com/esp8266/Arduino/issues/2021
} else { } else {
if (my_activity < (uint32_t)ssleep) { if (my_activity < (uint32_t)TasmotaGlobal.sleep) {
SleepDelay((uint32_t)ssleep - my_activity); // Provide time for background tasks like wifi SleepDelay((uint32_t)TasmotaGlobal.sleep - my_activity); // Provide time for background tasks like wifi
} else { } else {
if (global_state.network_down) { if (global_state.network_down) {
SleepDelay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period SleepDelay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period
@ -428,7 +428,7 @@ void loop(void) {
} }
if (!my_activity) { my_activity++; } // We cannot divide by 0 if (!my_activity) { my_activity++; } // We cannot divide by 0
uint32_t loop_delay = ssleep; uint32_t loop_delay = TasmotaGlobal.sleep;
if (!loop_delay) { loop_delay++; } // We cannot divide by 0 if (!loop_delay) { loop_delay++; } // We cannot divide by 0
uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second
uint32_t this_cycle_ratio = 100 * my_activity / loop_delay; uint32_t this_cycle_ratio = 100 * my_activity / loop_delay;

View File

@ -1859,12 +1859,12 @@ void LightAnimate(void)
// or set a maximum of PWM_MAX_SLEEP if light is on or Fade is running // or set a maximum of PWM_MAX_SLEEP if light is on or Fade is running
if (Light.power || Light.fade_running) { if (Light.power || Light.fade_running) {
if (Settings.sleep > PWM_MAX_SLEEP) { if (Settings.sleep > PWM_MAX_SLEEP) {
ssleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that animations are smooth TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that animations are smooth
} else { } else {
ssleep = Settings.sleep; // or keep the current sleep if it's lower than 50 TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's lower than 50
} }
} else { } else {
ssleep = Settings.sleep; TasmotaGlobal.sleep = Settings.sleep;
} }
if (!Light.power) { // All channels powered off if (!Light.power) { // All channels powered off

View File

@ -347,8 +347,8 @@ bool ZigbeeUploadXmodem(void) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: Init sync")); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: Init sync"));
ZigbeeSerial->flush(); ZigbeeSerial->flush();
ZigbeeSerial->write('1'); // upload ebl ZigbeeSerial->write('1'); // upload ebl
if (ssleep > 0) { if (TasmotaGlobal.sleep > 0) {
ssleep = 1; // Speed up loop used for xmodem upload TasmotaGlobal.sleep = 1; // Speed up loop used for xmodem upload
} }
XModem.timeout = millis() + (XMODEM_SYNC_TIMEOUT * 1000); XModem.timeout = millis() + (XMODEM_SYNC_TIMEOUT * 1000);
ZbUpload.ota_step = ZBU_SYNC; ZbUpload.ota_step = ZBU_SYNC;
@ -442,8 +442,8 @@ bool ZigbeeUploadXmodem(void) {
case ZBU_DONE: { // *** Clean up and restart to disable bootloader and use new firmware case ZBU_DONE: { // *** Clean up and restart to disable bootloader and use new firmware
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: " D_RESTARTING)); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: " D_RESTARTING));
ZigbeeUploadSetBootloader(1); // Disable bootloader and reset MCU - should happen at restart ZigbeeUploadSetBootloader(1); // Disable bootloader and reset MCU - should happen at restart
if (1 == ssleep) { if (1 == TasmotaGlobal.sleep) {
ssleep = Settings.sleep; // Restore loop sleep TasmotaGlobal.sleep = Settings.sleep; // Restore loop sleep
} }
// TasmotaGlobal.restart_flag = 2; // Restart to disable bootloader and use new firmware // TasmotaGlobal.restart_flag = 2; // Restart to disable bootloader and use new firmware
ZbUpload.ota_step = ZBU_FINISH; // Never return to zero without a restart to get a sane Zigbee environment ZbUpload.ota_step = ZBU_FINISH; // Never return to zero without a restart to get a sane Zigbee environment

View File

@ -53,7 +53,7 @@ void BuzzerSet(uint8_t state)
analogWrite(Pin(GPIO_BUZZER, 0), Settings.pwm_range / 2); // set 50% duty cycle for frequency output analogWrite(Pin(GPIO_BUZZER, 0), Settings.pwm_range / 2); // set 50% duty cycle for frequency output
} }
else { else {
analogWrite(Pin(GPIO_BUZZER, 0), 0); // set 0% (or 100% for inverted PWM) duty cycle which turns off frequency output either way analogWrite(Pin(GPIO_BUZZER, 0), 0); // set 0% (or 100% for inverted PWM) duty cycle which turns off frequency output either way
} }
last_state = state; last_state = state;
} }
@ -61,7 +61,7 @@ void BuzzerSet(uint8_t state)
else { else {
DigitalWrite(GPIO_BUZZER, 0, state); // Buzzer On/Off DigitalWrite(GPIO_BUZZER, 0, state); // Buzzer On/Off
} }
} }
//void BuzzerBeep(uint32_t count = 1, uint32_t on = 1, uint32_t off = 1, uint32_t tune = 0, uint32_t mode = 0); //void BuzzerBeep(uint32_t count = 1, uint32_t on = 1, uint32_t off = 1, uint32_t tune = 0, uint32_t mode = 0);
@ -101,14 +101,14 @@ void BuzzerBeep(uint32_t count, uint32_t on, uint32_t off, uint32_t tune, uint32
Buzzer.enable = (Buzzer.count > 0); Buzzer.enable = (Buzzer.count > 0);
if (Buzzer.enable) { if (Buzzer.enable) {
if (Settings.sleep > PWM_MAX_SLEEP) { if (Settings.sleep > PWM_MAX_SLEEP) {
ssleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that buzzer periods are a bit more accurate TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that buzzer periods are a bit more accurate
} else { } else {
ssleep = Settings.sleep; // or keep the current sleep if it's lower than 10 TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's lower than 10
} }
} }
else { else {
ssleep = Settings.sleep; // restore original sleep TasmotaGlobal.sleep = Settings.sleep; // restore original sleep
BuzzerSet(0); BuzzerSet(0);
} }
} }

View File

@ -172,11 +172,11 @@ void CpuLoadLoop(void)
CPU_loops ++; CPU_loops ++;
if ((CPU_last_millis + (CPU_load_check *1000)) <= CPU_last_loop_time) { if ((CPU_last_millis + (CPU_load_check *1000)) <= CPU_last_loop_time) {
#if defined(F_CPU) && (F_CPU == 160000000L) #if defined(F_CPU) && (F_CPU == 160000000L)
int CPU_load = 100 - ( (CPU_loops*(1 + 30*ssleep)) / (CPU_load_check *800) ); int CPU_load = 100 - ( (CPU_loops*(1 + 30*TasmotaGlobal.sleep)) / (CPU_load_check *800) );
CPU_loops = CPU_loops / CPU_load_check; CPU_loops = CPU_loops / CPU_load_check;
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(160MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops); AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(160MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
#else #else
int CPU_load = 100 - ( (CPU_loops*(1 + 30*ssleep)) / (CPU_load_check *400) ); int CPU_load = 100 - ( (CPU_loops*(1 + 30*TasmotaGlobal.sleep)) / (CPU_load_check *400) );
CPU_loops = CPU_loops / CPU_load_check; CPU_loops = CPU_loops / CPU_load_check;
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(80MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops); AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(80MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
#endif #endif

View File

@ -665,7 +665,7 @@ bool Xsns37(uint8_t function)
RfSnsAnalyzeRawSignal(); RfSnsAnalyzeRawSignal();
} }
} }
ssleep = 0; TasmotaGlobal.sleep = 0;
break; break;
case FUNC_EVERY_SECOND: case FUNC_EVERY_SECOND:
RfSnsEverySecond(); RfSnsEverySecond();