From 89d8fbb0ec756290ddc422e08b209c586f59dca4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 28 Feb 2021 12:50:02 +0100 Subject: [PATCH] Change ARRAY_SIZE() to nitems() --- tasmota/settings.ino | 2 +- tasmota/support.ino | 26 +++++++++---------- tasmota/support_command.ino | 18 ++++++------- tasmota/support_tasmota.ino | 10 ++++---- tasmota/tasmota.ino | 2 +- tasmota/tasmota_ca.ino | 2 +- tasmota/tasmota_globals.h | 6 ++--- tasmota/xdrv_01_webserver.ino | 20 +++++++-------- tasmota/xdrv_02_mqtt.ino | 4 +-- tasmota/xdrv_10_scripter.ino | 2 +- tasmota/xdrv_16_tuyamcu.ino | 10 ++++---- tasmota/xdrv_23_zigbee_2_devices.ino | 8 +++--- tasmota/xdrv_23_zigbee_4_persistence.ino | 2 +- tasmota/xdrv_23_zigbee_5_converters.ino | 20 +++++++-------- tasmota/xdrv_23_zigbee_7_0_statemachine.ino | 6 ++--- tasmota/xdrv_23_zigbee_8_parsers.ino | 14 +++++------ tasmota/xdrv_23_zigbee_A_impl.ino | 4 +-- tasmota/xdrv_41_tcp_bridge.ino | 12 ++++----- tasmota/xnrg_18_sdm72.ino | 2 +- tasmota/xsns_53_sml.ino | 2 +- tasmota/xsns_83_neopool.ino | 28 ++++++++++----------- 21 files changed, 99 insertions(+), 101 deletions(-) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index d4857bb15..fe5316e9f 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -744,7 +744,7 @@ void SettingsDefaultSet2(void) { Settings.module = MODULE; Settings.fallback_module = FALLBACK_MODULE; ModuleDefault(WEMOS); -// for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { Settings.my_gp.io[i] = GPIO_NONE; } +// for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { Settings.my_gp.io[i] = GPIO_NONE; } SettingsUpdateText(SET_FRIENDLYNAME1, PSTR(FRIENDLY_NAME)); SettingsUpdateText(SET_FRIENDLYNAME2, PSTR(FRIENDLY_NAME"2")); SettingsUpdateText(SET_FRIENDLYNAME3, PSTR(FRIENDLY_NAME"3")); diff --git a/tasmota/support.ino b/tasmota/support.ino index 0cb0daf5a..d5ba2d914 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1237,7 +1237,7 @@ int ResponseJsonEndEnd(void) #ifdef ESP8266 uint16_t GpioConvert(uint8_t gpio) { - if (gpio >= ARRAY_SIZE(kGpioConvert)) { + if (gpio >= nitems(kGpioConvert)) { return AGPIO(GPIO_USER); } return pgm_read_word(kGpioConvert + gpio); @@ -1285,7 +1285,7 @@ void ConvertGpios(void) { void DumpConvertTable(void) { bool jsflg = false; uint32_t lines = 1; - for (uint32_t i = 0; i < ARRAY_SIZE(kGpioConvert); i++) { + for (uint32_t i = 0; i < nitems(kGpioConvert); i++) { uint32_t data = pgm_read_word(kGpioConvert + i); if (!jsflg) { Response_P(PSTR("{\"GPIOConversion%d\":{"), lines); @@ -1293,14 +1293,14 @@ void DumpConvertTable(void) { ResponseAppend_P(PSTR(",")); } jsflg = true; - if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == ARRAY_SIZE(kGpioConvert) -1)) { + if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == nitems(kGpioConvert) -1)) { ResponseJsonEndEnd(); MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command); jsflg = false; lines++; } } - for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { + for (uint32_t i = 0; i < nitems(kAdcNiceList); i++) { uint32_t data = pgm_read_word(kAdcNiceList + i); if (!jsflg) { Response_P(PSTR("{\"ADC0Conversion%d\":{"), lines); @@ -1308,7 +1308,7 @@ void DumpConvertTable(void) { ResponseAppend_P(PSTR(",")); } jsflg = true; - if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == ARRAY_SIZE(kAdcNiceList) -1)) { + if ((ResponseAppend_P(PSTR("\"%d\":\"%d\""), i, data) > (MAX_LOGSZ - TOPSZ)) || (i == nitems(kAdcNiceList) -1)) { ResponseJsonEndEnd(); MqttPublishPrefixTopic_P(RESULT_OR_STAT, XdrvMailbox.command); jsflg = false; @@ -1328,7 +1328,7 @@ int ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) { real_gpio += index; mask = 0xFFFF; } - for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.gpio_pin); i++) { + for (uint32_t i = 0; i < nitems(TasmotaGlobal.gpio_pin); i++) { if ((TasmotaGlobal.gpio_pin[i] & mask) == real_gpio) { return i; // Pin number configured for gpio } @@ -1342,7 +1342,7 @@ bool PinUsed(uint32_t gpio, uint32_t index) { } uint32_t GetPin(uint32_t lpin) { - if (lpin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) { + if (lpin < nitems(TasmotaGlobal.gpio_pin)) { return TasmotaGlobal.gpio_pin[lpin]; } else { return GPIO_NONE; @@ -1466,7 +1466,7 @@ void GetInternalTemplate(void* ptr, uint32_t module, uint32_t option) { void TemplateGpios(myio *gp) { uint16_t *dest = (uint16_t *)gp; - uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)]; + uint16_t src[nitems(Settings.user_template.gp.io)]; memset(dest, GPIO_NONE, sizeof(myio)); if (USER_MODULE == Settings.module) { @@ -1484,7 +1484,7 @@ void TemplateGpios(myio *gp) // AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio)); uint32_t j = 0; - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } dest[j] = src[i]; @@ -1600,7 +1600,7 @@ bool JsonTemplate(char* dataBuf) uint8_t template8[sizeof(mytmplt8285)] = { GPIO_NONE }; if (13 == arr.size()) { // Possible old template uint32_t gpio = 0; - for (uint32_t i = 0; i < ARRAY_SIZE(template8) -1; i++) { + for (uint32_t i = 0; i < nitems(template8) -1; i++) { gpio = arr[i].getUInt(); if (gpio > 255) { // New templates might have values above 255 break; @@ -1615,13 +1615,13 @@ bool JsonTemplate(char* dataBuf) val = root[PSTR(D_JSON_FLAG)]; if (val) { - template8[ARRAY_SIZE(template8) -1] = val.getUInt() & 0x0F; + template8[nitems(template8) -1] = val.getUInt() & 0x0F; } TemplateConvert(template8, Settings.user_template.gp.io); Settings.user_template.flag.data = 0; } else { #endif - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { JsonParserToken val = arr[i]; if (!val) { break; } uint16_t gpio = val.getUInt(); @@ -1657,7 +1657,7 @@ void TemplateJson(void) // AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)&Settings.user_template, sizeof(Settings.user_template) / 2, 2); Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME)); - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { uint16_t gpio = Settings.user_template.gp.io[i]; if (gpio == AGPIO(GPIO_USER)) { gpio = AGPIO(GPIO_NONE) +1; diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 5dc9e9eaa..1a16279ad 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1156,7 +1156,7 @@ void CmndModule(void) Settings.module = XdrvMailbox.payload; SetModuleType(); if (Settings.last_module != XdrvMailbox.payload) { - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { Settings.my_gp.io[i] = GPIO_NONE; } } @@ -1200,12 +1200,12 @@ void CmndModules(void) void CmndGpio(void) { - if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) { + if (XdrvMailbox.index < nitems(Settings.my_gp.io)) { myio template_gp; TemplateGpios(&template_gp); if (ValidGPIO(XdrvMailbox.index, template_gp.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < AGPIO(GPIO_SENSOR_END))) { bool present = false; - for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { + for (uint32_t i = 0; i < nitems(kGpioNiceList); i++) { uint32_t midx = pgm_read_word(kGpioNiceList + i); uint32_t max_midx = ((midx & 0x001F) > 0) ? midx : midx +1; if ((XdrvMailbox.payload >= (midx & 0xFFE0)) && (XdrvMailbox.payload < max_midx)) { @@ -1214,7 +1214,7 @@ void CmndGpio(void) } } if (present) { - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { if (ValidGPIO(i, template_gp.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) { Settings.my_gp.io[i] = GPIO_NONE; } @@ -1225,7 +1225,7 @@ void CmndGpio(void) } bool jsflg = false; bool jsflg2 = false; - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { if (ValidGPIO(i, template_gp.io[i]) || ((255 == XdrvMailbox.payload) && !FlashPin(i))) { if (!jsflg) { Response_P(PSTR("{")); @@ -1243,7 +1243,7 @@ void CmndGpio(void) char sindex[4] = { 0 }; uint32_t sensor_name_idx = BGPIO(sensor_type); uint32_t nice_list_search = sensor_type & 0xFFE0; - for (uint32_t j = 0; j < ARRAY_SIZE(kGpioNiceList); j++) { + for (uint32_t j = 0; j < nitems(kGpioNiceList); j++) { uint32_t nls_idx = pgm_read_word(kGpioNiceList + j); if (((nls_idx & 0xFFE0) == nice_list_search) && ((nls_idx & 0x001F) > 0)) { snprintf_P(sindex, sizeof(sindex), PSTR("%d"), (sensor_type & 0x001F) +1); @@ -1310,10 +1310,10 @@ void CmndGpios(void) // DumpConvertTable(); ShowGpios(nullptr, GPIO_SENSOR_END, 0, lines); } else { - ShowGpios(kGpioNiceList, ARRAY_SIZE(kGpioNiceList), 0, lines); + ShowGpios(kGpioNiceList, nitems(kGpioNiceList), 0, lines); #ifdef ESP8266 #ifndef USE_ADC_VCC - ShowGpios(kAdcNiceList, ARRAY_SIZE(kAdcNiceList), 1, lines); + ShowGpios(kAdcNiceList, nitems(kAdcNiceList), 1, lines); #endif // USE_ADC_VCC #endif // ESP8266 } @@ -1345,7 +1345,7 @@ void CmndTemplate(void) } SettingsUpdateText(SET_TEMPLATE_NAME, PSTR("Merged")); uint32_t j = 0; - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } if (TasmotaGlobal.my_module.io[j] > GPIO_NONE) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 1e57256e6..9556f5aee 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1556,7 +1556,7 @@ void GpioInit(void) ConvertGpios(); #endif // ESP8266 - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { if ((Settings.user_template.gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.user_template.gp.io[i] < AGPIO(GPIO_USER))) { Settings.user_template.gp.io[i] = AGPIO(GPIO_USER); // Fix not supported sensor ids in template } @@ -1564,7 +1564,7 @@ void GpioInit(void) myio template_gp; TemplateGpios(&template_gp); - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { if ((Settings.my_gp.io[i] >= AGPIO(GPIO_SENSOR_END)) && (Settings.my_gp.io[i] < AGPIO(GPIO_USER))) { Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module } @@ -1576,7 +1576,7 @@ void GpioInit(void) } } - for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.my_module.io); i++) { + for (uint32_t i = 0; i < nitems(TasmotaGlobal.my_module.io); i++) { uint32_t mpin = ValidPin(i, TasmotaGlobal.my_module.io[i]); DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin); @@ -1648,7 +1648,7 @@ void GpioInit(void) if (mpin) { SetPin(i, mpin); } // Anything above GPIO_NONE and below GPIO_SENSOR_END } -// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)TasmotaGlobal.gpio_pin, ARRAY_SIZE(TasmotaGlobal.gpio_pin), sizeof(TasmotaGlobal.gpio_pin[0])); +// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)TasmotaGlobal.gpio_pin, nitems(TasmotaGlobal.gpio_pin), sizeof(TasmotaGlobal.gpio_pin[0])); analogWriteRange(Settings.pwm_range); // Default is 1023 (Arduino.h) analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c) @@ -1715,7 +1715,7 @@ void GpioInit(void) AddLogSpi(1, Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_MISO)); #endif // USE_SPI - for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.my_module.io); i++) { + for (uint32_t i = 0; i < nitems(TasmotaGlobal.my_module.io); i++) { uint32_t mpin = ValidPin(i, TasmotaGlobal.my_module.io[i]); // AddLog(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin); if (AGPIO(GPIO_OUTPUT_HI) == mpin) { diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index c0b7b4669..637d2b84b 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -307,7 +307,7 @@ void setup(void) { TasmotaGlobal.no_autoexec = true; } if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors } } diff --git a/tasmota/tasmota_ca.ino b/tasmota/tasmota_ca.ino index 97b79614b..f4982c688 100644 --- a/tasmota/tasmota_ca.ino +++ b/tasmota/tasmota_ca.ino @@ -245,7 +245,7 @@ const br_x509_trust_anchor PROGMEM Tasmota_TA[] = { } }; -const size_t Tasmota_TA_size = ARRAY_SIZE(Tasmota_TA); +const size_t Tasmota_TA_size = nitems(Tasmota_TA); // we add a separate CA for telegram /*********************************************************************************************\ diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 9c05574d7..52149943c 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -461,15 +461,13 @@ const char kWebColors[] PROGMEM = #define tmin(a,b) ((a)<(b)?(a):(b)) #define tmax(a,b) ((a)>(b)?(a):(b)) +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) + #define STR_HELPER(x) #x #ifndef STR #define STR(x) STR_HELPER(x) #endif -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - #define AGPIO(x) ((x)<<5) #define BGPIO(x) ((x)>>5) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 4ded970b9..4595f50a2 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -453,7 +453,7 @@ void StartWebserver(int type, IPAddress ipweb) if (!Webserver) { Webserver = new ESP8266WebServer((HTTP_MANAGER == type || HTTP_MANAGER_RESET_ONLY == type) ? 80 : WEB_PORT); // call `Webserver->on()` on each entry - for (uint32_t i=0; iNone (0)}3}2'17'>Button1 (17)}3... + for (uint32_t i = 0; i < nitems(kGpioNiceList); i++) { // GPIO: }2'0'>None (0)}3}2'17'>Button1 (17)}3... if (option && (1 == i)) { WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), PSTR(D_SENSOR_USER)); // }2'255'>User}3 } @@ -1338,7 +1338,7 @@ void WSContentSendNiceLists(uint32_t option) { WSContentSend_P(PSTR("hs=[")); uint32_t midx; bool first_done = false; - for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { // hs=[36,68,100,132,168,200,232,264,292,324,356,388,421,453]; + for (uint32_t i = 0; i < nitems(kGpioNiceList); i++) { // hs=[36,68,100,132,168,200,232,264,292,324,356,388,421,453]; midx = pgm_read_word(kGpioNiceList + i); if (midx & 0x001F) { if (first_done) { WSContentSend_P(PSTR(",")); } @@ -1348,7 +1348,7 @@ void WSContentSendNiceLists(uint32_t option) { } #ifdef ESP8266 #ifdef USE_ADC - for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { // hs=[36,68,100,132,168,200,232,264,292,324,356,388,421,453]; + for (uint32_t i = 0; i < nitems(kAdcNiceList); i++) { // hs=[36,68,100,132,168,200,232,264,292,324,356,388,421,453]; midx = pgm_read_word(kAdcNiceList + i); if (midx & 0x001F) { if (first_done) { WSContentSend_P(PSTR(",")); } @@ -1366,7 +1366,7 @@ void WSContentSendNiceLists(uint32_t option) { void WSContentSendAdcNiceList(uint32_t option) { char stemp[30]; // Template number and Sensor name WSContentSend_P(PSTR("os=\"")); - for (uint32_t i = 0; i < ARRAY_SIZE(kAdcNiceList); i++) { // GPIO: }2'0'>None}3}2'17'>Analog}3... + for (uint32_t i = 0; i < nitems(kAdcNiceList); i++) { // GPIO: }2'0'>None}3}2'17'>Analog}3... if (option && (1 == i)) { WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX, AGPIO(GPIO_USER), PSTR(D_SENSOR_USER)); // }2'15'>User}3 } @@ -1404,7 +1404,7 @@ void HandleTemplateConfiguration(void) WSContentBegin(200, CT_PLAIN); WSContentSend_P(PSTR("%s}1"), AnyModuleName(module).c_str()); // NAME: Generic - for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 + for (uint32_t i = 0; i < nitems(template_gp.io); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 if (!FlashPin(i)) { WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", template_gp.io[i]); } @@ -1490,7 +1490,7 @@ void TemplateSaveSettings(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); uint32_t j = 0; - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } snprintf_P(svalue, sizeof(svalue), PSTR("%s%s%d"), svalue, (i>0)?",":"", WebGetGpioArg(j)); @@ -1549,7 +1549,7 @@ void HandleModuleConfiguration(void) WSContentSendNiceLists(0); - for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) { + for (uint32_t i = 0; i < nitems(template_gp.io); i++) { if (ValidGPIO(i, template_gp.io[i])) { WSContentSend_P(PSTR("sk(%d,%d);"), TasmotaGlobal.my_module.io[i], i); // g0 - g17 } @@ -1566,7 +1566,7 @@ void HandleModuleConfiguration(void) WSContentSendStyle(); WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str()); - for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) { + for (uint32_t i = 0; i < nitems(template_gp.io); i++) { if (ValidGPIO(i, template_gp.io[i])) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); WSContentSend_P(PSTR("%s " D_GPIO "%d"), @@ -1592,7 +1592,7 @@ void ModuleSaveSettings(void) myio template_gp; TemplateGpios(&template_gp); String gpios = ""; - for (uint32_t i = 0; i < ARRAY_SIZE(template_gp.io); i++) { + for (uint32_t i = 0; i < nitems(template_gp.io); i++) { if (Settings.last_module != new_module) { Settings.my_gp.io[i] = GPIO_NONE; } else { diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index b90007e44..6be10eb70 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -33,7 +33,7 @@ WiFiClient EspClient; // Wifi Client - non-TLS const char kMqttCommands[] PROGMEM = "|" // No prefix // SetOption synonyms - D_SO_MQTTJSONONLY "|" + D_SO_MQTTJSONONLY "|" #ifdef USE_MQTT_TLS D_SO_MQTTTLS "|" #endif @@ -195,7 +195,7 @@ void MqttInit(void) { #endif #ifdef USE_MQTT_TLS_CA_CERT - tlsClient->setTrustAnchor(Tasmota_TA, ARRAY_SIZE(Tasmota_TA)); + tlsClient->setTrustAnchor(Tasmota_TA, nitems(Tasmota_TA)); #endif // USE_MQTT_TLS_CA_CERT MqttClient.setClient(*tlsClient); diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 83fd386b8..10a7db17f 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -2676,7 +2676,7 @@ chknext: } } */ - if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) { + if ((gpiopin < nitems(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) { fvar = TasmotaGlobal.gpio_pin[gpiopin]; // skip ] bracket len++; diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index fc2cd861c..22eba70f2 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -330,11 +330,11 @@ float TuyaAdjustedTemperature(int16_t packetValue, uint8_t res) break; case 3: return (float)packetValue / 1000.0; - break; + break; default: return (float)packetValue; break; - } + } } /*********************************************************************************************\ * Internal Functions @@ -622,10 +622,10 @@ void LightSerialDuty(uint16_t duty, char *hex_char, uint8_t TuyaIdx) dpid = TuyaGetDpId(TUYA_MCU_FUNC_CT); } else { dpid = TuyaGetDpId(TUYA_MCU_FUNC_DIMMER2); } } - + if (Tuya.ignore_dim && Tuya.ignore_dimmer_cmd_timeout < millis()) { Tuya.ignore_dim = false; - } + } if (duty > 0 && !Tuya.ignore_dim && TuyaSerial && dpid > 0) { if (TuyaIdx == 2 && CTLight) { @@ -955,7 +955,7 @@ void TuyaNormalPowerModePacketProcess(void) uint8_t key1_gpio = Tuya.buffer[7]; bool key1_set = false; bool led1_set = false; - for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { + for (uint32_t i = 0; i < nitems(Settings.my_gp.io); i++) { if (Settings.my_gp.io[i] == AGPIO(GPIO_LED1)) led1_set = true; else if (Settings.my_gp.io[i] == AGPIO(GPIO_KEY1)) key1_set = true; } diff --git a/tasmota/xdrv_23_zigbee_2_devices.ino b/tasmota/xdrv_23_zigbee_2_devices.ino index 6a6b60655..e349691c7 100644 --- a/tasmota/xdrv_23_zigbee_2_devices.ino +++ b/tasmota/xdrv_23_zigbee_2_devices.ino @@ -100,7 +100,7 @@ Z_Data_Type Z_Data::CharToDataType(char c) { if (c == '_') { return Z_Data_Type::Z_Device; } else { - for (uint32_t i=0; iname_offset)) { continue; } // avoid strcasecmp_P() from crashing if (0 == strcasecmp_P(command, Z_strings + pgm_read_word(&converter->name_offset))) { @@ -690,7 +690,7 @@ const __FlashStringHelper* zigbeeFindAttributeByName(const char *command, // const __FlashStringHelper* zigbeeFindAttributeById(uint16_t cluster, uint16_t attr_id, uint8_t *attr_type, int8_t *multiplier) { - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t conv_cluster = CxToCluster(pgm_read_byte(&converter->cluster_short)); uint16_t conv_attr_id = pgm_read_word(&converter->attribute); @@ -1458,7 +1458,7 @@ void ZCLFrame::parseReadAttributes(Z_attribute_list& attr_list) { read_attr_ids[i/2] = attrid; // find the attribute name - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t conv_cluster = CxToCluster(pgm_read_byte(&converter->cluster_short)); uint16_t conv_attribute = pgm_read_word(&converter->attribute); @@ -1527,7 +1527,7 @@ void ZCLFrame::parseReadConfigAttributes(Z_attribute_list& attr_list) { // find the attribute name int8_t multiplier = 1; - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t conv_cluster = CxToCluster(pgm_read_byte(&converter->cluster_short)); uint16_t conv_attribute = pgm_read_word(&converter->attribute); @@ -1997,7 +1997,7 @@ void Z_postProcessAttributes(uint16_t shortaddr, uint16_t src_ep, class Z_attrib uint8_t map_offset = 0; uint8_t zigbee_type = Znodata; int8_t conv_multiplier; - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t conv_cluster = CxToCluster(pgm_read_byte(&converter->cluster_short)); uint16_t conv_attribute = pgm_read_word(&converter->attribute); @@ -2088,7 +2088,7 @@ void Z_postProcessAttributes(uint16_t shortaddr, uint16_t src_ep, class Z_attrib // Internal search function void Z_parseAttributeKey_inner(class Z_attribute & attr, uint16_t preferred_cluster) { // scan attributes to find by name, and retrieve type - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t local_attr_id = pgm_read_word(&converter->attribute); uint16_t local_cluster_id = CxToCluster(pgm_read_byte(&converter->cluster_short)); @@ -2177,7 +2177,7 @@ bool Z_parseAttributeKey(class Z_attribute & attr, uint16_t preferred_cluster) { void Z_Data::toAttributes(Z_attribute_list & attr_list) const { Z_Data_Type type = getType(); // iterate through attributes to see which ones need to be exported - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint8_t conv_export = pgm_read_byte(&converter->multiplier_idx) & Z_EXPORT_DATA; uint8_t conv_mapping = pgm_read_byte(&converter->mapping); diff --git a/tasmota/xdrv_23_zigbee_7_0_statemachine.ino b/tasmota/xdrv_23_zigbee_7_0_statemachine.ino index bb50d300c..a9afb9764 100644 --- a/tasmota/xdrv_23_zigbee_7_0_statemachine.ino +++ b/tasmota/xdrv_23_zigbee_7_0_statemachine.ino @@ -438,7 +438,7 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = { ZI_SEND(ZBS_PFGK) // check PFGK on ZB1.2 ZI_WAIT_RECV(1000, ZBR_PFGK) ZI_GOTO(ZIGBEE_LABEL_START_COORD) - + ZI_LABEL(ZIGBEE_LABEL_ZB3_INIT) ZI_SEND(ZBS_PFGK3) // check PFGK on ZB3 ZI_WAIT_RECV(1000, ZBR_PFGK3) @@ -947,7 +947,7 @@ void ZigbeeGotoLabel(uint8_t label) { uint8_t cur_d8 = 0; uint8_t cur_instr_len = 1; // size of current instruction in words - for (uint32_t i = 0; i < ARRAY_SIZE(zb_prog); i += cur_instr_len) { + for (uint32_t i = 0; i < nitems(zb_prog); i += cur_instr_len) { const Zigbee_Instruction *cur_instr_line = &zb_prog[i]; cur_instr = pgm_read_byte(&cur_instr_line->i.i); cur_d8 = pgm_read_byte(&cur_instr_line->i.d8); @@ -1006,7 +1006,7 @@ void ZigbeeStateMachine_Run(void) { zigbee.recv_until = false; zigbee.state_no_timeout = false; // reset the no_timeout for next instruction - if (zigbee.pc > ARRAY_SIZE(zb_prog)) { + if (zigbee.pc > nitems(zb_prog)) { AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_ZIGBEE "Invalid pc: %d, aborting"), zigbee.pc); zigbee.pc = -1; } diff --git a/tasmota/xdrv_23_zigbee_8_parsers.ino b/tasmota/xdrv_23_zigbee_8_parsers.ino index 04fed0f57..39db75771 100644 --- a/tasmota/xdrv_23_zigbee_8_parsers.ino +++ b/tasmota/xdrv_23_zigbee_8_parsers.ino @@ -207,7 +207,7 @@ void EnergyScanResults(void) { uint32_t bars = changeUIntScale(energy_unsigned, bar_min + 0x80, bar_max + 0x80, 0, bar_count); for (uint32_t j = 0; j < bars; j++) { bar_str[j] = '#'; } bar_str[bars] = 0; - + AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Channel %2d: %s"), i + USE_ZIGBEE_CHANNEL_MIN, bar_str); } ResponseAppend_P(PSTR("]}")); @@ -667,7 +667,7 @@ const uint8_t Z_bindings[] PROGMEM = { int32_t Z_ClusterToCxBinding(uint16_t cluster) { uint8_t cx = ClusterToCx(cluster); - for (uint32_t i=0; i 0xFEFF) ? uxy[i] : 0xFEFF; } diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index 870315055..fc8bfdc3c 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -622,7 +622,7 @@ void ZbSendRead(JsonParserToken val_attr, ZCLMessage & zcl) { bool found = false; // scan attributes to find by name, and retrieve type - for (uint32_t i = 0; i < ARRAY_SIZE(Z_PostProcess); i++) { + for (uint32_t i = 0; i < nitems(Z_PostProcess); i++) { const Z_AttributeConverter *converter = &Z_PostProcess[i]; uint16_t local_attr_id = pgm_read_word(&converter->attribute); uint16_t local_cluster_id = CxToCluster(pgm_read_byte(&converter->cluster_short)); @@ -1463,7 +1463,7 @@ void CmndZbPermitJoin(void) { } if (0 == zigbee.permit_end_time) { zigbee.permit_end_time = 1; } // avoid very rare case where timer collides with timestamp equals to zero } - + ResponseCmndDone(); } diff --git a/tasmota/xdrv_41_tcp_bridge.ino b/tasmota/xdrv_41_tcp_bridge.ino index aeadfde61..44a686e77 100644 --- a/tasmota/xdrv_41_tcp_bridge.ino +++ b/tasmota/xdrv_41_tcp_bridge.ino @@ -62,15 +62,15 @@ void TCPLoop(void) if ((server_tcp) && (server_tcp->hasClient())) { // find an empty slot uint32_t i; - for (i=0; iavailable(); break; } } - if (i >= ARRAY_SIZE(client_tcp)) { - i = client_next++ % ARRAY_SIZE(client_tcp); + if (i >= nitems(client_tcp)) { + i = client_next++ % nitems(client_tcp); WiFiClient &client = client_tcp[i]; client.stop(); client = server_tcp->available(); @@ -92,14 +92,14 @@ void TCPLoop(void) if (buf_len > 0) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "from MCU: %*_H"), buf_len, tcp_buf); - for (uint32_t i=0; i 0)) { + if ((gpiopin < nitems(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) { return true; } return false; diff --git a/tasmota/xsns_83_neopool.ino b/tasmota/xsns_83_neopool.ino index eb7ac25d4..22fc9489b 100644 --- a/tasmota/xsns_83_neopool.ino +++ b/tasmota/xsns_83_neopool.ino @@ -767,7 +767,7 @@ void NeoPool250ms(void) // Every 250 mSec } #endif // DEBUG_TASMOTA_SENSOR - ++neopool_read_state %= ARRAY_SIZE(NeoPoolReg); + ++neopool_read_state %= nitems(NeoPoolReg); #ifdef NEOPOOL_OPTIMIZE_READINGS if (0 == neopool_read_state) { neopool_first_read = false; @@ -795,7 +795,7 @@ void NeoPool250ms(void) // Every 250 mSec #ifdef DEBUG_TASMOTA_SENSOR AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("NEO: notify 0x%04X - addr block 0x%04X ignored"), NeoPoolGetData(MBF_NOTIFICATION), NeoPoolReg[neopool_read_state].addr); #endif // DEBUG_TASMOTA_SENSOR - ++neopool_read_state %= ARRAY_SIZE(NeoPoolReg); + ++neopool_read_state %= nitems(NeoPoolReg); } } #endif // NEOPOOL_OPTIMIZE_READINGS @@ -840,7 +840,7 @@ bool NeoPoolInitData(void) bool res = false; neopool_error = true; - for(uint32_t i=0; i= NeoPoolReg[i].addr && addr < NeoPoolReg[i].addr+NeoPoolReg[i].cnt) { return NeoPoolReg[i].data[addr - NeoPoolReg[i].addr]; } @@ -1206,14 +1206,14 @@ void NeoPoolShow(bool json) } // Filtration mode - GetTextIndexed(stemp, sizeof(stemp), NeoPoolGetData(MBF_PAR_FILT_MODE) < MBV_PAR_FILT_INTELLIGENT ? NeoPoolGetData(MBF_PAR_FILT_MODE) : ARRAY_SIZE(kNeoPoolFiltrationMode)-1, kNeoPoolFiltrationMode); + GetTextIndexed(stemp, sizeof(stemp), NeoPoolGetData(MBF_PAR_FILT_MODE) < MBV_PAR_FILT_INTELLIGENT ? NeoPoolGetData(MBF_PAR_FILT_MODE) : nitems(kNeoPoolFiltrationMode)-1, kNeoPoolFiltrationMode); WSContentSend_PD(HTTP_SNS_NEOPOOL_FILT_MODE, neopool_type, stemp); // Relays for(uint32_t i=0; i<8; i++) { char sdesc[24]; - memset(sdesc, 0, ARRAY_SIZE(sdesc)); - memset(stemp, 0, ARRAY_SIZE(stemp)); + memset(sdesc, 0, nitems(sdesc)); + memset(stemp, 0, nitems(stemp)); if (0 != NeoPoolGetData(MBF_PAR_PH_ACID_RELAY_GPIO) && i == NeoPoolGetData(MBF_PAR_PH_ACID_RELAY_GPIO)-1) { strncpy_P(sdesc, PSTR(D_NEOPOOL_RELAY_PH_ACID), sizeof(sdesc)); } @@ -1306,14 +1306,14 @@ void CmndNeopoolReadReg(void) { uint16_t addr, data[30] = { 0 }, cnt=1; uint32_t value[2] = { 0 }; - uint32_t params_cnt = ParseParameters(ARRAY_SIZE(value), value); + uint32_t params_cnt = ParseParameters(nitems(value), value); bool fbits32 = !strcasecmp_P(XdrvMailbox.command, PSTR(D_PRFX_NEOPOOL D_CMND_NP_READL)); cnt = 1; if (2 == params_cnt) { cnt = value[1]; } - if (params_cnt && cnt < (fbits32 ? (ARRAY_SIZE(data)/2) : ARRAY_SIZE(data))) { + if (params_cnt && cnt < (fbits32 ? (nitems(data)/2) : nitems(data))) { addr = value[0]; if (NEOPOOL_OK != NeoPoolReadRegister(addr, data, fbits32 ? (cnt*2) : cnt)) { NeopoolResponseError(); @@ -1326,8 +1326,8 @@ void CmndNeopoolReadReg(void) void CmndNeopoolWriteReg(void) { uint16_t addr, data[20] = { 0 }, cnt; - uint32_t value[(ARRAY_SIZE(data)/2)+1] = { 0 }; - uint32_t params_cnt = ParseParameters(ARRAY_SIZE(value), value); + uint32_t value[(nitems(data)/2)+1] = { 0 }; + uint32_t params_cnt = ParseParameters(nitems(value), value); bool fbits32 = !strcasecmp_P(XdrvMailbox.command, PSTR(D_PRFX_NEOPOOL D_CMND_NP_WRITEL)); if (params_cnt > 1) { @@ -1359,7 +1359,7 @@ void CmndNeopoolBit(void) uint16_t addr, data; int8_t bit; uint32_t value[3] = { 0 }; - uint32_t params_cnt = ParseParameters(ARRAY_SIZE(value), value); + uint32_t params_cnt = ParseParameters(nitems(value), value); bool fbits32 = !strcasecmp_P(XdrvMailbox.command, PSTR(D_PRFX_NEOPOOL D_CMND_NP_BITL)); uint16_t tempdata[2]; @@ -1457,7 +1457,7 @@ void CmndNeopoolFiltrationMode(void) NeopoolResponseError(); return; } - ResponseCmndChar(GetTextIndexed(stemp, sizeof(stemp), data < MBV_PAR_FILT_INTELLIGENT ? data : ARRAY_SIZE(kNeoPoolFiltrationMode)-1, kNeoPoolFiltrationMode)); + ResponseCmndChar(GetTextIndexed(stemp, sizeof(stemp), data < MBV_PAR_FILT_INTELLIGENT ? data : nitems(kNeoPoolFiltrationMode)-1, kNeoPoolFiltrationMode)); } void CmndNeopoolTime(void) @@ -1508,7 +1508,7 @@ void CmndNeopoolLight(void) return; } if (relay >=1 && relay <=8) { - if (XdrvMailbox.data_len && XdrvMailbox.payload >= 0 && XdrvMailbox.payload < ARRAY_SIZE(timer_val)) { + if (XdrvMailbox.data_len && XdrvMailbox.payload >= 0 && XdrvMailbox.payload < nitems(timer_val)) { addr = MBF_PAR_TIMER_BLOCK_LIGHT_INT + MBV_TIMER_OFFMB_TIMER_ENABLE; data = timer_val[XdrvMailbox.payload]; NeoPoolWriteRegister(MBF_PAR_TIMER_BLOCK_LIGHT_INT + MBV_TIMER_OFFMB_TIMER_ENABLE, &data, 1);