mirror of https://github.com/arendst/Tasmota.git
Use global struct
This commit is contained in:
parent
4c6fa325ac
commit
8a703adf84
|
@ -683,10 +683,10 @@ void CmndSleep(void)
|
|||
{
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 251)) {
|
||||
Settings.sleep = XdrvMailbox.payload;
|
||||
ssleep = XdrvMailbox.payload;
|
||||
TasmotaGlobal.sleep = XdrvMailbox.payload;
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
// DEBUG_SENSOR_LOG(PSTR("FLOG: now loop(), %u bytes left"), Flog->bytes_left);
|
||||
OsWatchLoop();
|
||||
delay(ssleep);
|
||||
delay(TasmotaGlobal.sleep);
|
||||
}
|
||||
k+=size;
|
||||
if(bytes_left>7){
|
||||
|
@ -416,7 +416,7 @@ void FLOG::stopRecording(void){
|
|||
_readSector(next_sector);
|
||||
bytes_left = sector.header.buf_pointer - sizeof(sector.header);
|
||||
OsWatchLoop();
|
||||
delay(ssleep);
|
||||
delay(TasmotaGlobal.sleep);
|
||||
}
|
||||
running_download = false;
|
||||
// Callback 3: create a footer or simply finish the download with an empty payload
|
||||
|
|
|
@ -669,7 +669,7 @@ void MqttShowState(void)
|
|||
|
||||
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
|
||||
ssleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
|
||||
TasmotaGlobal.sleep, TasmotaGlobal.loop_load_avg, MqttConnectCount());
|
||||
|
||||
for (uint32_t i = 1; i <= devices_present; i++) {
|
||||
#ifdef USE_LIGHT
|
||||
|
|
|
@ -153,7 +153,7 @@ void WiFiSetSleepMode(void)
|
|||
*/
|
||||
|
||||
// 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
|
||||
} else {
|
||||
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)
|
||||
|
|
|
@ -118,10 +118,10 @@ struct {
|
|||
uint8_t state_250mS; // State 250msecond per second flag
|
||||
uint8_t latching_relay_pulse; // Latching relay pulse timer
|
||||
uint8_t active_device; // Active device in ExecuteCommandPower
|
||||
uint8_t sleep; // Current copy of Settings.sleep
|
||||
|
||||
} TasmotaGlobal;
|
||||
|
||||
uint8_t ssleep; // Current copy of Settings.sleep
|
||||
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_power = 0; // LED power state
|
||||
|
@ -235,7 +235,7 @@ void setup(void) {
|
|||
syslog_level = Settings.syslog_level;
|
||||
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;
|
||||
ssleep = Settings.sleep;
|
||||
TasmotaGlobal.sleep = Settings.sleep;
|
||||
#ifndef USE_EMULATION
|
||||
Settings.flag2.emulation = 0;
|
||||
#else
|
||||
|
@ -416,10 +416,10 @@ void loop(void) {
|
|||
|
||||
if (Settings.flag3.sleep_normal) { // SetOption60 - Enable normal sleep instead of dynamic sleep
|
||||
// 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 {
|
||||
if (my_activity < (uint32_t)ssleep) {
|
||||
SleepDelay((uint32_t)ssleep - my_activity); // Provide time for background tasks like wifi
|
||||
if (my_activity < (uint32_t)TasmotaGlobal.sleep) {
|
||||
SleepDelay((uint32_t)TasmotaGlobal.sleep - my_activity); // Provide time for background tasks like wifi
|
||||
} else {
|
||||
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
|
||||
|
@ -428,7 +428,7 @@ void loop(void) {
|
|||
}
|
||||
|
||||
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
|
||||
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;
|
||||
|
|
|
@ -1859,12 +1859,12 @@ void LightAnimate(void)
|
|||
// or set a maximum of PWM_MAX_SLEEP if light is on or Fade is running
|
||||
if (Light.power || Light.fade_running) {
|
||||
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 {
|
||||
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 {
|
||||
ssleep = Settings.sleep;
|
||||
TasmotaGlobal.sleep = Settings.sleep;
|
||||
}
|
||||
|
||||
if (!Light.power) { // All channels powered off
|
||||
|
|
|
@ -347,8 +347,8 @@ bool ZigbeeUploadXmodem(void) {
|
|||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: Init sync"));
|
||||
ZigbeeSerial->flush();
|
||||
ZigbeeSerial->write('1'); // upload ebl
|
||||
if (ssleep > 0) {
|
||||
ssleep = 1; // Speed up loop used for xmodem upload
|
||||
if (TasmotaGlobal.sleep > 0) {
|
||||
TasmotaGlobal.sleep = 1; // Speed up loop used for xmodem upload
|
||||
}
|
||||
XModem.timeout = millis() + (XMODEM_SYNC_TIMEOUT * 1000);
|
||||
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
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("XMD: " D_RESTARTING));
|
||||
ZigbeeUploadSetBootloader(1); // Disable bootloader and reset MCU - should happen at restart
|
||||
if (1 == ssleep) {
|
||||
ssleep = Settings.sleep; // Restore loop sleep
|
||||
if (1 == TasmotaGlobal.sleep) {
|
||||
TasmotaGlobal.sleep = Settings.sleep; // Restore loop sleep
|
||||
}
|
||||
// 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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ void BuzzerSet(uint8_t state)
|
|||
else {
|
||||
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);
|
||||
|
@ -101,14 +101,14 @@ void BuzzerBeep(uint32_t count, uint32_t on, uint32_t off, uint32_t tune, uint32
|
|||
|
||||
Buzzer.enable = (Buzzer.count > 0);
|
||||
if (Buzzer.enable) {
|
||||
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
|
||||
} else {
|
||||
ssleep = Settings.sleep; // or keep the current sleep if it's lower than 10
|
||||
}
|
||||
if (Settings.sleep > PWM_MAX_SLEEP) {
|
||||
TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that buzzer periods are a bit more accurate
|
||||
} else {
|
||||
TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's lower than 10
|
||||
}
|
||||
}
|
||||
else {
|
||||
ssleep = Settings.sleep; // restore original sleep
|
||||
TasmotaGlobal.sleep = Settings.sleep; // restore original sleep
|
||||
BuzzerSet(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,11 +172,11 @@ void CpuLoadLoop(void)
|
|||
CPU_loops ++;
|
||||
if ((CPU_last_millis + (CPU_load_check *1000)) <= CPU_last_loop_time) {
|
||||
#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;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(160MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
|
||||
#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;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(80MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
|
||||
#endif
|
||||
|
|
|
@ -665,7 +665,7 @@ bool Xsns37(uint8_t function)
|
|||
RfSnsAnalyzeRawSignal();
|
||||
}
|
||||
}
|
||||
ssleep = 0;
|
||||
TasmotaGlobal.sleep = 0;
|
||||
break;
|
||||
case FUNC_EVERY_SECOND:
|
||||
RfSnsEverySecond();
|
||||
|
|
Loading…
Reference in New Issue