From 1b69502d9be27f74365047043c1885cb0df27d61 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Sun, 30 Jun 2019 16:44:36 +0200
Subject: [PATCH] Code optimization - Change for(uint8_t in for (uint32_t
Code optimization - Change for(uint8_t in for (uint32_t
---
sonoff/settings.ino | 58 +++++++--------
sonoff/sonoff.ino | 102 +++++++++++++--------------
sonoff/support.ino | 18 ++---
sonoff/support_button.ino | 6 +-
sonoff/support_switch.ino | 6 +-
sonoff/support_wifi.ino | 6 +-
sonoff/xdrv_01_webserver.ino | 76 ++++++++++----------
sonoff/xdrv_02_mqtt.ino | 21 +++---
sonoff/xdrv_04_light.ino | 70 +++++++++---------
sonoff/xdrv_05_irremote.ino | 14 ++--
sonoff/xdrv_06_snfbridge.ino | 14 ++--
sonoff/xdrv_07_domoticz.ino | 14 ++--
sonoff/xdrv_08_serial_bridge.ino | 2 +-
sonoff/xdrv_09_timers.ino | 12 ++--
sonoff/xdrv_10_rules.ino | 40 +++++------
sonoff/xdrv_10_scripter.ino | 2 +-
sonoff/xdrv_11_knx.ino | 38 +++++-----
sonoff/xdrv_12_home_assistant.ino | 6 +-
sonoff/xdrv_13_display.ino | 12 ++--
sonoff/xdrv_14_mp3.ino | 2 +-
sonoff/xdrv_15_pca9685.ino | 6 +-
sonoff/xdrv_16_tuyadimmer.ino | 6 +-
sonoff/xdrv_18_armtronix_dimmers.ino | 2 +-
sonoff/xdrv_20_hue.ino | 6 +-
sonoff/xdrv_99_debug.ino | 6 +-
sonoff/xdrv_interface.ino | 2 +-
sonoff/xdsp_01_lcd.ino | 4 +-
sonoff/xdsp_02_ssd1306.ino | 2 +-
sonoff/xdsp_03_matrix.ino | 16 ++---
sonoff/xdsp_04_ili9341.ino | 2 +-
sonoff/xdsp_05_epaper_29.ino | 2 +-
sonoff/xdsp_interface.ino | 2 +-
sonoff/xnrg_01_hlw8012.ino | 6 +-
sonoff/xnrg_02_cse7766.ino | 2 +-
sonoff/xnrg_03_pzem004t.ino | 4 +-
sonoff/xnrg_04_mcp39f501.ino | 8 +--
sonoff/xnrg_05_pzem_ac.ino | 4 +-
sonoff/xnrg_07_ade7953.ino | 2 +-
sonoff/xnrg_interface.ino | 2 +-
sonoff/xplg_ws2812.ino | 12 ++--
sonoff/xsns_01_counter.ino | 6 +-
sonoff/xsns_02_analog.ino | 2 +-
sonoff/xsns_04_snfsc.ino | 2 +-
sonoff/xsns_05_ds18b20.ino | 6 +-
sonoff/xsns_05_ds18x20.ino | 24 +++----
sonoff/xsns_05_ds18x20_legacy.ino | 12 ++--
sonoff/xsns_06_dht.ino | 12 ++--
sonoff/xsns_07_sht1x.ino | 4 +-
sonoff/xsns_08_htu21.ino | 2 +-
sonoff/xsns_09_bmp.ino | 6 +-
sonoff/xsns_10_bh1750.ino | 2 +-
sonoff/xsns_11_veml6070.ino | 2 +-
sonoff/xsns_12_ads1115.ino | 10 +--
sonoff/xsns_12_ads1115_i2cdev.ino | 4 +-
sonoff/xsns_13_ina219.ino | 2 +-
sonoff/xsns_14_sht3x.ino | 6 +-
sonoff/xsns_15_mhz19.ino | 2 +-
sonoff/xsns_18_pms5003.ino | 4 +-
sonoff/xsns_20_novasds.ino | 2 +-
sonoff/xsns_23_sdm120.ino | 4 +-
sonoff/xsns_25_sdm630.ino | 4 +-
sonoff/xsns_26_lm75ad.ino | 2 +-
sonoff/xsns_28_tm1638.ino | 14 ++--
sonoff/xsns_29_mcp230xx.ino | 32 ++++-----
sonoff/xsns_30_mpr121.ino | 8 +--
sonoff/xsns_32_mpu6050.ino | 2 +-
sonoff/xsns_34_hx711.ino | 2 +-
sonoff/xsns_35_tx20.ino | 2 +-
sonoff/xsns_37_rfsensor.ino | 8 +--
sonoff/xsns_39_max31855.ino | 2 +-
sonoff/xsns_40_pn532.ino | 18 ++---
sonoff/xsns_41_max44009.ino | 2 +-
sonoff/xsns_43_hre.ino | 4 +-
sonoff/xsns_44_sps30.ino | 8 +--
sonoff/xsns_interface.ino | 2 +-
sonoff/zzzz_debug.ino | 4 +-
76 files changed, 421 insertions(+), 422 deletions(-)
diff --git a/sonoff/settings.ino b/sonoff/settings.ino
index 4e7af0d4e..eae6d3817 100644
--- a/sonoff/settings.ino
+++ b/sonoff/settings.ino
@@ -151,7 +151,7 @@ uint32_t GetRtcSettingsCrc(void)
uint32_t crc = 0;
uint8_t *bytes = (uint8_t*)&RtcSettings;
- for (uint16_t i = 0; i < sizeof(RTCMEM); i++) {
+ for (uint32_t i = 0; i < sizeof(RTCMEM); i++) {
crc += bytes[i]*(i+1);
}
return crc;
@@ -174,7 +174,7 @@ void RtcSettingsLoad(void)
RtcSettings.valid = RTC_MEM_VALID;
RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday;
RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal;
- for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
+ for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
RtcSettings.pulse_counter[i] = Settings.pulse_counter[i];
}
RtcSettings.power = Settings.power;
@@ -197,7 +197,7 @@ uint32_t GetRtcRebootCrc(void)
uint32_t crc = 0;
uint8_t *bytes = (uint8_t*)&RtcReboot;
- for (uint16_t i = 0; i < sizeof(RTCRBT); i++) {
+ for (uint32_t i = 0; i < sizeof(RTCRBT); i++) {
crc += bytes[i]*(i+1);
}
return crc;
@@ -442,7 +442,7 @@ uint16_t GetSettingsCrc(void)
uint16_t crc = 0;
uint8_t *bytes = (uint8_t*)&Settings;
- for (uint16_t i = 0; i < sizeof(SYSCFG); i++) {
+ for (uint32_t i = 0; i < sizeof(SYSCFG); i++) {
if ((i < 14) || (i > 15)) { crc += bytes[i]*(i+1); } // Skip crc
}
return crc;
@@ -526,7 +526,7 @@ void SettingsSave(uint8_t rotate)
#endif // USE_EEPROM
if (!stop_flash_rotate && rotate) {
- for (uint8_t i = 1; i < CFG_ROTATES; i++) {
+ for (uint32_t i = 1; i < CFG_ROTATES; i++) {
ESP.flashEraseSector(settings_location -i); // Delete previous configurations by resetting to 0xFF
delay(1);
}
@@ -553,7 +553,7 @@ void SettingsLoad(void)
settings_location = 0;
uint32_t flash_location = SETTINGS_LOCATION +1;
uint16_t cfg_holder = 0;
- for (uint8_t i = 0; i < CFG_ROTATES; i++) {
+ for (uint32_t i = 0; i < CFG_ROTATES; i++) {
flash_location--;
ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
@@ -694,7 +694,7 @@ void SettingsDefaultSet2(void)
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
Settings.module = MODULE;
ModuleDefault(WEMOS);
-// for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
+// for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
strlcpy(Settings.friendlyname[0], FRIENDLY_NAME, sizeof(Settings.friendlyname[0]));
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
@@ -710,7 +710,7 @@ void SettingsDefaultSet2(void)
Settings.ledstate = APP_LEDSTATE;
Settings.ledmask = APP_LEDMASK;
Settings.pulse_timer[0] = APP_PULSETIME;
-// for (uint8_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }
+// for (uint32_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }
// Serial
Settings.baudrate = APP_BAUDRATE / 1200;
@@ -750,7 +750,7 @@ void SettingsDefaultSet2(void)
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
// Switch
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) { Settings.switchmode[i] = SWITCH_MODE; }
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) { Settings.switchmode[i] = SWITCH_MODE; }
// MQTT
Settings.flag.mqtt_enabled = MQTT_USE;
@@ -785,12 +785,12 @@ void SettingsDefaultSet2(void)
char fingerprint[60];
strlcpy(fingerprint, MQTT_FINGERPRINT1, sizeof(fingerprint));
char *p = fingerprint;
- for (uint8_t i = 0; i < 20; i++) {
+ for (uint32_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
}
strlcpy(fingerprint, MQTT_FINGERPRINT2, sizeof(fingerprint));
p = fingerprint;
- for (uint8_t i = 0; i < 20; i++) {
+ for (uint32_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[1][i] = strtol(p, &p, 16);
}
Settings.tele_period = TELE_PERIOD;
@@ -829,17 +829,17 @@ void SettingsDefaultSet2(void)
Settings.param[P_IR_UNKNOW_THRESHOLD] = IR_RCV_MIN_UNKNOWN_SIZE;
// RF Bridge
-// for (uint8_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
+// for (uint32_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
// Domoticz
Settings.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
-// for (uint8_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
+// for (uint32_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
// Settings.domoticz_relay_idx[i] = 0;
// Settings.domoticz_key_idx[i] = 0;
// Settings.domoticz_switch_idx[i] = 0;
// }
-// for (uint8_t i = 0; i < MAX_DOMOTICZ_SNS_IDX; i++) {
+// for (uint32_t i = 0; i < MAX_DOMOTICZ_SNS_IDX; i++) {
// Settings.domoticz_sensor_idx[i] = 0;
// }
@@ -854,7 +854,7 @@ void SettingsDefaultSet2(void)
// Rules
// Settings.rule_enabled = 0;
// Settings.rule_once = 0;
-// for (uint8_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
+// for (uint32_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
Settings.flag2.calc_resolution = CALC_RESOLUTION;
// Home Assistant
@@ -872,7 +872,7 @@ void SettingsDefaultSet2(void)
//Settings.flag.decimal_text = 0;
Settings.pwm_frequency = PWM_FREQ;
Settings.pwm_range = PWM_RANGE;
- for (uint8_t i = 0; i < MAX_PWMS; i++) {
+ for (uint32_t i = 0; i < MAX_PWMS; i++) {
Settings.light_color[i] = 255;
// Settings.pwm_value[i] = 0;
}
@@ -901,8 +901,8 @@ void SettingsDefaultSet2(void)
strlcpy(Settings.ntp_server[0], NTP_SERVER1, sizeof(Settings.ntp_server[0]));
strlcpy(Settings.ntp_server[1], NTP_SERVER2, sizeof(Settings.ntp_server[1]));
strlcpy(Settings.ntp_server[2], NTP_SERVER3, sizeof(Settings.ntp_server[2]));
- for (uint8_t j = 0; j < 3; j++) {
- for (uint8_t i = 0; i < strlen(Settings.ntp_server[j]); i++) {
+ for (uint32_t j = 0; j < 3; j++) {
+ for (uint32_t i = 0; i < strlen(Settings.ntp_server[j]); i++) {
if (Settings.ntp_server[j][i] == ',') {
Settings.ntp_server[j][i] = '.';
}
@@ -915,7 +915,7 @@ void SettingsDefaultSet2(void)
Settings.button_debounce = KEY_DEBOUNCE_TIME;
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
- for (uint8_t j = 0; j < 5; j++) {
+ for (uint32_t j = 0; j < 5; j++) {
Settings.rgbwwTable[j] = 255;
}
@@ -996,7 +996,7 @@ void SettingsDefaultSet_5_13_1c(void)
void SettingsDefaultWebColor(void)
{
char scolor[10];
- for (uint8_t i = 0; i < COL_LAST; i++) {
+ for (uint32_t i = 0; i < COL_LAST; i++) {
WebHexCode(i, GetTextIndexed(scolor, sizeof(scolor), i, kWebColors));
}
}
@@ -1008,7 +1008,7 @@ void SettingsDelta(void)
if (Settings.version != VERSION) { // Fix version dependent changes
if (Settings.version < 0x05050000) {
- for (uint8_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
+ for (uint32_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
}
if (Settings.version < 0x05080000) {
@@ -1030,12 +1030,12 @@ void SettingsDelta(void)
Settings.altitude = 0;
}
if (Settings.version < 0x0508000B) {
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { // Move GPIO_LEDs
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { // Move GPIO_LEDs
if ((Settings.my_gp.io[i] >= 25) && (Settings.my_gp.io[i] <= 32)) { // Was GPIO_LED1
Settings.my_gp.io[i] += 23; // Move GPIO_LED1
}
}
- for (uint8_t i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
+ for (uint32_t i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
Settings.pwm_value[i] = Settings.pulse_timer[4 +i];
Settings.pulse_timer[4 +i] = 0;
}
@@ -1066,7 +1066,7 @@ void SettingsDelta(void)
char fingerprint[60];
memcpy(fingerprint, Settings.mqtt_fingerprint, sizeof(fingerprint));
char *p = fingerprint;
- for (uint8_t i = 0; i < 20; i++) {
+ for (uint32_t i = 0; i < 20; i++) {
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
Settings.mqtt_fingerprint[1][i] = Settings.mqtt_fingerprint[0][i];
}
@@ -1101,7 +1101,7 @@ void SettingsDelta(void)
SettingsDefaultSet_5_13_1c();
}
if (Settings.version < 0x050E0002) {
- for (uint8_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
+ for (uint32_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
Settings.rule_enabled = Settings.flag.mqtt_serial_raw; // Was rules_enabled until 5.14.0b
Settings.rule_once = Settings.flag.pressure_conversion; // Was rules_once until 5.14.0b
}
@@ -1110,14 +1110,14 @@ void SettingsDelta(void)
Settings.cfg_crc = GetSettingsCrc();
}
if (Settings.version < 0x06000002) {
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if (i < 4) {
Settings.switchmode[i] = Settings.interlock[i];
} else {
Settings.switchmode[i] = SWITCH_MODE;
}
}
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
Settings.my_gp.io[i] += 4;
}
@@ -1136,7 +1136,7 @@ void SettingsDelta(void)
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
}
if (Settings.version < 0x0602010A) {
- for (uint8_t j = 0; j < 5; j++) {
+ for (uint32_t j = 0; j < 5; j++) {
Settings.rgbwwTable[j] = 255;
}
}
@@ -1160,7 +1160,7 @@ void SettingsDelta(void)
}
if (Settings.version < 0x0604010B) {
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
- for (uint8_t i = 1; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; }
+ for (uint32_t i = 1; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; }
}
if (Settings.version < 0x0604010D) {
Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET;
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index 4ef78d8c4..8f14f714b 100755
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -269,7 +269,7 @@ char* GetTopic_P(char *stopic, uint8_t prefix, char *topic, const char* subtopic
fulltopic += F("/");
fulltopic += FPSTR(MQTT_TOKEN_PREFIX); // Need prefix for commands to handle mqtt topic loops
}
- for (uint8_t i = 0; i < 3; i++) {
+ for (uint32_t i = 0; i < 3; i++) {
if ('\0' == Settings.mqtt_prefix[i][0]) {
snprintf_P(Settings.mqtt_prefix[i], sizeof(Settings.mqtt_prefix[i]), kPrefixes[i]);
}
@@ -313,7 +313,7 @@ void SetLatchingRelay(power_t lpower, uint8_t state)
latching_relay_pulse = 2; // max 200mS (initiated by stateloop())
}
- for (uint8_t i = 0; i < devices_present; i++) {
+ for (uint32_t i = 0; i < devices_present; i++) {
uint8_t port = (i << 1) + ((latching_power >> i) &1);
if (pin[GPIO_REL1 +port] < 99) {
digitalWrite(pin[GPIO_REL1 +port], bitRead(rel_inverted, port) ? !state : state);
@@ -333,10 +333,10 @@ void SetDevicePower(power_t rpower, int source)
}
if (Settings.flag.interlock) { // Allow only one or no relay set
- for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
+ for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
power_t mask = 1;
uint8_t count = 0;
- for (uint8_t j = 0; j < devices_present; j++) {
+ for (uint32_t j = 0; j < devices_present; j++) {
if ((Settings.interlock[i] & mask) && (rpower & mask)) { count++; }
mask <<= 1;
}
@@ -368,7 +368,7 @@ void SetDevicePower(power_t rpower, int source)
SetLatchingRelay(rpower, 1);
}
else {
- for (uint8_t i = 0; i < devices_present; i++) {
+ for (uint32_t i = 0; i < devices_present; i++) {
state = rpower &1;
if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) {
digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? !state : state);
@@ -401,7 +401,7 @@ void SetLedPower(uint8_t state)
SetLedPowerIdx(0, state);
} else {
power_t mask = 1;
- for (uint8_t i = 0; i < leds_present; i++) { // Map leds to power
+ for (uint32_t i = 0; i < leds_present; i++) { // Map leds to power
bool tstate = (power & mask);
SetLedPowerIdx(i, tstate);
mask <<= 1;
@@ -411,7 +411,7 @@ void SetLedPower(uint8_t state)
void SetLedPowerAll(uint8_t state)
{
- for (uint8_t i = 0; i < leds_present; i++) {
+ for (uint32_t i = 0; i < leds_present; i++) {
SetLedPowerIdx(i, state);
}
}
@@ -449,7 +449,7 @@ uint8_t GetFanspeed(void)
void SetFanspeed(uint8_t fanspeed)
{
- for (uint8_t i = 0; i < MAX_FAN_SPEED -1; i++) {
+ for (uint32_t i = 0; i < MAX_FAN_SPEED -1; i++) {
uint8_t state = kIFan02Speed[fanspeed][i];
// uint8_t state = pgm_read_byte(kIFan02Speed +(speed *3) +i);
ExecuteCommandPower(i +2, state, SRC_IGNORE); // Use relay 2, 3 and 4
@@ -506,8 +506,8 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
bool jsflg = false;
bool grpflg = false;
// bool user_append_index = false;
- uint16_t i = 0;
- uint16_t index;
+ uint32_t i = 0;
+ uint32_t index;
uint32_t address;
#ifdef USE_DEBUG_DRIVER
@@ -728,7 +728,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
if ((payload >= POWER_ALL_OFF) && (payload <= POWER_ALL_OFF_PULSETIME_ON)) {
Settings.poweronstate = payload;
if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) {
- for (uint8_t i = 1; i <= devices_present; i++) {
+ for (uint32_t i = 1; i <= devices_present; i++) {
ExecuteCommandPower(i, POWER_ON, SRC_IGNORE);
}
}
@@ -942,7 +942,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
Settings.module = payload;
SetModuleType();
if (Settings.last_module != payload) {
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE;
}
}
@@ -953,7 +953,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
else if (CMND_MODULES == command_code) {
uint8_t midx = USER_MODULE;
- for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) {
+ for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) {
if (i > 0) { midx = pgm_read_byte(kModuleNiceList + i -1); }
if (!jsflg) {
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
@@ -981,7 +981,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
else if (CMND_ADCS == command_code) {
Response_P(PSTR("{\"" D_CMND_ADCS "\":["));
- for (uint8_t i = 0; i < ADC0_END; i++) {
+ for (uint32_t i = 0; i < ADC0_END; i++) {
if (jsflg) {
ResponseAppend_P(PSTR(","));
}
@@ -996,12 +996,12 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
ModuleGpios(&cmodule);
if (ValidGPIO(index, cmodule.io[index]) && (payload >= 0) && (payload < GPIO_SENSOR_END)) {
bool present = false;
- for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) {
+ for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) {
uint8_t midx = pgm_read_byte(kGpioNiceList + i);
if (midx == payload) { present = true; }
}
if (present) {
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == payload)) {
Settings.my_gp.io[i] = GPIO_NONE;
}
@@ -1011,7 +1011,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
}
Response_P(PSTR("{"));
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (ValidGPIO(i, cmodule.io[i])) {
if (jsflg) { ResponseAppend_P(PSTR(",")); }
jsflg = true;
@@ -1028,7 +1028,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
myio cmodule;
ModuleGpios(&cmodule);
uint8_t midx;
- for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) {
+ for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) {
midx = pgm_read_byte(kGpioNiceList + i);
if (!GetUsedInModule(midx, cmodule.io)) {
if (!jsflg) {
@@ -1070,7 +1070,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
snprintf_P(Settings.user_template.name, sizeof(Settings.user_template.name), PSTR("Merged"));
uint8_t j = 0;
- for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
+ for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
if (my_module.io[j] > GPIO_NONE) {
@@ -1109,7 +1109,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
else if (CMND_PWMRANGE == command_code) {
if ((1 == payload) || ((payload > 254) && (payload < 1024))) {
Settings.pwm_range = (1 == payload) ? PWM_RANGE : payload;
- for (uint8_t i = 0; i < MAX_PWMS; i++) {
+ for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (Settings.pwm_value[i] > Settings.pwm_range) {
Settings.pwm_value[i] = Settings.pwm_range;
}
@@ -1173,7 +1173,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
Serial.printf("%s\n", dataBuf); // "Hello Tiger\n"
}
else if (2 == index || 4 == index) {
- for (uint16_t i = 0; i < data_len; i++) {
+ for (uint32_t i = 0; i < data_len; i++) {
Serial.write(dataBuf[i]); // "Hello Tiger" or "A0"
}
}
@@ -1317,7 +1317,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
if (max_relays > 1) { // Only interlock with more than 1 relay
if (data_len > 0) {
if (strstr(dataBuf, ",") != nullptr) { // Interlock entry
- for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; } // Reset current interlocks
+ for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; } // Reset current interlocks
char *group;
char *q;
uint8_t group_index = 0;
@@ -1336,9 +1336,9 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
group_index++;
}
- for (uint8_t i = 0; i < group_index; i++) {
+ for (uint32_t i = 0; i < group_index; i++) {
uint8_t minimal_bits = 0;
- for (uint8_t j = 0; j < max_relays; j++) {
+ for (uint32_t j = 0; j < max_relays; j++) {
if (bitRead(Settings.interlock[i], j)) { minimal_bits++; }
}
if (minimal_bits < 2) { Settings.interlock[i] = 0; } // Discard single relay as interlock
@@ -1352,13 +1352,13 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
Response_P(PSTR("{\"" D_CMND_INTERLOCK "\":\"%s\",\"" D_JSON_GROUPS "\":\""), GetStateText(Settings.flag.interlock));
uint8_t anygroup = 0;
- for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
+ for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
if (Settings.interlock[i]) {
anygroup++;
ResponseAppend_P(PSTR("%s"), (anygroup > 1) ? " " : "");
uint8_t anybit = 0;
power_t mask = 1;
- for (uint8_t j = 0; j < max_relays; j++) {
+ for (uint32_t j = 0; j < max_relays; j++) {
if (Settings.interlock[i] & mask) {
anybit++;
ResponseAppend_P(PSTR("%s%d"), (anybit > 1) ? "," : "", j +1);
@@ -1368,7 +1368,7 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
}
}
if (!anygroup) {
- for (uint8_t j = 1; j <= max_relays; j++) {
+ for (uint32_t j = 1; j <= max_relays; j++) {
ResponseAppend_P(PSTR("%s%d"), (j > 1) ? "," : "", j);
}
}
@@ -1687,9 +1687,9 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source)
if (Settings.flag.interlock && !interlock_mutex) { // Clear all but masked relay in interlock group
interlock_mutex = true;
- for (uint8_t i = 0; i < MAX_INTERLOCKS; i++) {
+ for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) {
if (Settings.interlock[i] & mask) { // Find interlock group
- for (uint8_t j = 0; j < devices_present; j++) {
+ for (uint32_t j = 0; j < devices_present; j++) {
power_t imask = 1 << j;
if ((Settings.interlock[i] & imask) && (power & imask) && (mask != imask)) {
ExecuteCommandPower(j +1, POWER_OFF, SRC_IGNORE);
@@ -1749,7 +1749,7 @@ void StopAllPowerBlink(void)
{
power_t mask;
- for (uint8_t i = 1; i <= devices_present; i++) {
+ for (uint32_t i = 1; i <= devices_present; i++) {
mask = 1 << (i -1);
if (blink_mask & mask) {
blink_mask &= (POWER_MASK ^ mask); // Clear device mask
@@ -1813,11 +1813,11 @@ void PublishStatus(uint8_t payload)
uint8_t maxfn = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : (!devices_present) ? 1 : devices_present;
if (SONOFF_IFAN02 == my_module_type) { maxfn = 1; }
stemp[0] = '\0';
- for (uint8_t i = 0; i < maxfn; i++) {
+ for (uint32_t i = 0; i < maxfn; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%s%s\"%s\"" ), stemp, (i > 0 ? "," : ""), Settings.friendlyname[i]);
}
stemp2[0] = '\0';
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%s%d" ), stemp2, (i > 0 ? "," : ""), Settings.switchmode[i]);
}
Response_P(PSTR("{\"" D_CMND_STATUS "\":{\"" D_CMND_MODULE "\":%d,\"" D_CMND_FRIENDLYNAME "\":[%s],\"" D_CMND_TOPIC "\":\"%s\",\"" D_CMND_BUTTONTOPIC "\":\"%s\",\"" D_CMND_POWER "\":%d,\"" D_CMND_POWERONSTATE "\":%d,\"" D_CMND_LEDSTATE "\":%d,\"" D_CMND_LEDMASK "\":\"%04X\",\"" D_CMND_SAVEDATA "\":%d,\"" D_JSON_SAVESTATE "\":%d,\"" D_CMND_SWITCHTOPIC "\":\"%s\",\"" D_CMND_SWITCHMODE "\":[%s],\"" D_CMND_BUTTONRETAIN "\":%d,\"" D_CMND_SWITCHRETAIN "\":%d,\"" D_CMND_SENSORRETAIN "\":%d,\"" D_CMND_POWERRETAIN "\":%d}}"),
@@ -1839,7 +1839,7 @@ void PublishStatus(uint8_t payload)
if ((0 == payload) || (3 == payload)) {
stemp2[0] = '\0';
- for (int8_t i = 0; i < PARAM8_SIZE; i++) {
+ for (uint32_t i = 0; i < PARAM8_SIZE; i++) {
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s%02X"), stemp2, Settings.param[i]);
}
Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS3_LOGGING "\":{\"" D_CMND_SERIALLOG "\":%d,\"" D_CMND_WEBLOG "\":%d,\"" D_CMND_SYSLOG "\":%d,\"" D_CMND_LOGHOST "\":\"%s\",\"" D_CMND_LOGPORT "\":%d,\"" D_CMND_SSID "\":[\"%s\",\"%s\"],\"" D_CMND_TELEPERIOD "\":%d,\"" D_JSON_RESOLUTION "\":\"%08X\",\"" D_CMND_SETOPTION "\":[\"%08X\",\"%s\",\"%08X\"]}}"),
@@ -1919,7 +1919,7 @@ void MqttShowPWMState(void)
{
ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{"));
bool first = true;
- for (uint8_t i = 0; i < MAX_PWMS; i++) {
+ for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 + i] < 99) {
ResponseAppend_P(PSTR("%s\"" D_CMND_PWM "%d\":%d"), first ? "" : ",", i+1, Settings.pwm_value[i]);
first = false;
@@ -1942,7 +1942,7 @@ void MqttShowState(void)
ResponseAppend_P(PSTR(",\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u"),
GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), sleep, loop_load_avg);
- for (uint8_t i = 0; i < devices_present; i++) {
+ for (uint32_t i = 0; i < devices_present; i++) {
#ifdef USE_LIGHT
if (i == light_device -1) {
LightState(1);
@@ -1981,7 +1981,7 @@ bool MqttShowSensor(void)
{
ResponseAppend_P(PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str());
int json_data_start = strlen(mqtt_data);
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
#ifdef USE_TM1638
if ((pin[GPIO_SWT1 +i] < 99) || ((pin[GPIO_TM16CLK] < 99) && (pin[GPIO_TM16DIO] < 99) && (pin[GPIO_TM16STB] < 99))) {
#else
@@ -2100,7 +2100,7 @@ void Every100mSeconds(void)
if (!latching_relay_pulse) SetLatchingRelay(0, 0);
}
- for (uint8_t i = 0; i < MAX_PULSETIMERS; i++) {
+ for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) {
if (pulse_timer[i] != 0L) { // Timer active?
if (TimeReached(pulse_timer[i])) { // Timer finished?
pulse_timer[i] = 0L; // Turn off this timer
@@ -2267,7 +2267,7 @@ void Every250mSeconds(void)
if (save_data_counter <= 0) {
if (Settings.flag.save_state) {
power_t mask = POWER_MASK;
- for (uint8_t i = 0; i < MAX_PULSETIMERS; i++) {
+ for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) {
if ((Settings.pulse_timer[i] > 0) && (Settings.pulse_timer[i] < 30)) { // 3 seconds
mask &= ~(1 << i);
}
@@ -2500,7 +2500,7 @@ void SerialInput(void)
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), serial_in_buffer);
} else {
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\""));
- for (int i = 0; i < serial_in_byte_counter; i++) {
+ for (uint32_t i = 0; i < serial_in_byte_counter; i++) {
ResponseAppend_P(PSTR("%02x"), serial_in_buffer[i]);
}
ResponseAppend_P(PSTR("\"}"));
@@ -2529,7 +2529,7 @@ void GpioInit(void)
baudrate = APP_BAUDRATE;
}
- for (uint8_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
if ((Settings.user_template.gp.io[i] >= GPIO_SENSOR_END) && (Settings.user_template.gp.io[i] < GPIO_USER)) {
Settings.user_template.gp.io[i] = GPIO_USER; // Fix not supported sensor ids in template
}
@@ -2537,7 +2537,7 @@ void GpioInit(void)
myio def_gp;
ModuleGpios(&def_gp);
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
if ((Settings.my_gp.io[i] >= GPIO_SENSOR_END) && (Settings.my_gp.io[i] < GPIO_USER)) {
Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
}
@@ -2560,10 +2560,10 @@ void GpioInit(void)
my_adc0 = template_adc0; // Force Template override
}
- for (uint16_t i = 0; i < GPIO_MAX; i++) {
+ for (uint32_t i = 0; i < GPIO_MAX; i++) {
pin[i] = 99;
}
- for (uint8_t i = 0; i < sizeof(my_module.io); i++) {
+ for (uint32_t i = 0; i < sizeof(my_module.io); i++) {
mpin = ValidPin(i, my_module.io[i]);
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DBG: gpio pin %d, mpin %d"), i, mpin);
@@ -2628,7 +2628,7 @@ void GpioInit(void)
#ifdef USE_SPI
spi_flg = ((((pin[GPIO_SPI_CS] < 99) && (pin[GPIO_SPI_CS] > 14)) || (pin[GPIO_SPI_CS] < 12)) || (((pin[GPIO_SPI_DC] < 99) && (pin[GPIO_SPI_DC] > 14)) || (pin[GPIO_SPI_DC] < 12)));
if (spi_flg) {
- for (uint16_t i = 0; i < GPIO_MAX; i++) {
+ for (uint32_t i = 0; i < GPIO_MAX; i++) {
if ((pin[i] >= 12) && (pin[i] <=14)) pin[i] = 99;
}
my_module.io[12] = GPIO_SPI_MISO;
@@ -2651,7 +2651,7 @@ void GpioInit(void)
light_type = LT_BASIC; // Use basic PWM control if SetOption15 = 0
#ifdef USE_LIGHT
if (Settings.flag.pwm_control) {
- for (uint8_t i = 0; i < MAX_PWMS; i++) {
+ for (uint32_t i = 0; i < MAX_PWMS; i++) {
if (pin[GPIO_PWM1 +i] < 99) { light_type++; } // Use Dimmer/Color control for all PWM as SetOption15 = 1
}
}
@@ -2699,7 +2699,7 @@ void GpioInit(void)
#endif // USE_LIGHT
else {
if (!light_type) { devices_present = 0; }
- for (uint8_t i = 0; i < MAX_RELAYS; i++) {
+ for (uint32_t i = 0; i < MAX_RELAYS; i++) {
if (pin[GPIO_REL1 +i] < 99) {
pinMode(pin[GPIO_REL1 +i], OUTPUT);
devices_present++;
@@ -2711,7 +2711,7 @@ void GpioInit(void)
}
}
- for (uint8_t i = 0; i < MAX_LEDS; i++) {
+ for (uint32_t i = 0; i < MAX_LEDS; i++) {
if (pin[GPIO_LED1 +i] < 99) {
#ifdef USE_ARILUX_RF
if ((3 == i) && (leds_present < 2) && (99 == pin[GPIO_ARIRFSEL])) {
@@ -2753,7 +2753,7 @@ void GpioInit(void)
#endif // USE_SM16716
#endif // USE_LIGHT
if (!light_type) {
- for (uint8_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
+ for (uint32_t i = 0; i < MAX_PWMS; i++) { // Basic PWM control only
if (pin[GPIO_PWM1 +i] < 99) {
pwm_present = true;
pinMode(pin[GPIO_PWM1 +i], OUTPUT);
@@ -2828,7 +2828,7 @@ void setup(void)
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET]) { // Restart twice
Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +1) { // Restart 3 times
- for (uint8_t i = 0; i < MAX_RULE_SETS; i++) {
+ for (uint32_t i = 0; i < MAX_RULE_SETS; i++) {
if (bitRead(Settings.rule_stop, i)) {
bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop
}
@@ -2838,7 +2838,7 @@ void setup(void)
Settings.rule_enabled = 0; // Disable all rules
}
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
}
Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors
@@ -2903,7 +2903,7 @@ void setup(void)
}
// Issue #526 and #909
- for (uint8_t i = 0; i < devices_present; i++) {
+ for (uint32_t i = 0; i < devices_present; i++) {
if (!Settings.flag3.no_power_feedback) { // #5594 and #5663
if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) {
bitWrite(power, i, digitalRead(pin[GPIO_REL1 +i]) ^ bitRead(rel_inverted, i));
diff --git a/sonoff/support.ino b/sonoff/support.ino
index ef04075a3..be441f167 100644
--- a/sonoff/support.ino
+++ b/sonoff/support.ino
@@ -690,7 +690,7 @@ double TaylorLog(double x)
double totalValue = 0;
double powe = 1;
double y;
- for (int count = 0; count < 10; count++) { // Experimental number of 10 iterations
+ for (uint32_t count = 0; count < 10; count++) { // Experimental number of 10 iterations
z *= step;
y = (1 / powe) * z;
totalValue = totalValue + y;
@@ -865,7 +865,7 @@ void SerialSendRaw(char *codes)
uint32_t GetHash(const char *buffer, size_t size)
{
uint32_t hash = 0;
- for (uint16_t i = 0; i <= size; i++) {
+ for (uint32_t i = 0; i <= size; i++) {
hash += (uint8_t)*buffer++ * (i +1);
}
return hash;
@@ -958,7 +958,7 @@ uint8_t ModuleNr()
bool ValidTemplateModule(uint8_t index)
{
- for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) {
+ for (uint32_t i = 0; i < sizeof(kModuleNiceList); i++) {
if (index == pgm_read_byte(kModuleNiceList + i)) {
return true;
}
@@ -1002,7 +1002,7 @@ void ModuleGpios(myio *gp)
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
uint8_t j = 0;
- for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
+ for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
dest[j] = src[i];
@@ -1117,7 +1117,7 @@ bool GetUsedInModule(uint8_t val, uint8_t *arr)
offset = -(GPIO_CNTR1_NP - GPIO_CNTR1);
}
- for (uint8_t i = 0; i < MAX_GPIO_PIN; i++) {
+ for (uint32_t i = 0; i < MAX_GPIO_PIN; i++) {
if (arr[i] == val) { return true; }
if (arr[i] == val + offset) { return true; }
}
@@ -1140,7 +1140,7 @@ bool JsonTemplate(const char* dataBuf)
strlcpy(Settings.user_template.name, name, sizeof(Settings.user_template.name));
}
if (obj[D_JSON_GPIO].success()) {
- for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
+ for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
}
}
@@ -1159,7 +1159,7 @@ bool JsonTemplate(const char* dataBuf)
void TemplateJson()
{
Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), Settings.user_template.name);
- for (uint8_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
ResponseAppend_P(PSTR("%s%d"), (i>0)?",":"", Settings.user_template.gp.io[i]);
}
ResponseAppend_P(PSTR("],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), Settings.user_template.flag, Settings.user_template_base +1);
@@ -1249,7 +1249,7 @@ bool I2cValidRead(uint8_t addr, uint8_t reg, uint8_t size)
if (0 == Wire.endTransmission(false)) { // Try to become I2C Master, send data and collect bytes, keep master status for next request...
Wire.requestFrom((int)addr, (int)size); // send data n-bytes read
if (Wire.available() == size) {
- for (uint8_t i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; i++) {
i2c_buffer = i2c_buffer << 8 | Wire.read(); // receive DATA
}
status = true;
@@ -1572,7 +1572,7 @@ void AddLog_P2(uint8_t loglevel, PGM_P formatP, ...)
void AddLogBuffer(uint8_t loglevel, uint8_t *buffer, int count)
{
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
- for (int i = 0; i < count; i++) {
+ for (uint32_t i = 0; i < count; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer++));
}
AddLog(loglevel);
diff --git a/sonoff/support_button.ino b/sonoff/support_button.ino
index dc653c8f8..9311cd838 100644
--- a/sonoff/support_button.ino
+++ b/sonoff/support_button.ino
@@ -52,7 +52,7 @@ void ButtonInvertFlag(uint8 button_bit)
void ButtonInit(void)
{
buttons_present = 0;
- for (uint8_t i = 0; i < MAX_KEYS; i++) {
+ for (uint32_t i = 0; i < MAX_KEYS; i++) {
if (pin[GPIO_KEY1 +i] < 99) {
buttons_present++;
pinMode(pin[GPIO_KEY1 +i], bitRead(key_no_pullup, i) ? INPUT : ((16 == pin[GPIO_KEY1 +i]) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
@@ -110,8 +110,8 @@ void ButtonHandler(void)
char scmnd[20];
// uint8_t maxdev = (devices_present > MAX_KEYS) ? MAX_KEYS : devices_present;
-// for (uint8_t button_index = 0; button_index < maxdev; button_index++) {
- for (uint8_t button_index = 0; button_index < MAX_KEYS; button_index++) {
+// for (uint32_t button_index = 0; button_index < maxdev; button_index++) {
+ for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
button = NOT_PRESSED;
button_present = 0;
diff --git a/sonoff/support_switch.ino b/sonoff/support_switch.ino
index 3eb927388..ca1d486fa 100644
--- a/sonoff/support_switch.ino
+++ b/sonoff/support_switch.ino
@@ -71,7 +71,7 @@ void SwitchProbe(void)
uint8_t force_high = (Settings.switch_debounce % 50) &1; // 51, 101, 151 etc
uint8_t force_low = (Settings.switch_debounce % 50) &2; // 52, 102, 152 etc
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) {
// Olimex user_switch2.c code to fix 50Hz induced pulses
if (1 == digitalRead(pin[GPIO_SWT1 +i])) {
@@ -111,7 +111,7 @@ void SwitchProbe(void)
void SwitchInit(void)
{
switches_found = 0;
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
lastwallswitch[i] = 1; // Init global to virtual switch state;
if (pin[GPIO_SWT1 +i] < 99) {
switches_found++;
@@ -135,7 +135,7 @@ void SwitchHandler(uint8_t mode)
uint8_t switchflag;
uint16_t loops_per_second = 1000 / Settings.switch_debounce;
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
if ((pin[GPIO_SWT1 +i] < 99) || (mode)) {
if (holdwallswitch[i]) {
diff --git a/sonoff/support_wifi.ino b/sonoff/support_wifi.ino
index 8c406fad5..08b8a36e2 100644
--- a/sonoff/support_wifi.ino
+++ b/sonoff/support_wifi.ino
@@ -296,7 +296,7 @@ void WifiBeginAfterScan()
if (wifi_scan_result > 0) {
// Networks found
- for (int8_t i = 0; i < wifi_scan_result; ++i) {
+ for (uint32_t i = 0; i < wifi_scan_result; ++i) {
String ssid_scan;
int32_t rssi_scan;
@@ -308,7 +308,7 @@ void WifiBeginAfterScan()
WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, bssid_scan, chan_scan, hidden_scan);
bool known = false;
- uint8_t j;
+ uint32_t j;
for (j = 0; j < 2; j++) {
if (ssid_scan == Settings.sta_ssid[j]) { // SSID match
known = true;
@@ -332,7 +332,7 @@ void WifiBeginAfterScan()
}
wifi_scan_state = 0;
// If bssid changed then (re)connect wifi
- for (uint8_t i = 0; i < sizeof(wifi_bssid); i++) {
+ for (uint32_t i = 0; i < sizeof(wifi_bssid); i++) {
if (last_bssid[i] != wifi_bssid[i]) {
WifiBegin(ap, channel); // 0 (AP1), 1 (AP2) or 3 (default AP)
break;
diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino
index 6beda6c25..3653045ef 100644
--- a/sonoff/xdrv_01_webserver.ino
+++ b/sonoff/xdrv_01_webserver.ino
@@ -725,7 +725,7 @@ void WSContentSend_PD(const char* formatP, ...) // Content send snprintf_P ch
va_end(arg);
if (D_DECIMAL_SEPARATOR[0] != '.') {
- for (int i = 0; i < len; i++) {
+ for (uint32_t i = 0; i < len; i++) {
if ('.' == mqtt_data[i]) {
mqtt_data[i] = D_DECIMAL_SEPARATOR[0];
}
@@ -944,12 +944,12 @@ void HandleRoot(void)
WSContentSend_P(PSTR("
"));
if (SONOFF_IFAN02 == my_module_type) {
WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, "");
- for (uint8_t i = 0; i < MAX_FAN_SPEED; i++) {
+ for (uint32_t i = 0; i < MAX_FAN_SPEED; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i);
WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, stemp, "");
}
} else {
- for (uint8_t idx = 1; idx <= devices_present; idx++) {
+ for (uint32_t idx = 1; idx <= devices_present; idx++) {
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : "");
}
@@ -960,9 +960,9 @@ void HandleRoot(void)
WSContentSend_P(HTTP_TABLE100);
WSContentSend_P(PSTR("
"));
uint8_t idx = 0;
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
if (idx > 0) { WSContentSend_P(PSTR("
")); }
- for (uint8_t j = 0; j < 4; j++) {
+ for (uint32_t j = 0; j < 4; j++) {
idx++;
WSContentSend_P(PSTR(" | "), idx, idx); // &k is related to WebGetArg("k", tmp, sizeof(tmp));
}
@@ -1048,7 +1048,7 @@ bool HandleRootStatusRefresh(void)
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), fanspeed);
WSContentSend_P(HTTP_DEVICE_STATE, 64, (fanspeed) ? "bold" : "normal", 54, (fanspeed) ? svalue : GetStateText(0));
} else {
- for (uint8_t idx = 1; idx <= devices_present; idx++) {
+ for (uint32_t idx = 1; idx <= devices_present; idx++) {
snprintf_P(svalue, sizeof(svalue), PSTR("%d"), bitRead(power, idx -1));
WSContentSend_P(HTTP_DEVICE_STATE, 100 / devices_present, (bitRead(power, idx -1)) ? "bold" : "normal", fsize, (devices_present < 5) ? GetStateText(bitRead(power, idx -1)) : svalue);
}
@@ -1107,7 +1107,7 @@ void HandleTemplateConfiguration(void)
if (WebServer->hasArg("m")) {
WSContentBegin(200, CT_PLAIN);
- for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
+ for (uint32_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
uint8_t midx = pgm_read_byte(kModuleNiceList + i);
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
}
@@ -1127,7 +1127,7 @@ void HandleTemplateConfiguration(void)
WSContentBegin(200, CT_PLAIN);
WSContentSend_P(PSTR("%s}1"), AnyModuleName(module).c_str()); // NAME: Generic
- for (uint8_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3...
+ for (uint32_t i = 0; i < sizeof(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3...
if (1 == i) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, 255, D_SENSOR_USER, 255); // }2'255'>User (255)}3
}
@@ -1136,7 +1136,7 @@ void HandleTemplateConfiguration(void)
}
WSContentSend_P(PSTR("}1")); // Field separator
- for (uint8_t i = 0; i < ADC0_END; i++) { // FLAG: }2'0'>None (0)}3}2'17'>Analog (17)}3...
+ for (uint32_t i = 0; i < ADC0_END; i++) { // FLAG: }2'0'>None (0)}3}2'17'>Analog (17)}3...
if (1 == i) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, ADC0_USER, D_SENSOR_USER, ADC0_USER); // }2'15'>User (15)}3
}
@@ -1144,7 +1144,7 @@ void HandleTemplateConfiguration(void)
}
WSContentSend_P(PSTR("}1")); // Field separator
- for (uint8_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
+ for (uint32_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]);
}
@@ -1167,7 +1167,7 @@ void HandleTemplateConfiguration(void)
""
"
"));
WSContentSend_P(HTTP_TABLE100);
- for (uint8_t i = 0; i < 17; i++) {
+ for (uint32_t i = 0; i < 17; i++) {
if ((i < 6) || ((i > 8) && (i != 11))) { // Ignore flash pins GPIO06, 7, 8 and 11
WSContentSend_P(PSTR("
" D_GPIO "%d | |
"),
((9==i)||(10==i)) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? " style='width:200px'" : "", i);
@@ -1194,7 +1194,7 @@ void TemplateSaveSettings(void)
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
uint8_t j = 0;
- for (uint8_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j);
@@ -1206,7 +1206,7 @@ void TemplateSaveSettings(void)
WebGetArg("g17", tmp, sizeof(tmp)); // FLAG - ADC0
uint8_t flag = atoi(tmp);
- for (uint8_t i = 0; i < GPIO_FLAG_USED; i++) {
+ for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {
snprintf_P(webindex, sizeof(webindex), PSTR("c%d"), i);
uint8_t state = WebServer->hasArg(webindex) << i +4; // FLAG
flag += state;
@@ -1238,7 +1238,7 @@ void HandleModuleConfiguration(void)
if (WebServer->hasArg("m")) {
WSContentBegin(200, CT_PLAIN);
uint8_t vidx = 0;
- for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
+ for (uint32_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
if (0 == i) {
midx = USER_MODULE;
vidx = 0;
@@ -1254,7 +1254,7 @@ void HandleModuleConfiguration(void)
if (WebServer->hasArg("g")) {
WSContentBegin(200, CT_PLAIN);
- for (uint8_t j = 0; j < sizeof(kGpioNiceList); j++) {
+ for (uint32_t j = 0; j < sizeof(kGpioNiceList); j++) {
midx = pgm_read_byte(kGpioNiceList + j);
if (!GetUsedInModule(midx, cmodule.io)) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames), midx);
@@ -1267,7 +1267,7 @@ void HandleModuleConfiguration(void)
#ifndef USE_ADC_VCC
if (WebServer->hasArg("a")) {
WSContentBegin(200, CT_PLAIN);
- for (uint8_t j = 0; j < ADC0_END; j++) {
+ for (uint32_t j = 0; j < ADC0_END; j++) {
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, j, GetTextIndexed(stemp, sizeof(stemp), j, kAdc0Names), j);
}
WSContentEnd();
@@ -1280,7 +1280,7 @@ void HandleModuleConfiguration(void)
WSContentStart_P(S_CONFIGURE_MODULE);
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module);
- for (uint8_t i = 0; i < sizeof(cmodule); i++) {
+ for (uint32_t i = 0; i < sizeof(cmodule); i++) {
if (ValidGPIO(i, cmodule.io[i])) {
WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16
}
@@ -1288,7 +1288,7 @@ void HandleModuleConfiguration(void)
WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0);
WSContentSendStyle();
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str());
- for (uint8_t i = 0; i < sizeof(cmodule); i++) {
+ for (uint32_t i = 0; i < sizeof(cmodule); i++) {
if (ValidGPIO(i, cmodule.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2);
char sesp8285[40];
@@ -1321,7 +1321,7 @@ void ModuleSaveSettings(void)
myio cmodule;
ModuleGpios(&cmodule);
String gpios = "";
- for (uint8_t i = 0; i < sizeof(cmodule); i++) {
+ for (uint32_t i = 0; i < sizeof(cmodule); i++) {
if (Settings.last_module != new_module) {
Settings.my_gp.io[i] = GPIO_NONE;
} else {
@@ -1397,13 +1397,13 @@ void HandleWifiConfiguration(void)
} else {
//sort networks
int indices[n];
- for (int i = 0; i < n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
indices[i] = i;
}
// RSSI SORT
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
+ for (uint32_t i = 0; i < n; i++) {
+ for (uint32_t j = i + 1; j < n; j++) {
if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) {
std::swap(indices[i], indices[j]);
}
@@ -1413,10 +1413,10 @@ void HandleWifiConfiguration(void)
// remove duplicates ( must be RSSI sorted )
if (remove_duplicate_access_points) {
String cssid;
- for (int i = 0; i < n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
if (-1 == indices[i]) { continue; }
cssid = WiFi.SSID(indices[i]);
- for (int j = i + 1; j < n; j++) {
+ for (uint32_t j = i + 1; j < n; j++) {
if (cssid == WiFi.SSID(indices[j])) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_DUPLICATE_ACCESSPOINT " %s"), WiFi.SSID(indices[j]).c_str());
indices[j] = -1; // set dup aps to index -1
@@ -1426,7 +1426,7 @@ void HandleWifiConfiguration(void)
}
//display networks in page
- for (int i = 0; i < n; i++) {
+ for (uint32_t i = 0; i < n; i++) {
if (-1 == indices[i]) { continue; } // skip dups
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI D_SSID " %s, " D_BSSID " %s, " D_CHANNEL " %d, " D_RSSI " %d"), WiFi.SSID(indices[i]).c_str(), WiFi.BSSIDstr(indices[i]).c_str(), WiFi.channel(indices[i]), WiFi.RSSI(indices[i]));
int quality = WifiGetRssiAsQuality(WiFi.RSSI(indices[i]));
@@ -1508,13 +1508,13 @@ void HandleLoggingConfiguration(void)
char stemp1[45];
char stemp2[32];
uint8_t dlevel[3] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE };
- for (uint8_t idx = 0; idx < 3; idx++) {
+ for (uint32_t idx = 0; idx < 3; idx++) {
uint8_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:Settings.syslog_level;
WSContentSend_P(PSTR("%s (%s)
-> "));
WSContentSend_P(HTTP_FORM_KNX_GA, "GA_FNUM", "GA_AREA", "GA_FDEF");
WSContentSend_P(HTTP_FORM_KNX_ADD_BTN, "GAwarning", (Settings.knx_GA_registered < MAX_KNX_GA) ? "" : "disabled", 1);
- for (uint8_t i = 0; i < Settings.knx_GA_registered ; ++i)
+ for (uint32_t i = 0; i < Settings.knx_GA_registered ; ++i)
{
if ( Settings.knx_GA_param[i] )
{
@@ -911,7 +911,7 @@ void HandleKNXConfiguration(void)
WSContentSend_P(HTTP_FORM_KNX4);
uint8_t j;
- for (uint8_t i = 0; i < KNX_MAX_device_param ; i++)
+ for (uint32_t i = 0; i < KNX_MAX_device_param ; i++)
{
// Check How many Relays are available and add: RelayX and TogleRelayX
if ( (i > 8) && (i < 16) ) { j=i-8; } else { j=i; }
@@ -924,7 +924,7 @@ void HandleKNXConfiguration(void)
WSContentSend_P(PSTR(" "));
WSContentSend_P(HTTP_FORM_KNX_ADD_BTN, "CBwarning", (Settings.knx_CB_registered < MAX_KNX_CB) ? "" : "disabled", 2);
- for (uint8_t i = 0; i < Settings.knx_CB_registered ; ++i)
+ for (uint32_t i = 0; i < Settings.knx_CB_registered ; ++i)
{
if ( Settings.knx_CB_param[i] )
{
@@ -964,7 +964,7 @@ void KNX_Save_Settings(void)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_KNX "GA: %d"),
Settings.knx_GA_registered );
- for (uint8_t i = 0; i < Settings.knx_GA_registered ; ++i)
+ for (uint32_t i = 0; i < Settings.knx_GA_registered ; ++i)
{
KNX_addr.value = Settings.knx_GA_addr[i];
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_KNX "GA #%d: %s " D_TO " %d/%d/%d"),
@@ -975,7 +975,7 @@ void KNX_Save_Settings(void)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_KNX "CB: %d"),
Settings.knx_CB_registered );
- for (uint8_t i = 0; i < Settings.knx_CB_registered ; ++i)
+ for (uint32_t i = 0; i < Settings.knx_CB_registered ; ++i)
{
KNX_addr.value = Settings.knx_CB_addr[i];
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_KNX "CB #%d: %d/%d/%d " D_TO " %s"),
diff --git a/sonoff/xdrv_12_home_assistant.ino b/sonoff/xdrv_12_home_assistant.ino
index 406e6d451..78002fbbd 100644
--- a/sonoff/xdrv_12_home_assistant.ino
+++ b/sonoff/xdrv_12_home_assistant.ino
@@ -197,7 +197,7 @@ void HAssAnnounceRelayLight(void)
bool is_light = false;
bool is_topic_light = false;
- for (int i = 1; i <= MAX_RELAYS; i++) {
+ for (uint32_t i = 1; i <= MAX_RELAYS; i++) {
is_light = ((i == devices_present) && (light_type));
is_topic_light = Settings.flag.hass_light || is_light;
@@ -334,7 +334,7 @@ void HAssAnnounceSwitches(void)
char *tmp = Settings.switch_topic;
Format(sw_topic, tmp, sizeof(sw_topic));
if ((strlen(sw_topic) != 0) && strcmp(sw_topic, "0")) {
- for (uint8_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
+ for (uint32_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) {
uint8_t switch_present = 0;
uint8_t toggle = 1;
@@ -363,7 +363,7 @@ void HAssAnnounceButtons(void)
char *tmp = Settings.button_topic;
Format(key_topic, tmp, sizeof(key_topic));
if ((strlen(key_topic) != 0) && strcmp(key_topic, "0")) {
- for (uint8_t button_index = 0; button_index < MAX_KEYS; button_index++) {
+ for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) {
uint8_t button_present = 0;
uint8_t toggle = 1;
diff --git a/sonoff/xdrv_13_display.ino b/sonoff/xdrv_13_display.ino
index 3f40bdb84..b00f2a3ce 100644
--- a/sonoff/xdrv_13_display.ino
+++ b/sonoff/xdrv_13_display.ino
@@ -495,7 +495,7 @@ void DisplayText(void)
void DisplayClearScreenBuffer(void)
{
if (disp_screen_buffer_cols) {
- for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
+ for (uint32_t i = 0; i < disp_screen_buffer_rows; i++) {
memset(disp_screen_buffer[i], 0, disp_screen_buffer_cols);
}
}
@@ -504,7 +504,7 @@ void DisplayClearScreenBuffer(void)
void DisplayFreeScreenBuffer(void)
{
if (disp_screen_buffer != nullptr) {
- for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
+ for (uint32_t i = 0; i < disp_screen_buffer_rows; i++) {
if (disp_screen_buffer[i] != nullptr) { free(disp_screen_buffer[i]); }
}
free(disp_screen_buffer);
@@ -519,7 +519,7 @@ void DisplayAllocScreenBuffer(void)
disp_screen_buffer_rows = Settings.display_rows;
disp_screen_buffer = (char**)malloc(sizeof(*disp_screen_buffer) * disp_screen_buffer_rows);
if (disp_screen_buffer != nullptr) {
- for (uint8_t i = 0; i < disp_screen_buffer_rows; i++) {
+ for (uint32_t i = 0; i < disp_screen_buffer_rows; i++) {
disp_screen_buffer[i] = (char*)malloc(sizeof(*disp_screen_buffer[i]) * (Settings.display_cols[0] +1));
if (disp_screen_buffer[i] == nullptr) {
DisplayFreeScreenBuffer();
@@ -554,7 +554,7 @@ void DisplayFillScreen(uint8_t line)
void DisplayClearLogBuffer(void)
{
if (disp_log_buffer_cols) {
- for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
+ for (uint32_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
memset(disp_log_buffer[i], 0, disp_log_buffer_cols);
}
}
@@ -563,7 +563,7 @@ void DisplayClearLogBuffer(void)
void DisplayFreeLogBuffer(void)
{
if (disp_log_buffer != nullptr) {
- for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
+ for (uint32_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
if (disp_log_buffer[i] != nullptr) { free(disp_log_buffer[i]); }
}
free(disp_log_buffer);
@@ -576,7 +576,7 @@ void DisplayAllocLogBuffer(void)
if (!disp_log_buffer_cols) {
disp_log_buffer = (char**)malloc(sizeof(*disp_log_buffer) * DISPLAY_LOG_ROWS);
if (disp_log_buffer != nullptr) {
- for (uint8_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
+ for (uint32_t i = 0; i < DISPLAY_LOG_ROWS; i++) {
disp_log_buffer[i] = (char*)malloc(sizeof(*disp_log_buffer[i]) * (Settings.display_cols[0] +1));
if (disp_log_buffer[i] == nullptr) {
DisplayFreeLogBuffer();
diff --git a/sonoff/xdrv_14_mp3.ino b/sonoff/xdrv_14_mp3.ino
index 5e74b7122..d00eefe88 100644
--- a/sonoff/xdrv_14_mp3.ino
+++ b/sonoff/xdrv_14_mp3.ino
@@ -123,7 +123,7 @@ enum MP3_Commands { // commands useable in conso
uint16_t MP3_Checksum(uint8_t *array)
{
uint16_t checksum = 0;
- for (uint8_t i = 0; i < 6; i++) {
+ for (uint32_t i = 0; i < 6; i++) {
checksum += array[i];
}
checksum = checksum^0xffff;
diff --git a/sonoff/xdrv_15_pca9685.ino b/sonoff/xdrv_15_pca9685.ino
index e3ffbaa8e..3e8d26e42 100644
--- a/sonoff/xdrv_15_pca9685.ino
+++ b/sonoff/xdrv_15_pca9685.ino
@@ -56,7 +56,7 @@ void PCA9685_Reset(void)
{
I2cWrite8(USE_PCA9685_ADDR, PCA9685_REG_MODE1, 0x80);
PCA9685_SetPWMfreq(USE_PCA9685_FREQ);
- for (uint8_t pin=0;pin<16;pin++) {
+ for (uint32_t pin=0;pin<16;pin++) {
PCA9685_SetPWM(pin,0,false);
pca9685_pin_pwm_value[pin] = 0;
}
@@ -112,7 +112,7 @@ bool PCA9685_Command(void)
return serviced;
}
char sub_string[XdrvMailbox.data_len];
- for (uint8_t ca=0;cawrite(payload_len >> 8); // following data length (Hi)
TuyaSerial->write(payload_len & 0xFF); // following data length (Lo)
snprintf_P(log_data, sizeof(log_data), PSTR("TYA: TX Packet: \"55aa00%02x%02x%02x"), cmd, payload_len >> 8, payload_len & 0xFF);
- for(int i = 0; i < payload_len; ++i) {
+ for (uint32_t i = 0; i < payload_len; ++i) {
TuyaSerial->write(payload[i]);
checksum += payload[i];
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, payload[i]);
@@ -248,7 +248,7 @@ void TuyaPacketProcess(void)
uint8_t key1_gpio = tuya_buffer[7];
bool key1_set = false;
bool led1_set = false;
- for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
+ for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true;
else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true;
}
@@ -337,7 +337,7 @@ void TuyaSerialInput(void)
tuya_buffer[tuya_byte_counter++] = serial_in_byte;
snprintf_P(log_data, sizeof(log_data), PSTR("TYA: RX Packet: \""));
- for (int i = 0; i < tuya_byte_counter; i++) {
+ for (uint32_t i = 0; i < tuya_byte_counter; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s%02x"), log_data, tuya_buffer[i]);
}
snprintf_P(log_data, sizeof(log_data), PSTR("%s\""), log_data);
diff --git a/sonoff/xdrv_18_armtronix_dimmers.ino b/sonoff/xdrv_18_armtronix_dimmers.ino
index 16176539a..4ce30f6b0 100644
--- a/sonoff/xdrv_18_armtronix_dimmers.ino
+++ b/sonoff/xdrv_18_armtronix_dimmers.ino
@@ -113,7 +113,7 @@ void ArmtronixSerialInput(void)
answer = ArmtronixSerial->readStringUntil('\n');
if (answer.substring(0,7) == "Status:") {
commaIndex = 6;
- for (int i =0; i<2; i++) {
+ for (uint32_t i =0; i<2; i++) {
newDimState[i] = answer.substring(commaIndex+1,answer.indexOf(',',commaIndex+1)).toInt();
if (newDimState[i] != armtronix_dimState[i]) {
temp = ((float)newDimState[i])*1.01010101010101; //max 255
diff --git a/sonoff/xdrv_20_hue.ino b/sonoff/xdrv_20_hue.ino
index 0041cb1a3..f9546e6b5 100644
--- a/sonoff/xdrv_20_hue.ino
+++ b/sonoff/xdrv_20_hue.ino
@@ -364,7 +364,7 @@ void HueGlobalConfig(String *path)
path->remove(0,1); // cut leading / to get
response = F("{\"lights\":{\"");
- for (uint8_t i = 1; i <= maxhue; i++) {
+ for (uint32_t i = 1; i <= maxhue; i++) {
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
@@ -408,7 +408,7 @@ void HueLights(String *path)
path->remove(0,path->indexOf("/lights")); // Remove until /lights
if (path->endsWith("/lights")) { // Got /lights
response = "{\"";
- for (uint8_t i = 1; i <= maxhue; i++) {
+ for (uint32_t i = 1; i <= maxhue; i++) {
response += EncodeLightId(i);
response += F("\":{\"state\":");
HueLightStatus1(i, &response);
@@ -604,7 +604,7 @@ void HueGroups(String *path)
if (path->endsWith("/0")) {
response = FPSTR(HUE_GROUP0_STATUS_JSON);
String lights = F("\"1\"");
- for (uint8_t i = 2; i <= maxhue; i++) {
+ for (uint32_t i = 2; i <= maxhue; i++) {
lights += ",\"";
lights += EncodeLightId(i);
lights += "\"";
diff --git a/sonoff/xdrv_99_debug.ino b/sonoff/xdrv_99_debug.ino
index e3e90a398..46d2af06f 100644
--- a/sonoff/xdrv_99_debug.ino
+++ b/sonoff/xdrv_99_debug.ino
@@ -327,11 +327,11 @@ void DebugCfgPeek(char* parms)
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16;
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), address);
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[address +i]);
}
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' ');
}
snprintf_P(log_data, sizeof(log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), log_data, data8, data8, data16, data16, data32, data32);
@@ -352,7 +352,7 @@ void DebugCfgPoke(char* parms)
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
uint8_t *nbuffer = (uint8_t *) &data;
- for (uint8_t i = 0; i < 4; i++) { buffer[address +i] = nbuffer[+i]; }
+ for (uint32_t i = 0; i < 4; i++) { buffer[address +i] = nbuffer[+i]; }
uint32_t ndata32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino
index 84f80062b..7dddf1353 100644
--- a/sonoff/xdrv_interface.ino
+++ b/sonoff/xdrv_interface.ino
@@ -225,7 +225,7 @@ bool XdrvCall(uint8_t Function)
{
bool result = false;
- for (uint8_t x = 0; x < xdrv_present; x++) {
+ for (uint32_t x = 0; x < xdrv_present; x++) {
// WifiAddDelayWhenDisconnected();
result = xdrv_func_ptr[x](Function);
diff --git a/sonoff/xdsp_01_lcd.ino b/sonoff/xdsp_01_lcd.ino
index c0877a859..2c75c040c 100644
--- a/sonoff/xdsp_01_lcd.ino
+++ b/sonoff/xdsp_01_lcd.ino
@@ -110,7 +110,7 @@ void LcdCenter(uint8_t row, char* txt)
}
memset(line, 0x20, Settings.display_cols[0]);
line[Settings.display_cols[0]] = 0;
- for (uint8_t i = 0; i < len; i++) {
+ for (uint32_t i = 0; i < len; i++) {
line[offset +i] = txt[i];
}
lcd->setCursor(0, row);
@@ -130,7 +130,7 @@ bool LcdPrintLog(void)
if (txt != nullptr) {
uint8_t last_row = Settings.display_rows -1;
- for (uint8_t i = 0; i < last_row; i++) {
+ for (uint32_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
lcd->setCursor(0, i); // Col 0, Row i
lcd->print(disp_screen_buffer[i +1]);
diff --git a/sonoff/xdsp_02_ssd1306.ino b/sonoff/xdsp_02_ssd1306.ino
index 8d8b696d7..62047347f 100644
--- a/sonoff/xdsp_02_ssd1306.ino
+++ b/sonoff/xdsp_02_ssd1306.ino
@@ -147,7 +147,7 @@ void Ssd1306PrintLog(void)
oled->clearDisplay();
oled->setTextSize(Settings.display_size);
oled->setCursor(0,0);
- for (uint8_t i = 0; i < last_row; i++) {
+ for (uint32_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
oled->println(disp_screen_buffer[i]);
}
diff --git a/sonoff/xdsp_03_matrix.ino b/sonoff/xdsp_03_matrix.ino
index a77b5df1e..a86d5cfac 100644
--- a/sonoff/xdsp_03_matrix.ino
+++ b/sonoff/xdsp_03_matrix.ino
@@ -47,14 +47,14 @@ uint8_t mtx_done = 0;
void MatrixWrite(void)
{
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->writeDisplay();
}
}
void MatrixClear(void)
{
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
}
MatrixWrite();
@@ -62,7 +62,7 @@ void MatrixClear(void)
void MatrixFixed(char* txt)
{
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(-i *8, 0);
matrix[i]->print(txt);
@@ -77,7 +77,7 @@ void MatrixCenter(char* txt)
int len = strlen(txt);
offset = (len < 8) ? offset = ((mtx_matrices *8) - (len *6)) / 2 : 0;
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(-(i *8)+offset, 0);
matrix[i]->print(txt);
@@ -101,7 +101,7 @@ void MatrixScrollLeft(char* txt, int loop)
disp_refresh--;
if (!disp_refresh) {
disp_refresh = Settings.display_refresh;
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
matrix[i]->setCursor(mtx_x - i *8, 0);
matrix[i]->print(txt);
@@ -144,9 +144,9 @@ void MatrixScrollUp(char* txt, int loop)
words[wordcounter++] = p;
p = strtok(nullptr, separators);
}
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->clear();
- for (uint8_t j = 0; j < wordcounter; j++) {
+ for (uint32_t j = 0; j < wordcounter; j++) {
matrix[i]->setCursor(-i *8, mtx_y + (j *8));
matrix[i]->println(words[j]);
}
@@ -169,7 +169,7 @@ void MatrixScrollUp(char* txt, int loop)
void MatrixInitMode(void)
{
- for (uint8_t i = 0; i < mtx_matrices; i++) {
+ for (uint32_t i = 0; i < mtx_matrices; i++) {
matrix[i]->setRotation(Settings.display_rotate); // 1
matrix[i]->setBrightness(Settings.display_dimmer);
matrix[i]->blinkRate(0); // 0 - 3
diff --git a/sonoff/xdsp_04_ili9341.ino b/sonoff/xdsp_04_ili9341.ino
index bf3c2729c..5bb777607 100644
--- a/sonoff/xdsp_04_ili9341.ino
+++ b/sonoff/xdsp_04_ili9341.ino
@@ -167,7 +167,7 @@ void Ili9341PrintLog(void)
tft_scroll = theight; // Start below header
tft->setCursor(0, tft_scroll);
- for (uint8_t i = 0; i < last_row; i++) {
+ for (uint32_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
// tft->fillRect(0, tft_scroll, tft->width(), theight, ILI9341_BLACK); // Erase line
tft->print(disp_screen_buffer[i]);
diff --git a/sonoff/xdsp_05_epaper_29.ino b/sonoff/xdsp_05_epaper_29.ino
index c1daf8259..f972848f3 100644
--- a/sonoff/xdsp_05_epaper_29.ino
+++ b/sonoff/xdsp_05_epaper_29.ino
@@ -209,7 +209,7 @@ void EpdPrintLog(void)
// epd_scroll = theight; // Start below header
epd_scroll = 0; // Start at top with no header
- for (uint8_t i = 0; i < last_row; i++) {
+ for (uint32_t i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
EpdDrawStringAt(0, epd_scroll, disp_screen_buffer[i], COLORED, 0);
epd_scroll += theight;
diff --git a/sonoff/xdsp_interface.ino b/sonoff/xdsp_interface.ino
index 1f7becf88..bc0890f3b 100644
--- a/sonoff/xdsp_interface.ino
+++ b/sonoff/xdsp_interface.ino
@@ -123,7 +123,7 @@ bool XdspCall(uint8_t Function)
{
bool result = false;
- for (uint8_t x = 0; x < xdsp_present; x++) {
+ for (uint32_t x = 0; x < xdsp_present; x++) {
result = xdsp_func_ptr[x](Function);
if (result && (FUNC_DISPLAY_MODEL == Function)) {
diff --git a/sonoff/xnrg_01_hlw8012.ino b/sonoff/xnrg_01_hlw8012.ino
index f120b4725..503d4e50f 100644
--- a/sonoff/xnrg_01_hlw8012.ino
+++ b/sonoff/xnrg_01_hlw8012.ino
@@ -153,11 +153,11 @@ void HlwEvery200ms(void)
// Debugging for calculating mean and median
char stemp[100];
stemp[0] = '\0';
- for (uint8_t i = 0; i < hlw_cf1_pulse_counter; i++) {
+ for (uint32_t i = 0; i < hlw_cf1_pulse_counter; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%s %d"), stemp, hlw_debug[i]);
}
- for (uint8_t i = 0; i < hlw_cf1_pulse_counter; i++) {
- for (uint8_t j = i + 1; j < hlw_cf1_pulse_counter; j++) {
+ for (uint32_t i = 0; i < hlw_cf1_pulse_counter; i++) {
+ for (uint32_t j = i + 1; j < hlw_cf1_pulse_counter; j++) {
if (hlw_debug[i] > hlw_debug[j]) { // Sort ascending
std::swap(hlw_debug[i], hlw_debug[j]);
}
diff --git a/sonoff/xnrg_02_cse7766.ino b/sonoff/xnrg_02_cse7766.ino
index 793cf08ce..c546571bb 100644
--- a/sonoff/xnrg_02_cse7766.ino
+++ b/sonoff/xnrg_02_cse7766.ino
@@ -138,7 +138,7 @@ bool CseSerialInput(void)
AddLogSerial(LOG_LEVEL_DEBUG_MORE);
uint8_t checksum = 0;
- for (uint8_t i = 2; i < 23; i++) { checksum += serial_in_buffer[i]; }
+ for (uint32_t i = 2; i < 23; i++) { checksum += serial_in_buffer[i]; }
if (checksum == serial_in_buffer[23]) {
energy_data_valid = 0;
CseReceived();
diff --git a/sonoff/xnrg_03_pzem004t.ino b/sonoff/xnrg_03_pzem004t.ino
index 8340b09dc..1e5d0723b 100644
--- a/sonoff/xnrg_03_pzem004t.ino
+++ b/sonoff/xnrg_03_pzem004t.ino
@@ -68,7 +68,7 @@ IPAddress pzem_ip(192, 168, 1, 1);
uint8_t PzemCrc(uint8_t *data)
{
uint16_t crc = 0;
- for (uint8_t i = 0; i < sizeof(PZEMCommand) -1; i++) crc += *data++;
+ for (uint32_t i = 0; i < sizeof(PZEMCommand) -1; i++) crc += *data++;
return (uint8_t)(crc & 0xFF);
}
@@ -77,7 +77,7 @@ void PzemSend(uint8_t cmd)
PZEMCommand pzem;
pzem.command = cmd;
- for (uint8_t i = 0; i < sizeof(pzem.addr); i++) pzem.addr[i] = pzem_ip[i];
+ for (uint32_t i = 0; i < sizeof(pzem.addr); i++) pzem.addr[i] = pzem_ip[i];
pzem.data = 0;
uint8_t *bytes = (uint8_t*)&pzem;
diff --git a/sonoff/xnrg_04_mcp39f501.ino b/sonoff/xnrg_04_mcp39f501.ino
index cbffbf10b..86bb81855 100644
--- a/sonoff/xnrg_04_mcp39f501.ino
+++ b/sonoff/xnrg_04_mcp39f501.ino
@@ -121,7 +121,7 @@ uint8_t McpChecksum(uint8_t *data)
uint8_t offset = 0;
uint8_t len = data[1] -1;
- for (uint8_t i = offset; i < len; i++) { checksum += data[i]; }
+ for (uint32_t i = offset; i < len; i++) { checksum += data[i]; }
return checksum;
}
@@ -130,7 +130,7 @@ unsigned long McpExtractInt(char *data, uint8_t offset, uint8_t size)
unsigned long result = 0;
unsigned long pow = 1;
- for (uint8_t i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; i++) {
result = result + (uint8_t)data[offset + i] * pow;
pow = pow * 256;
}
@@ -139,7 +139,7 @@ unsigned long McpExtractInt(char *data, uint8_t offset, uint8_t size)
void McpSetInt(unsigned long value, uint8_t *data, uint8_t offset, size_t size)
{
- for (uint8_t i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; i++) {
data[offset + i] = ((value >> (i * 8)) & 0xFF);
}
}
@@ -154,7 +154,7 @@ void McpSend(uint8_t *data)
// AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]);
- for (uint8_t i = 0; i < data[1]; i++) {
+ for (uint32_t i = 0; i < data[1]; i++) {
McpSerial->write(data[i]);
}
}
diff --git a/sonoff/xnrg_05_pzem_ac.ino b/sonoff/xnrg_05_pzem_ac.ino
index afabca17c..f23b22172 100644
--- a/sonoff/xnrg_05_pzem_ac.ino
+++ b/sonoff/xnrg_05_pzem_ac.ino
@@ -40,9 +40,9 @@ TasmotaModbus *PzemAcModbus;
uint16_t PzemCalculateCRC(uint8_t *buffer, uint8_t num)
{
uint16_t crc = 0xFFFF;
- for (uint8_t i = 0; i < num; i++) {
+ for (uint32_t i = 0; i < num; i++) {
crc ^= buffer[i];
- for (uint8_t j = 8; j; j--) {
+ for (uint32_t j = 8; j; j--) {
if ((crc & 0x0001) != 0) { // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
diff --git a/sonoff/xnrg_07_ade7953.ino b/sonoff/xnrg_07_ade7953.ino
index 54ae7a110..09566266b 100644
--- a/sonoff/xnrg_07_ade7953.ino
+++ b/sonoff/xnrg_07_ade7953.ino
@@ -90,7 +90,7 @@ uint32_t Ade7953Read(uint16_t reg)
Wire.endTransmission(0);
Wire.requestFrom(ADE7953_ADDR, size);
if (size <= Wire.available()) {
- for (int i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; i++) {
response = response << 8 | Wire.read(); // receive DATA (MSB first)
}
}
diff --git a/sonoff/xnrg_interface.ino b/sonoff/xnrg_interface.ino
index 61ff34e24..22582f6c7 100644
--- a/sonoff/xnrg_interface.ino
+++ b/sonoff/xnrg_interface.ino
@@ -96,7 +96,7 @@ int XnrgCall(uint8_t Function)
{
int result = 0;
- for (uint8_t x = 0; x < xnrg_present; x++) {
+ for (uint32_t x = 0; x < xnrg_present; x++) {
result = xnrg_func_ptr[x](Function);
if (result && ((FUNC_SERIAL == Function) ||
diff --git a/sonoff/xplg_ws2812.ino b/sonoff/xplg_ws2812.ino
index 7908289c5..ff8884462 100644
--- a/sonoff/xplg_ws2812.ino
+++ b/sonoff/xplg_ws2812.ino
@@ -98,7 +98,7 @@ void Ws2812StripShow(void)
#endif
if (Settings.light_correction) {
- for (uint16_t i = 0; i < Settings.light_pixels; i++) {
+ for (uint32_t i = 0; i < Settings.light_pixels; i++) {
c = strip->GetPixelColor(i);
c.R = ledGamma(c.R);
c.G = ledGamma(c.G);
@@ -149,7 +149,7 @@ void Ws2812UpdateHand(int position, uint8_t index)
uint8_t range = 1;
if (index < WS_MARKER) range = ((Settings.ws_width[index] -1) / 2) +1;
- for (uint8_t h = 1; h < range; h++) {
+ for (uint32_t h = 1; h < range; h++) {
float offset = (float)(range - h) / (float)range;
Ws2812UpdatePixelColor(position -h, hand_color, offset);
Ws2812UpdatePixelColor(position +h, hand_color, offset);
@@ -165,7 +165,7 @@ void Ws2812Clock(void)
Ws2812UpdateHand((RtcTime.minute * 1000) / clksize, WS_MINUTE);
Ws2812UpdateHand((((RtcTime.hour % 12) * 5000) + ((RtcTime.minute * 1000) / 12 )) / clksize, WS_HOUR);
if (Settings.ws_color[WS_MARKER][WS_RED] + Settings.ws_color[WS_MARKER][WS_GREEN] + Settings.ws_color[WS_MARKER][WS_BLUE]) {
- for (uint8_t i = 0; i < 12; i++) {
+ for (uint32_t i = 0; i < 12; i++) {
Ws2812UpdateHand((i * 5000) / clksize, WS_MARKER);
}
}
@@ -224,7 +224,7 @@ void Ws2812Gradient(uint8_t schemenr)
WsColor oldColor, currentColor;
Ws2812GradientColor(schemenr, &oldColor, range, gradRange, offset);
currentColor = oldColor;
- for (uint16_t i = 0; i < Settings.light_pixels; i++) {
+ for (uint32_t i = 0; i < Settings.light_pixels; i++) {
if (kWsRepeat[Settings.light_width] > 1) {
Ws2812GradientColor(schemenr, ¤tColor, range, gradRange, i +offset);
}
@@ -329,7 +329,7 @@ void Ws2812SetColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue, uint
strip->SetPixelColor(led -1, lcolor); // Led 1 is strip Led 0 -> substract offset 1
} else {
// strip->ClearTo(lcolor); // Set WS2812_MAX_LEDS pixels
- for (uint16_t i = 0; i < Settings.light_pixels; i++) {
+ for (uint32_t i = 0; i < Settings.light_pixels; i++) {
strip->SetPixelColor(i, lcolor);
}
}
@@ -364,7 +364,7 @@ char* Ws2812GetColor(uint16_t led, char* scolor)
sl_ledcolor[1] = lcolor.G;
sl_ledcolor[2] = lcolor.B;
scolor[0] = '\0';
- for (uint8_t i = 0; i < light_subtype; i++) {
+ for (uint32_t i = 0; i < light_subtype; i++) {
if (Settings.flag.decimal_text) {
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", sl_ledcolor[i]);
} else {
diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino
index 62b35d1ac..081954f36 100644
--- a/sonoff/xsns_01_counter.ino
+++ b/sonoff/xsns_01_counter.ino
@@ -73,7 +73,7 @@ void CounterUpdate4(void)
void CounterSaveState(void)
{
- for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
+ for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
Settings.pulse_counter[i] = RtcSettings.pulse_counter[i];
}
@@ -85,7 +85,7 @@ void CounterInit(void)
typedef void (*function) () ;
function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 };
- for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
+ for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
pinMode(pin[GPIO_CNTR1 +i], bitRead(counter_no_pullup, i) ? INPUT : INPUT_PULLUP);
attachInterrupt(pin[GPIO_CNTR1 +i], counter_callbacks[i], FALLING);
@@ -104,7 +104,7 @@ void CounterShow(bool json)
uint8_t dsxflg = 0;
uint8_t header = 0;
- for (uint8_t i = 0; i < MAX_COUNTERS; i++) {
+ for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
if (pin[GPIO_CNTR1 +i] < 99) {
char counter[33];
if (bitRead(Settings.pulse_counter_type, i)) {
diff --git a/sonoff/xsns_02_analog.ino b/sonoff/xsns_02_analog.ino
index 0fe674c3a..9a0c94029 100644
--- a/sonoff/xsns_02_analog.ino
+++ b/sonoff/xsns_02_analog.ino
@@ -78,7 +78,7 @@ uint16_t AdcRead(uint8_t factor)
// factor 5 = 32 samples
uint8_t samples = 1 << factor;
uint16_t analog = 0;
- for (uint8_t i = 0; i < samples; i++) {
+ for (uint32_t i = 0; i < samples; i++) {
analog += analogRead(A0);
delay(1);
}
diff --git a/sonoff/xsns_04_snfsc.ino b/sonoff/xsns_04_snfsc.ino
index 3ab380a3c..6d974e9f4 100644
--- a/sonoff/xsns_04_snfsc.ino
+++ b/sonoff/xsns_04_snfsc.ino
@@ -85,7 +85,7 @@ void SonoffScSerialInput(char *rcvstat)
value[i++] = atoi(str);
}
if (value[0] > 0) {
- for (uint8_t i = 0; i < 5; i++) {
+ for (uint32_t i = 0; i < 5; i++) {
sc_value[i] = value[i];
}
sc_value[2] = (11 - sc_value[2]) * 10; // Invert light level
diff --git a/sonoff/xsns_05_ds18b20.ino b/sonoff/xsns_05_ds18b20.ino
index d68664570..a0a05a44a 100644
--- a/sonoff/xsns_05_ds18b20.ino
+++ b/sonoff/xsns_05_ds18b20.ino
@@ -127,7 +127,7 @@ bool OneWireCrc8(uint8_t *addr)
while (len--) {
uint8_t inbyte = *addr++; // from 0 to 7
- for (uint8_t i = 8; i; i--) {
+ for (uint32_t i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) {
@@ -161,11 +161,11 @@ bool Ds18b20Read(void)
return;
}
*/
- for (uint8_t retry = 0; retry < 3; retry++) {
+ for (uint32_t retry = 0; retry < 3; retry++) {
OneWireReset();
OneWireWrite(W1_SKIP_ROM);
OneWireWrite(W1_READ_SCRATCHPAD);
- for (uint8_t i = 0; i < 9; i++) {
+ for (uint32_t i = 0; i < 9; i++) {
data[i] = OneWireRead();
}
if (OneWireCrc8(data)) {
diff --git a/sonoff/xsns_05_ds18x20.ino b/sonoff/xsns_05_ds18x20.ino
index cee07f1d7..ca3d667da 100644
--- a/sonoff/xsns_05_ds18x20.ino
+++ b/sonoff/xsns_05_ds18x20.ino
@@ -143,7 +143,7 @@ uint8_t OneWireRead(void)
void OneWireSelect(const uint8_t rom[8])
{
OneWireWrite(W1_MATCH_ROM);
- for (uint8_t i = 0; i < 8; i++) {
+ for (uint32_t i = 0; i < 8; i++) {
OneWireWrite(rom[i]);
}
}
@@ -153,7 +153,7 @@ void OneWireResetSearch(void)
onewire_last_discrepancy = 0;
onewire_last_device_flag = false;
onewire_last_family_discrepancy = 0;
- for (uint8_t i = 0; i < 8; i++) {
+ for (uint32_t i = 0; i < 8; i++) {
onewire_rom_id[i] = 0;
}
}
@@ -227,7 +227,7 @@ uint8_t OneWireSearch(uint8_t *newAddr)
onewire_last_family_discrepancy = 0;
search_result = false;
}
- for (uint8_t i = 0; i < 8; i++) {
+ for (uint32_t i = 0; i < 8; i++) {
newAddr[i] = onewire_rom_id[i];
}
return search_result;
@@ -240,7 +240,7 @@ bool OneWireCrc8(uint8_t *addr)
while (len--) {
uint8_t inbyte = *addr++; // from 0 to 7
- for (uint8_t i = 8; i; i--) {
+ for (uint32_t i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) {
@@ -274,14 +274,14 @@ void Ds18x20Init(void)
(ds18x20_sensor[ds18x20_sensors].address[0] == MAX31850_CHIPID))) {
ds18x20_sensor[ds18x20_sensors].index = ds18x20_sensors;
ids[ds18x20_sensors] = ds18x20_sensor[ds18x20_sensors].address[0]; // Chip id
- for (uint8_t j = 6; j > 0; j--) {
+ for (uint32_t j = 6; j > 0; j--) {
ids[ds18x20_sensors] = ids[ds18x20_sensors] << 8 | ds18x20_sensor[ds18x20_sensors].address[j];
}
ds18x20_sensors++;
}
}
- for (uint8_t i = 0; i < ds18x20_sensors; i++) {
- for (uint8_t j = i + 1; j < ds18x20_sensors; j++) {
+ for (uint32_t i = 0; i < ds18x20_sensors; i++) {
+ for (uint32_t j = i + 1; j < ds18x20_sensors; j++) {
if (ids[ds18x20_sensor[i].index] > ids[ds18x20_sensor[j].index]) { // Sort ascending
std::swap(ds18x20_sensor[i].index, ds18x20_sensor[j].index);
}
@@ -312,11 +312,11 @@ bool Ds18x20Read(uint8_t sensor)
uint8_t index = ds18x20_sensor[sensor].index;
if (ds18x20_sensor[index].valid) { ds18x20_sensor[index].valid--; }
- for (uint8_t retry = 0; retry < 3; retry++) {
+ for (uint32_t retry = 0; retry < 3; retry++) {
OneWireReset();
OneWireSelect(ds18x20_sensor[index].address);
OneWireWrite(W1_READ_SCRATCHPAD);
- for (uint8_t i = 0; i < 9; i++) {
+ for (uint32_t i = 0; i < 9; i++) {
data[i] = OneWireRead();
}
if (OneWireCrc8(data)) {
@@ -403,7 +403,7 @@ void Ds18x20EverySecond(void)
// 2mS
Ds18x20Convert(); // Start conversion, takes up to one second
} else {
- for (uint8_t i = 0; i < ds18x20_sensors; i++) {
+ for (uint32_t i = 0; i < ds18x20_sensors; i++) {
// 12mS per device
if (!Ds18x20Read(i)) { // Read temperature
Ds18x20Name(i);
@@ -421,7 +421,7 @@ void Ds18x20EverySecond(void)
void Ds18x20Show(bool json)
{
- for (uint8_t i = 0; i < ds18x20_sensors; i++) {
+ for (uint32_t i = 0; i < ds18x20_sensors; i++) {
uint8_t index = ds18x20_sensor[i].index;
if (ds18x20_sensor[index].valid) { // Check for valid temperature
@@ -435,7 +435,7 @@ void Ds18x20Show(bool json)
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, temperature);
} else {
char address[17];
- for (uint8_t j = 0; j < 6; j++) {
+ for (uint32_t j = 0; j < 6; j++) {
sprintf(address+2*j, "%02X", ds18x20_sensor[index].address[6-j]); // Skip sensor type and crc
}
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_ID "\":\"%s\",\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, address, temperature);
diff --git a/sonoff/xsns_05_ds18x20_legacy.ino b/sonoff/xsns_05_ds18x20_legacy.ino
index b31085e8b..6fe0d764c 100644
--- a/sonoff/xsns_05_ds18x20_legacy.ino
+++ b/sonoff/xsns_05_ds18x20_legacy.ino
@@ -65,11 +65,11 @@ void Ds18x20Search(void)
num_sensors++;
}
}
- for (uint8_t i = 0; i < num_sensors; i++) {
+ for (uint32_t i = 0; i < num_sensors; i++) {
ds18x20_index[i] = i;
}
- for (uint8_t i = 0; i < num_sensors; i++) {
- for (uint8_t j = i + 1; j < num_sensors; j++) {
+ for (uint32_t i = 0; i < num_sensors; i++) {
+ for (uint32_t j = i + 1; j < num_sensors; j++) {
if (uint32_t(ds18x20_address[ds18x20_index[i]]) > uint32_t(ds18x20_address[ds18x20_index[j]])) {
std::swap(ds18x20_index[i], ds18x20_index[j]);
}
@@ -87,7 +87,7 @@ String Ds18x20Addresses(uint8_t sensor)
{
char address[20];
- for (uint8_t i = 0; i < 8; i++) {
+ for (uint32_t i = 0; i < 8; i++) {
sprintf(address+2*i, "%02X", ds18x20_address[ds18x20_index[sensor]][i]);
}
return String(address);
@@ -116,7 +116,7 @@ bool Ds18x20Read(uint8_t sensor, float &t)
ds->select(ds18x20_address[ds18x20_index[sensor]]);
ds->write(W1_READ_SCRATCHPAD); // Read Scratchpad
- for (uint8_t i = 0; i < 9; i++) {
+ for (uint32_t i = 0; i < 9; i++) {
data[i] = ds->read();
}
if (OneWire::crc8(data, 8) == data[8]) {
@@ -170,7 +170,7 @@ void Ds18x20Show(bool json)
float t;
uint8_t dsxflg = 0;
- for (uint8_t i = 0; i < Ds18x20Sensors(); i++) {
+ for (uint32_t i = 0; i < Ds18x20Sensors(); i++) {
if (Ds18x20Read(i, t)) { // Check if read failed
Ds18x20Type(i);
char temperature[33];
diff --git a/sonoff/xsns_06_dht.ino b/sonoff/xsns_06_dht.ino
index 7615dbc6c..06b2dddff 100644
--- a/sonoff/xsns_06_dht.ino
+++ b/sonoff/xsns_06_dht.ino
@@ -47,7 +47,7 @@ struct DHTSTRUCT {
void DhtReadPrep(void)
{
- for (uint8_t i = 0; i < dht_sensors; i++) {
+ for (uint32_t i = 0; i < dht_sensors; i++) {
digitalWrite(Dht[i].pin, HIGH);
}
}
@@ -102,7 +102,7 @@ bool DhtRead(uint8_t sensor)
error = 1;
}
else {
- for (int i = 0; i < 80; i += 2) {
+ for (uint32_t i = 0; i < 80; i += 2) {
cycles[i] = DhtExpectPulse(sensor, LOW);
cycles[i+1] = DhtExpectPulse(sensor, HIGH);
}
@@ -110,7 +110,7 @@ bool DhtRead(uint8_t sensor)
interrupts();
if (error) { return false; }
- for (int i = 0; i < 40; ++i) {
+ for (uint32_t i = 0; i < 40; ++i) {
int32_t lowCycles = cycles[2*i];
int32_t highCycles = cycles[2*i+1];
if ((-1 == lowCycles) || (-1 == highCycles)) {
@@ -181,7 +181,7 @@ void DhtInit(void)
{
dht_max_cycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor.
- for (uint8_t i = 0; i < dht_sensors; i++) {
+ for (uint32_t i = 0; i < dht_sensors; i++) {
pinMode(Dht[i].pin, INPUT_PULLUP);
Dht[i].lastreadtime = 0;
Dht[i].lastresult = 0;
@@ -198,7 +198,7 @@ void DhtEverySecond(void)
// <1mS
DhtReadPrep();
} else {
- for (uint8_t i = 0; i < dht_sensors; i++) {
+ for (uint32_t i = 0; i < dht_sensors; i++) {
// DHT11 and AM2301 25mS per sensor, SI7021 5mS per sensor
DhtReadTempHum(i);
}
@@ -207,7 +207,7 @@ void DhtEverySecond(void)
void DhtShow(bool json)
{
- for (uint8_t i = 0; i < dht_sensors; i++) {
+ for (uint32_t i = 0; i < dht_sensors; i++) {
char temperature[33];
dtostrfd(Dht[i].t, Settings.flag2.temperature_resolution, temperature);
char humidity[33];
diff --git a/sonoff/xsns_07_sht1x.ino b/sonoff/xsns_07_sht1x.ino
index d636281a8..e3cffc6a3 100644
--- a/sonoff/xsns_07_sht1x.ino
+++ b/sonoff/xsns_07_sht1x.ino
@@ -49,7 +49,7 @@ bool ShtReset(void)
pinMode(sht_sda_pin, INPUT_PULLUP);
pinMode(sht_scl_pin, OUTPUT);
delay(11);
- for (uint8_t i = 0; i < 9; i++) {
+ for (uint32_t i = 0; i < 9; i++) {
digitalWrite(sht_scl_pin, HIGH);
digitalWrite(sht_scl_pin, LOW);
}
@@ -93,7 +93,7 @@ bool ShtSendCommand(const uint8_t cmd)
bool ShtAwaitResult(void)
{
// Maximum 320ms for 14 bit measurement
- for (uint8_t i = 0; i < 16; i++) {
+ for (uint32_t i = 0; i < 16; i++) {
if (LOW == digitalRead(sht_sda_pin)) {
return true;
}
diff --git a/sonoff/xsns_08_htu21.ino b/sonoff/xsns_08_htu21.ino
index 47d754df8..96246e349 100644
--- a/sonoff/xsns_08_htu21.ino
+++ b/sonoff/xsns_08_htu21.ino
@@ -69,7 +69,7 @@ char htu_types[7];
uint8_t HtuCheckCrc8(uint16_t data)
{
- for (uint8_t bit = 0; bit < 16; bit++) {
+ for (uint32_t bit = 0; bit < 16; bit++) {
if (data & 0x8000) {
data = (data << 1) ^ HTU21_CRC8_POLYNOM;
} else {
diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino
index 12252e3b6..8680d6dea 100755
--- a/sonoff/xsns_09_bmp.ino
+++ b/sonoff/xsns_09_bmp.ino
@@ -455,7 +455,7 @@ void BmpDetect(void)
if (!bmp_sensors) { return; }
memset(bmp_sensors, 0, bmp_sensor_size); // Init defaults to 0
- for (uint8_t i = 0; i < BMP_MAX_SENSORS; i++) {
+ for (uint32_t i = 0; i < BMP_MAX_SENSORS; i++) {
uint8_t bmp_type = I2cRead8(bmp_addresses[i], BMP_REGISTER_CHIPID);
if (bmp_type) {
bmp_sensors[bmp_count].bmp_address = bmp_addresses[i];
@@ -493,7 +493,7 @@ void BmpRead(void)
{
if (!bmp_sensors) { return; }
- for (uint8_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
+ for (uint32_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
switch (bmp_sensors[bmp_idx].bmp_type) {
case BMP180_CHIPID:
Bmp180Read(bmp_idx);
@@ -529,7 +529,7 @@ void BmpShow(bool json)
{
if (!bmp_sensors) { return; }
- for (uint8_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
+ for (uint32_t bmp_idx = 0; bmp_idx < bmp_count; bmp_idx++) {
if (bmp_sensors[bmp_idx].bmp_type) {
float bmp_sealevel = 0.0;
if (bmp_sensors[bmp_idx].bmp_pressure != 0.0) {
diff --git a/sonoff/xsns_10_bh1750.ino b/sonoff/xsns_10_bh1750.ino
index 93cf57e7c..d9af1b572 100644
--- a/sonoff/xsns_10_bh1750.ino
+++ b/sonoff/xsns_10_bh1750.ino
@@ -59,7 +59,7 @@ void Bh1750Detect(void)
return;
}
- for (uint8_t i = 0; i < sizeof(bh1750_addresses); i++) {
+ for (uint32_t i = 0; i < sizeof(bh1750_addresses); i++) {
bh1750_address = bh1750_addresses[i];
Wire.beginTransmission(bh1750_address);
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
diff --git a/sonoff/xsns_11_veml6070.ino b/sonoff/xsns_11_veml6070.ino
index fcb118c6d..42beba939 100644
--- a/sonoff/xsns_11_veml6070.ino
+++ b/sonoff/xsns_11_veml6070.ino
@@ -149,7 +149,7 @@ void Veml6070Detect(void)
void Veml6070UvTableInit(void)
{
// fill the uv-risk compare table once, based on the coefficient calculation
- for (uint8_t i = 0; i < VEML6070_UV_MAX_INDEX; i++) {
+ for (uint32_t i = 0; i < VEML6070_UV_MAX_INDEX; i++) {
#ifdef USE_VEML6070_RSET
if ( (USE_VEML6070_RSET >= 220000) && (USE_VEML6070_RSET <= 1000000) ) {
uv_risk_map[i] = ( (USE_VEML6070_RSET / VEML6070_TABLE_COEFFCIENT) / VEML6070_UV_MAX_DEFAULT ) * (i+1);
diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino
index e5a9cf323..270f4911a 100644
--- a/sonoff/xsns_12_ads1115.ino
+++ b/sonoff/xsns_12_ads1115.ino
@@ -161,7 +161,7 @@ int16_t Ads1115GetConversion(uint8_t channel)
void Ads1115Detect(void)
{
uint16_t buffer;
- for (uint8_t i = 0; i < sizeof(ads1115_addresses); i++) {
+ for (uint32_t i = 0; i < sizeof(ads1115_addresses); i++) {
if (!ads1115_found[i]) {
ads1115_address = ads1115_addresses[i];
if (I2cValidRead16(&buffer, ads1115_address, ADS1115_REG_POINTER_CONVERT) &&
@@ -179,7 +179,7 @@ void Ads1115GetValues(uint8_t address)
{
uint8_t old_address = ads1115_address;
ads1115_address = address;
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
ads1115_values[i] = Ads1115GetConversion(i);
//AddLog_P2(LOG_LEVEL_INFO, "Logging ADS1115 %02x (%i) = %i", address, i, ads1115_values[i] );
}
@@ -190,7 +190,7 @@ void Ads1115toJSON(char *comma_j)
{
ResponseAppend_P(PSTR("%s{"), comma_j);
char *comma = (char*)"";
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
ResponseAppend_P(PSTR("%s\"A%d\":%d"), comma, i, ads1115_values[i]);
comma = (char*)",";
}
@@ -202,7 +202,7 @@ void Ads1115toString(uint8_t address)
char label[15];
snprintf_P(label, sizeof(label), "ADS1115(%02x)", address);
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
WSContentSend_PD(HTTP_SNS_ANALOG, label, i, ads1115_values[i]);
}
}
@@ -217,7 +217,7 @@ void Ads1115Show(bool json)
char *comma = (char*)"";
- for (uint8_t t = 0; t < sizeof(ads1115_addresses); t++) {
+ for (uint32_t t = 0; t < sizeof(ads1115_addresses); t++) {
//AddLog_P2(LOG_LEVEL_INFO, "Logging ADS1115 %02x", ads1115_addresses[t]);
if (ads1115_found[t]) {
Ads1115GetValues(ads1115_addresses[t]);
diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino
index e08833346..9bfdd0ffe 100644
--- a/sonoff/xsns_12_ads1115_i2cdev.ino
+++ b/sonoff/xsns_12_ads1115_i2cdev.ino
@@ -81,7 +81,7 @@ void Ads1115Detect(void)
return;
}
- for (uint8_t i = 0; i < sizeof(ads1115_addresses); i++) {
+ for (uint32_t i = 0; i < sizeof(ads1115_addresses); i++) {
ads1115_address = ads1115_addresses[i];
ADS1115 adc0(ads1115_address);
if (adc0.testConnection()) {
@@ -101,7 +101,7 @@ void Ads1115Show(bool json)
if (ads1115_type) {
uint8_t dsxflg = 0;
- for (uint8_t i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
int16_t adc_value = Ads1115GetConversion(i);
if (json) {
diff --git a/sonoff/xsns_13_ina219.ino b/sonoff/xsns_13_ina219.ino
index 0dd7e5398..57e4a03a7 100644
--- a/sonoff/xsns_13_ina219.ino
+++ b/sonoff/xsns_13_ina219.ino
@@ -194,7 +194,7 @@ void Ina219Detect(void)
{
if (ina219_type) { return; }
- for (uint8_t i = 0; i < sizeof(ina219_addresses); i++) {
+ for (uint32_t i = 0; i < sizeof(ina219_addresses); i++) {
ina219_address = ina219_addresses[i];
if (Ina219SetCalibration(Settings.ina219_mode)) {
ina219_type = 1;
diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino
index 17ac313ee..36f39fe7b 100755
--- a/sonoff/xsns_14_sht3x.ino
+++ b/sonoff/xsns_14_sht3x.ino
@@ -66,7 +66,7 @@ bool Sht3xRead(float &t, float &h, uint8_t sht3x_address)
}
delay(30); // Timing verified with logic analyzer (10 is to short)
Wire.requestFrom(sht3x_address, (uint8_t)6); // Request 6 bytes of data
- for (int i = 0; i < 6; i++) {
+ for (uint32_t i = 0; i < 6; i++) {
data[i] = Wire.read(); // cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc
};
t = ConvertTemp((float)((((data[0] << 8) | data[1]) * 175) / 65535.0) - 45);
@@ -82,7 +82,7 @@ void Sht3xDetect(void)
float t;
float h;
- for (uint8_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
+ for (uint32_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
if (Sht3xRead(t, h, sht3x_addresses[i])) {
sht3x_sensors[sht3x_count].address = sht3x_addresses[i];
GetTextIndexed(sht3x_sensors[sht3x_count].types, sizeof(sht3x_sensors[sht3x_count].types), i, kShtTypes);
@@ -98,7 +98,7 @@ void Sht3xShow(bool json)
float t;
float h;
char types[11];
- for (uint8_t i = 0; i < sht3x_count; i++) {
+ for (uint32_t i = 0; i < sht3x_count; i++) {
if (Sht3xRead(t, h, sht3x_sensors[i].address)) {
char temperature[33];
dtostrfd(t, Settings.flag2.temperature_resolution, temperature);
diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino
index 5978ba058..007b58513 100644
--- a/sonoff/xsns_15_mhz19.ino
+++ b/sonoff/xsns_15_mhz19.ino
@@ -102,7 +102,7 @@ uint8_t mhz_state = 0;
uint8_t MhzCalculateChecksum(uint8_t *array)
{
uint8_t checksum = 0;
- for (uint8_t i = 1; i < 8; i++) {
+ for (uint32_t i = 1; i < 8; i++) {
checksum += array[i];
}
checksum = 255 - checksum;
diff --git a/sonoff/xsns_18_pms5003.ino b/sonoff/xsns_18_pms5003.ino
index e77eb0271..ee14f9348 100644
--- a/sonoff/xsns_18_pms5003.ino
+++ b/sonoff/xsns_18_pms5003.ino
@@ -65,12 +65,12 @@ bool PmsReadData(void)
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 32);
// get checksum ready
- for (uint8_t i = 0; i < 30; i++) {
+ for (uint32_t i = 0; i < 30; i++) {
sum += buffer[i];
}
// The data comes in endian'd, this solves it so it works on all platforms
uint16_t buffer_u16[15];
- for (uint8_t i = 0; i < 15; i++) {
+ for (uint32_t i = 0; i < 15; i++) {
buffer_u16[i] = buffer[2 + i*2 + 1];
buffer_u16[i] += (buffer[2 + i*2] << 8);
}
diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino
index e9d955af3..74571973a 100644
--- a/sonoff/xsns_20_novasds.ino
+++ b/sonoff/xsns_20_novasds.ino
@@ -77,7 +77,7 @@ bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensor
uint8_t novasds_cmnd[19] = {0xAA, 0xB4, byte1, byte2, byte3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (uint8_t)(sensorid & 0xFF), (uint8_t)((sensorid>>8) & 0xFF), 0x00, 0xAB};
// calc crc
- for (uint8_t i = 2; i < 17; i++) {
+ for (uint32_t i = 2; i < 17; i++) {
novasds_cmnd[17] += novasds_cmnd[i];
}
//~ AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SDS: Send %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X"),
diff --git a/sonoff/xsns_23_sdm120.ino b/sonoff/xsns_23_sdm120.ino
index 7c8e064de..6684f6a15 100644
--- a/sonoff/xsns_23_sdm120.ino
+++ b/sonoff/xsns_23_sdm120.ino
@@ -128,9 +128,9 @@ uint16_t SDM120_calculateCRC(uint8_t *frame, uint8_t num)
{
uint16_t crc, flag;
crc = 0xFFFF;
- for (uint8_t i = 0; i < num; i++) {
+ for (uint32_t i = 0; i < num; i++) {
crc ^= frame[i];
- for (uint8_t j = 8; j; j--) {
+ for (uint32_t j = 8; j; j--) {
if ((crc & 0x0001) != 0) { // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
diff --git a/sonoff/xsns_25_sdm630.ino b/sonoff/xsns_25_sdm630.ino
index c71009ce4..f1d2d16e6 100644
--- a/sonoff/xsns_25_sdm630.ino
+++ b/sonoff/xsns_25_sdm630.ino
@@ -105,9 +105,9 @@ uint16_t SDM630_calculateCRC(uint8_t *frame, uint8_t num)
{
uint16_t crc, flag;
crc = 0xFFFF;
- for (uint8_t i = 0; i < num; i++) {
+ for (uint32_t i = 0; i < num; i++) {
crc ^= frame[i];
- for (uint8_t j = 8; j; j--) {
+ for (uint32_t j = 8; j; j--) {
if ((crc & 0x0001) != 0) { // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
diff --git a/sonoff/xsns_26_lm75ad.ino b/sonoff/xsns_26_lm75ad.ino
index 88769b3aa..8a6e2c09c 100644
--- a/sonoff/xsns_26_lm75ad.ino
+++ b/sonoff/xsns_26_lm75ad.ino
@@ -53,7 +53,7 @@ void LM75ADDetect(void)
if (lm75ad_type) { return; }
uint16_t buffer;
- for (uint8_t i = 0; i < sizeof(lm75ad_addresses); i++) {
+ for (uint32_t i = 0; i < sizeof(lm75ad_addresses); i++) {
lm75ad_address = lm75ad_addresses[i];
if (I2cValidRead16(&buffer, lm75ad_address, LM75_THYST_REGISTER)) {
if (buffer == 0x4B00) {
diff --git a/sonoff/xsns_28_tm1638.ino b/sonoff/xsns_28_tm1638.ino
index 05e756966..f9f95b73d 100644
--- a/sonoff/xsns_28_tm1638.ino
+++ b/sonoff/xsns_28_tm1638.ino
@@ -48,7 +48,7 @@ uint8_t tm1638_state = 0;
void Tm16XXSend(uint8_t data)
{
- for (uint8_t i = 0; i < 8; i++) {
+ for (uint32_t i = 0; i < 8; i++) {
digitalWrite(tm1638_data_pin, !!(data & (1 << i)));
digitalWrite(tm1638_clock_pin, LOW);
delayMicroseconds(TM1638_CLOCK_DELAY);
@@ -80,7 +80,7 @@ uint8_t Tm16XXReceive(void)
pinMode(tm1638_data_pin, INPUT);
digitalWrite(tm1638_data_pin, HIGH);
- for (uint8_t i = 0; i < 8; ++i) {
+ for (uint32_t i = 0; i < 8; ++i) {
digitalWrite(tm1638_clock_pin, LOW);
delayMicroseconds(TM1638_CLOCK_DELAY);
temp |= digitalRead(tm1638_data_pin) << i;
@@ -98,7 +98,7 @@ uint8_t Tm16XXReceive(void)
void Tm16XXClearDisplay(void)
{
- for (int i = 0; i < tm1638_displays; i++) {
+ for (uint32_t i = 0; i < tm1638_displays; i++) {
TM16XXSendData(i << 1, 0);
}
}
@@ -110,7 +110,7 @@ void Tm1638SetLED(uint8_t color, uint8_t pos)
void Tm1638SetLEDs(word leds)
{
- for (int i = 0; i < tm1638_displays; i++) {
+ for (uint32_t i = 0; i < tm1638_displays; i++) {
uint8_t color = 0;
if ((leds & (1 << i)) != 0) {
@@ -131,7 +131,7 @@ uint8_t Tm1638GetButtons(void)
digitalWrite(tm1638_strobe_pin, LOW);
Tm16XXSend(0x42);
- for (int i = 0; i < 4; i++) {
+ for (uint32_t i = 0; i < 4; i++) {
keys |= Tm16XXReceive() << i;
}
digitalWrite(tm1638_strobe_pin, HIGH);
@@ -161,7 +161,7 @@ void TmInit(void)
digitalWrite(tm1638_strobe_pin, LOW);
Tm16XXSend(0xC0);
- for (int i = 0; i < 16; i++) {
+ for (uint32_t i = 0; i < 16; i++) {
Tm16XXSend(0x00);
}
digitalWrite(tm1638_strobe_pin, HIGH);
@@ -175,7 +175,7 @@ void TmLoop(void)
{
if (tm1638_state) {
uint8_t buttons = Tm1638GetButtons();
- for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
+ for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
SwitchSetVirtual(i, (buttons &1) ^1);
uint8_t color = (SwitchGetVirtual(i)) ? TM1638_COLOR_NONE : TM1638_COLOR_RED;
Tm1638SetLED(color, i);
diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino
index c853862b6..6d4384edb 100644
--- a/sonoff/xsns_29_mcp230xx.ino
+++ b/sonoff/xsns_29_mcp230xx.ino
@@ -68,7 +68,7 @@ const char MCP230XX_CMND_RESPONSE[] PROGMEM = "{\"S29cmnd_D%i\":{\"COMMAND\":\"%
void MCP230xx_CheckForIntCounter(void) {
uint8_t en = 0;
- for (uint8_t ca=0;ca<16;ca++) {
+ for (uint32_t ca=0;ca<16;ca++) {
if (Settings.mcp230xx_config[ca].int_count_en) {
en=1;
}
@@ -76,7 +76,7 @@ void MCP230xx_CheckForIntCounter(void) {
if (!Settings.mcp230xx_int_timer) en=0;
mcp230xx_int_counter_en=en;
if (!mcp230xx_int_counter_en) { // Interrupt counters are disabled, so we clear all the counters
- for (uint8_t ca=0;ca<16;ca++) {
+ for (uint32_t ca=0;ca<16;ca++) {
mcp230xx_int_counter[ca] = 0;
}
}
@@ -84,14 +84,14 @@ void MCP230xx_CheckForIntCounter(void) {
void MCP230xx_CheckForIntRetainer(void) {
uint8_t en = 0;
- for (uint8_t ca=0;ca<16;ca++) {
+ for (uint32_t ca=0;ca<16;ca++) {
if (Settings.mcp230xx_config[ca].int_retain_flag) {
en=1;
}
}
mcp230xx_int_retainer_en=en;
if (!mcp230xx_int_retainer_en) { // Interrupt counters are disabled, so we clear all the counters
- for (uint8_t ca=0;ca<16;ca++) {
+ for (uint32_t ca=0;ca<16;ca++) {
mcp230xx_int_retainer[ca] = 0;
}
}
@@ -141,14 +141,14 @@ uint8_t MCP230xx_readGPIO(uint8_t port) {
void MCP230xx_ApplySettings(void) {
uint8_t int_en = 0;
- for (uint8_t mcp230xx_port=0;mcp230xx_port 0) {
if (I2cValidRead8(&mcp230xx_intcap, USE_MCP230xx_ADDR, MCP230xx_INTCAP+mcp230xx_port)) {
- for (uint8_t intp = 0; intp < 8; intp++) {
+ for (uint32_t intp = 0; intp < 8; intp++) {
if ((intf >> intp) & 0x01) { // we know which pin caused interrupt
report_int = 0;
if (Settings.mcp230xx_config[intp+(mcp230xx_port*8)].pinmode > 1) {
@@ -394,7 +394,7 @@ void MCP230xx_SetOutPin(uint8_t pin,uint8_t pinstate) {
void MCP230xx_Reset(uint8_t pinmode) {
uint8_t pullup = 0;
if ((pinmode > 1) && (pinmode < 5)) { pullup=1; }
- for (uint8_t pinx=0;pinx<16;pinx++) {
+ for (uint32_t pinx=0;pinx<16;pinx++) {
Settings.mcp230xx_config[pinx].pinmode=pinmode;
Settings.mcp230xx_config[pinx].pullup=pullup;
Settings.mcp230xx_config[pinx].saved_state=0;
@@ -433,7 +433,7 @@ bool MCP230xx_Command(void) {
return serviced;
}
char sub_string[XdrvMailbox.data_len];
- for (uint8_t ca=0;ca= 5) {
char stt[7];
sprintf(stt,ConvertNumTxt((gpio>>pin)&1,Settings.mcp230xx_config[pin].pinmode));
@@ -724,13 +724,13 @@ void MCP230xx_OutputTelemetry(void) {
gpioa=MCP230xx_readGPIO(0);
if (2 == mcp230xx_type) { gpiob=MCP230xx_readGPIO(1); }
gpiototal=((uint16_t)gpiob << 8) | gpioa;
- for (uint8_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
+ for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
if (Settings.mcp230xx_config[pinx].pinmode >= 5) outputcount++;
}
if (outputcount) {
char stt[7];
Response_P(PSTR("{\"" D_JSON_TIME "\":\"%s\",\"MCP230_OUT\": {"), GetDateAndTime(DT_LOCAL).c_str());
- for (uint8_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
+ for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
if (Settings.mcp230xx_config[pinx].pinmode >= 5) {
sprintf(stt,ConvertNumTxt(((gpiototal>>pinx)&1),Settings.mcp230xx_config[pinx].pinmode));
ResponseAppend_P(PSTR("\"OUT_D%i\":\"%s\","),pinx,stt);
@@ -745,7 +745,7 @@ void MCP230xx_OutputTelemetry(void) {
void MCP230xx_Interrupt_Counter_Report(void) {
Response_P(PSTR("{\"" D_JSON_TIME "\":\"%s\",\"MCP230_INTTIMER\": {"), GetDateAndTime(DT_LOCAL).c_str());
- for (uint8_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
+ for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
if (Settings.mcp230xx_config[pinx].int_count_en) { // Counting is enabled for this pin so we add to report
ResponseAppend_P(PSTR("\"INTCNT_D%i\":%i,"),pinx,mcp230xx_int_counter[pinx]);
mcp230xx_int_counter[pinx]=0;
@@ -759,7 +759,7 @@ void MCP230xx_Interrupt_Counter_Report(void) {
void MCP230xx_Interrupt_Retain_Report(void) {
uint16_t retainresult = 0;
Response_P(PSTR("{\"" D_JSON_TIME "\":\"%s\",\"MCP_INTRETAIN\": {"), GetDateAndTime(DT_LOCAL).c_str());
- for (uint8_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
+ for (uint32_t pinx = 0;pinx < mcp230xx_pincount;pinx++) {
if (Settings.mcp230xx_config[pinx].int_retain_flag) {
ResponseAppend_P(PSTR("\"D%i\":%i,"),pinx,mcp230xx_int_retainer[pinx]);
retainresult |= (((mcp230xx_int_retainer[pinx])&1) << pinx);
diff --git a/sonoff/xsns_30_mpr121.ino b/sonoff/xsns_30_mpr121.ino
index fec6cf10d..22fcc381d 100644
--- a/sonoff/xsns_30_mpr121.ino
+++ b/sonoff/xsns_30_mpr121.ino
@@ -212,7 +212,7 @@ void Mpr121Init(struct mpr121 *pS)
{
// Loop through I2C addresses
- for (uint8_t i = 0; i < sizeof(pS->i2c_addr[i]); i++) {
+ for (uint32_t i = 0; i < sizeof(pS->i2c_addr[i]); i++) {
// Soft reset sensor and check if connected at I2C address
pS->connected[i] = (I2cWrite8(pS->i2c_addr[i], MPR121_SRST_REG, MPR121_SRST_VAL)
@@ -223,7 +223,7 @@ void Mpr121Init(struct mpr121 *pS)
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_I2C "MPR121(%c) " D_FOUND_AT " 0x%X"), pS->id[i], pS->i2c_addr[i]);
// Set thresholds for registers 0x41 - 0x5A (ExTTH and ExRTH)
- for (uint8_t j = 0; j < 13; j++) {
+ for (uint32_t j = 0; j < 13; j++) {
// Touch
I2cWrite8(pS->i2c_addr[i], MPR121_E0TTH_REG + 2 * j, MPR121_E0TTH_VAL);
@@ -317,7 +317,7 @@ void Mpr121Show(struct mpr121 *pS, uint8_t function)
{
// Loop through sensors
- for (uint8_t i = 0; i < sizeof(pS->i2c_addr[i]); i++) {
+ for (uint32_t i = 0; i < sizeof(pS->i2c_addr[i]); i++) {
// Check if sensor is connected
if (pS->connected[i]) {
@@ -346,7 +346,7 @@ void Mpr121Show(struct mpr121 *pS, uint8_t function)
ResponseAppend_P(PSTR(",\"MPR121%c\":{"), pS->id[i]);
}
// Loop through buttons
- for (uint8_t j = 0; j < 13; j++) {
+ for (uint32_t j = 0; j < 13; j++) {
// Add sensor, button and state to MQTT JSON message string
if ((FUNC_EVERY_50_MSECOND == function)
diff --git a/sonoff/xsns_32_mpu6050.ino b/sonoff/xsns_32_mpu6050.ino
index 6ac8763bd..58915efc9 100644
--- a/sonoff/xsns_32_mpu6050.ino
+++ b/sonoff/xsns_32_mpu6050.ino
@@ -120,7 +120,7 @@ void MPU_6050Detect(void)
return;
}
- for (uint8_t i = 0; i < sizeof(MPU_6050_addresses); i++)
+ for (uint32_t i = 0; i < sizeof(MPU_6050_addresses); i++)
{
if(!I2cDevice(MPU_6050_addresses[i]))
{
diff --git a/sonoff/xsns_34_hx711.ino b/sonoff/xsns_34_hx711.ino
index 7d4cd8858..47a38f7d3 100644
--- a/sonoff/xsns_34_hx711.ino
+++ b/sonoff/xsns_34_hx711.ino
@@ -164,7 +164,7 @@ bool HxCommand(void)
bool show_parms = false;
char sub_string[XdrvMailbox.data_len +1];
- for (uint8_t ca = 0; ca < XdrvMailbox.data_len; ca++) {
+ for (uint32_t ca = 0; ca < XdrvMailbox.data_len; ca++) {
if ((' ' == XdrvMailbox.data[ca]) || ('=' == XdrvMailbox.data[ca])) { XdrvMailbox.data[ca] = ','; }
}
diff --git a/sonoff/xsns_35_tx20.ino b/sonoff/xsns_35_tx20.ino
index 05d3cbd8b..ee3fca596 100644
--- a/sonoff/xsns_35_tx20.ino
+++ b/sonoff/xsns_35_tx20.ino
@@ -109,7 +109,7 @@ void Tx20StartRead(void)
delayMicroseconds(TX20_BIT_TIME / 2);
- for (int bitcount = 41; bitcount > 0; bitcount--) {
+ for (int32_t bitcount = 41; bitcount > 0; bitcount--) {
uint8_t dpin = (digitalRead(pin[GPIO_TX20_TXD_BLACK]));
if (bitcount > 41 - 5) {
// start, inverted
diff --git a/sonoff/xsns_37_rfsensor.ino b/sonoff/xsns_37_rfsensor.ino
index e4c8a0087..b5d3d6956 100644
--- a/sonoff/xsns_37_rfsensor.ino
+++ b/sonoff/xsns_37_rfsensor.ino
@@ -259,7 +259,7 @@ void RfSnsTheoV2Show(bool json)
{
bool sensor_once = false;
- for (uint8_t i = 0; i < RFSNS_THEOV2_MAX_CHANNEL; i++) {
+ for (uint32_t i = 0; i < RFSNS_THEOV2_MAX_CHANNEL; i++) {
if (rfsns_theo_v2_t1[i].time) {
char sensor[10];
snprintf_P(sensor, sizeof(sensor), PSTR("TV2T1C%d"), i +1);
@@ -296,7 +296,7 @@ void RfSnsTheoV2Show(bool json)
}
sensor_once = false;
- for (uint8_t i = 0; i < RFSNS_THEOV2_MAX_CHANNEL; i++) {
+ for (uint32_t i = 0; i < RFSNS_THEOV2_MAX_CHANNEL; i++) {
if (rfsns_theo_v2_t2[i].time) {
char sensor[10];
snprintf_P(sensor, sizeof(sensor), PSTR("TV2T2C%d"), i +1);
@@ -453,7 +453,7 @@ void RfSnsAnalyzeAlectov2()
if (rfsns_raw_signal->Number > RFSNS_ACH2010_MAX_PULSECOUNT) { maxidx = 9; }
// Get message back to front as the header is almost never received complete for ACH2010
uint8_t idx = maxidx;
- for (uint8_t x = rfsns_raw_signal->Number; x > 0; x = x-2) {
+ for (uint32_t x = rfsns_raw_signal->Number; x > 0; x = x-2) {
if (rfsns_raw_signal->Pulses[x-1] * rfsns_raw_signal->Multiply < 0x300) {
rfbit = 0x80;
} else {
@@ -528,7 +528,7 @@ uint8_t RfSnsAlectoCRC8(uint8_t *addr, uint8_t len)
uint8_t crc = 0;
while (len--) {
uint8_t inbyte = *addr++;
- for (uint8_t i = 8; i; i--) {
+ for (uint32_t i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x80;
crc <<= 1;
if (mix) { crc ^= 0x31; }
diff --git a/sonoff/xsns_39_max31855.ino b/sonoff/xsns_39_max31855.ino
index fc43ecac1..4f04c62db 100644
--- a/sonoff/xsns_39_max31855.ino
+++ b/sonoff/xsns_39_max31855.ino
@@ -102,7 +102,7 @@ int32_t MAX31855_ShiftIn(uint8_t Length){
digitalWrite(pin[GPIO_MAX31855CS], LOW); // CS = LOW -> Start SPI communication
delayMicroseconds(1); // CS fall to output enable = max. 100ns
- for(uint8_t i = 0; i < Length; i++)
+ for (uint32_t i = 0; i < Length; i++)
{
digitalWrite(pin[GPIO_MAX31855CLK], LOW);
delayMicroseconds(1); // CLK pulse width low = min. 100ns / CLK fall to output valid = max. 40ns
diff --git a/sonoff/xsns_40_pn532.ino b/sonoff/xsns_40_pn532.ino
index 491996327..210607fa8 100644
--- a/sonoff/xsns_40_pn532.ino
+++ b/sonoff/xsns_40_pn532.ino
@@ -142,12 +142,12 @@ int8_t PN532_writeCommand(const uint8_t *header, uint8_t hlen, const uint8_t *bo
uint8_t sum = PN532_HOSTTOPN532; // sum of TFI + DATA
PN532_Serial->write(header, hlen);
- for (uint8_t i = 0; i < hlen; i++) {
+ for (uint32_t i = 0; i < hlen; i++) {
sum += header[i];
}
PN532_Serial->write(body, blen);
- for (uint8_t i = 0; i < blen; i++) {
+ for (uint32_t i = 0; i < blen; i++) {
sum += body[i];
}
@@ -198,7 +198,7 @@ int16_t PN532_readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 50)
}
uint8_t sum = PN532_PN532TOHOST + cmd;
- for (uint8_t i=0; i 0; --bit) {
+ for (uint32_t bit = 8; bit > 0; --bit) {
if(crc & 0x80) {
crc = (crc << 1) ^ 0x31u;
} else {
@@ -172,8 +172,8 @@ void SPS30_Every_Second() {
ByteToFloat conv;
- for (uint8_t count=0; count<10; count++) {
- for (uint8_t i = 0; i < 4; i++){
+ for (uint32_t count=0; count<10; count++) {
+ for (uint32_t i = 0; i < 4; i++){
conv.array[3-i] = vars[count*sizeof(float)+i];
}
*fp++=conv.value;
diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino
index fdb947bfb..0c394eaa6 100644
--- a/sonoff/xsns_interface.ino
+++ b/sonoff/xsns_interface.ino
@@ -290,7 +290,7 @@ bool XsnsCall(uint8_t Function)
uint32_t profile_start_millis = millis();
#endif // PROFILE_XSNS_EVERY_SECOND
- for (uint8_t x = 0; x < xsns_present; x++) {
+ for (uint32_t x = 0; x < xsns_present; x++) {
#ifdef USE_DEBUG_DRIVER
if (XsnsEnabled(x)) {
#endif
diff --git a/sonoff/zzzz_debug.ino b/sonoff/zzzz_debug.ino
index d7b4c4c75..7b2e7e6ad 100644
--- a/sonoff/zzzz_debug.ino
+++ b/sonoff/zzzz_debug.ino
@@ -277,7 +277,7 @@ bool XsnsEnabled(uint8_t sns_index)
bool XsnsPresent(uint8_t sns_index)
{
uint8_t index = 0;
- for (uint8_t i = 0; i < sizeof(kXsnsList); i++) {
+ for (uint32_t i = 0; i < sizeof(kXsnsList); i++) {
#ifdef XFUNC_PTR_IN_ROM
index = pgm_read_byte(kXsnsList + i);
#else
@@ -293,7 +293,7 @@ String XsnsGetSensors(void)
char state[2] = { 0 };
String data = F("[");
- for (uint8_t i = 0; i < MAX_XSNS_DRIVERS; i++) {
+ for (uint32_t i = 0; i < MAX_XSNS_DRIVERS; i++) {
if (i && (!(i % 16))) { data += F(","); }
if (!(i % 16)) { data += F("\""); }
state[0] = '-';