mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Change ARRAY_SIZE() to nitems()
This commit is contained in:
parent
4d3fda5a74
commit
89d8fbb0ec
@ -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"));
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
/*********************************************************************************************\
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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; i<ARRAY_SIZE(WebServerDispatch); i++) {
|
||||
for (uint32_t i=0; i<nitems(WebServerDispatch); i++) {
|
||||
const WebServerDispatch_t & line = WebServerDispatch[i];
|
||||
// copy uri in RAM and prefix with '/'
|
||||
char uri[4];
|
||||
@ -1325,7 +1325,7 @@ void HandleConfiguration(void)
|
||||
|
||||
void WSContentSendNiceLists(uint32_t option) {
|
||||
char stemp[30]; // Template number and Sensor name
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(kGpioNiceList); i++) { // GPIO: }2'0'>None (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("<tr><td style='width:116px'>%s <b>" D_GPIO "%d</b></td><td style='width:146px'><select id='g%d' onchange='ot(%d,this.value)'></select></td>"),
|
||||
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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++;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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; i<ARRAY_SIZE(Z_Data_Type_char); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_Data_Type_char); i++) {
|
||||
if (pgm_read_byte(&Z_Data_Type_char[i]) == c) {
|
||||
return (Z_Data_Type) i;
|
||||
}
|
||||
@ -115,7 +115,7 @@ char Z_Data::DataTypeToChar(Z_Data_Type t) {
|
||||
return '_';
|
||||
} else {
|
||||
uint8_t tt = (uint8_t) t;
|
||||
if (tt < ARRAY_SIZE(Z_Data_Type_char)) {
|
||||
if (tt < nitems(Z_Data_Type_char)) {
|
||||
return pgm_read_byte(&Z_Data_Type_char[tt]);
|
||||
}
|
||||
}
|
||||
@ -418,7 +418,7 @@ public:
|
||||
inline void setZoneType(uint16_t _zone_type) { zone_type = _zone_type; }
|
||||
|
||||
bool update(void) {
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(Z_Alarm_Types); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_Alarm_Types); i++) {
|
||||
Z_Alarm_Types_t conv_type;
|
||||
conv_type.i = pgm_read_word(&Z_Alarm_Types[i].i);
|
||||
if (zone_type == conv_type.t.zcl_type) {
|
||||
@ -553,7 +553,7 @@ const uint8_t Z_Data_Type_len[] PROGMEM = {
|
||||
|
||||
size_t Z_Data::DataTypeToLength(Z_Data_Type t) {
|
||||
uint32_t tt = (uint32_t) t;
|
||||
if (tt < ARRAY_SIZE(Z_Data_Type_len)) {
|
||||
if (tt < nitems(Z_Data_Type_len)) {
|
||||
return pgm_read_byte(&Z_Data_Type_len[tt]);
|
||||
}
|
||||
return 0;
|
||||
|
@ -145,7 +145,7 @@ SBuffer hibernateDevicev2(const struct Z_Device &device) {
|
||||
|
||||
char *names[3] = { device.modelId, device.manufacturerId, device.friendlyName };
|
||||
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(names); i++) {
|
||||
for (uint32_t i=0; i<nitems(names); i++) {
|
||||
char *p = names[i];
|
||||
if (p) {
|
||||
size_t len = strlen(p);
|
||||
|
@ -140,14 +140,14 @@ const uint16_t Cx_cluster[] PROGMEM = {
|
||||
};
|
||||
|
||||
uint16_t CxToCluster(uint8_t cx) {
|
||||
if (cx < ARRAY_SIZE(Cx_cluster)) {
|
||||
if (cx < nitems(Cx_cluster)) {
|
||||
return pgm_read_word(&Cx_cluster[cx]);
|
||||
}
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
uint8_t ClusterToCx(uint16_t cluster) {
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(Cx_cluster); i++) {
|
||||
for (uint32_t i=0; i<nitems(Cx_cluster); i++) {
|
||||
if (pgm_read_word(&Cx_cluster[i]) == cluster) {
|
||||
return i;
|
||||
}
|
||||
@ -170,7 +170,7 @@ const int8_t Cm_multiplier[] PROGMEM = {
|
||||
|
||||
int8_t CmToMultiplier(uint8_t cm) {
|
||||
cm = cm & 0x0F; // get only low nibble
|
||||
if (cm < ARRAY_SIZE(Cm_multiplier)) {
|
||||
if (cm < nitems(Cm_multiplier)) {
|
||||
return pgm_read_byte(&Cm_multiplier[cm]);
|
||||
}
|
||||
return 1;
|
||||
@ -668,7 +668,7 @@ typedef union ZCLHeaderFrameControl_t {
|
||||
const __FlashStringHelper* zigbeeFindAttributeByName(const char *command,
|
||||
uint16_t *cluster, uint16_t *attribute, int8_t *multiplier,
|
||||
uint8_t *zigbee_type = nullptr, Z_Data_Type *data_type = nullptr, uint8_t *map_offset = nullptr) {
|
||||
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];
|
||||
if (0 == pgm_read_word(&converter->name_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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<ARRAY_SIZE(Z_bindings); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_bindings); i++) {
|
||||
if (pgm_read_byte(&Z_bindings[i]) == cx) {
|
||||
return i;
|
||||
}
|
||||
@ -711,7 +711,7 @@ void Z_AutoBindDefer(uint16_t shortaddr, uint8_t endpoint, const SBuffer &buf,
|
||||
}
|
||||
|
||||
// enqueue bind requests
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(Z_bindings); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_bindings); i++) {
|
||||
if (bitRead(cluster_map, i)) {
|
||||
uint16_t cluster = CxToCluster(pgm_read_byte(&Z_bindings[i]));
|
||||
if ((cluster == 0x0001) && (!Z_BatteryReportingDeviceSpecific(shortaddr))) { continue; }
|
||||
@ -720,7 +720,7 @@ void Z_AutoBindDefer(uint16_t shortaddr, uint8_t endpoint, const SBuffer &buf,
|
||||
}
|
||||
|
||||
// enqueue config attribute requests
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(Z_bindings); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_bindings); i++) {
|
||||
if (bitRead(cluster_in_map, i)) {
|
||||
uint16_t cluster = CxToCluster(pgm_read_byte(&Z_bindings[i]));
|
||||
if ((cluster == 0x0001) && (!Z_BatteryReportingDeviceSpecific(shortaddr))) { continue; }
|
||||
@ -1534,7 +1534,7 @@ void Z_AutoConfigReportingForCluster(uint16_t shortaddr, uint16_t groupaddr, uin
|
||||
Response_P(PSTR("ZbSend {\"Device\":\"0x%04X\",\"Config\":{"), shortaddr);
|
||||
|
||||
boolean comma = false;
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(Z_autoAttributeReporting); i++) {
|
||||
for (uint32_t i=0; i<nitems(Z_autoAttributeReporting); i++) {
|
||||
uint16_t conv_cluster = pgm_read_word(&(Z_autoAttributeReporting[i].cluster));
|
||||
uint16_t attr_id = pgm_read_word(&(Z_autoAttributeReporting[i].attr_id));
|
||||
|
||||
@ -2000,7 +2000,7 @@ int32_t ZNP_Recv_Default(int32_t res, const SBuffer &buf) {
|
||||
// if still during initialization phase, ignore any unexpected message
|
||||
return -1; // ignore message
|
||||
} else {
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(Z_DispatchTable); i++) {
|
||||
for (uint32_t i = 0; i < nitems(Z_DispatchTable); i++) {
|
||||
if (Z_ReceiveMatchPrefix(buf, Z_DispatchTable[i].match)) {
|
||||
(*Z_DispatchTable[i].func)(res, buf);
|
||||
}
|
||||
@ -2120,7 +2120,7 @@ void ZCLFrame::autoResponder(const uint16_t *attr_list_ids, size_t attr_len) {
|
||||
LightGetHSB(&hue, &sat, nullptr);
|
||||
LightGetXY(&XY[0], &XY[1]);
|
||||
uint16_t uxy[2];
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(XY); i++) {
|
||||
for (uint32_t i = 0; i < nitems(XY); i++) {
|
||||
uxy[i] = XY[i] * 65536.0f;
|
||||
uxy[i] = (uxy[i] > 0xFEFF) ? uxy[i] : 0xFEFF;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -62,15 +62,15 @@ void TCPLoop(void)
|
||||
if ((server_tcp) && (server_tcp->hasClient())) {
|
||||
// find an empty slot
|
||||
uint32_t i;
|
||||
for (i=0; i<ARRAY_SIZE(client_tcp); i++) {
|
||||
for (i=0; i<nitems(client_tcp); i++) {
|
||||
WiFiClient &client = client_tcp[i];
|
||||
if (!client) {
|
||||
client = server_tcp->available();
|
||||
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<ARRAY_SIZE(client_tcp); i++) {
|
||||
for (uint32_t i=0; i<nitems(client_tcp); i++) {
|
||||
WiFiClient &client = client_tcp[i];
|
||||
if (client) { client.write(tcp_buf, buf_len); }
|
||||
}
|
||||
}
|
||||
|
||||
// handle data received from TCP
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(client_tcp); i++) {
|
||||
for (uint32_t i=0; i<nitems(client_tcp); i++) {
|
||||
WiFiClient &client = client_tcp[i];
|
||||
buf_len = 0;
|
||||
while (client && (buf_len < TCP_BRIDGE_BUF_SIZE) && (client.available())) {
|
||||
@ -152,7 +152,7 @@ void CmndTCPStart(void) {
|
||||
delete server_tcp;
|
||||
server_tcp = nullptr;
|
||||
|
||||
for (uint32_t i=0; i<ARRAY_SIZE(client_tcp); i++) {
|
||||
for (uint32_t i=0; i<nitems(client_tcp); i++) {
|
||||
WiFiClient &client = client_tcp[i];
|
||||
client.stop();
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ void Sdm72Every250ms(void)
|
||||
#endif // SDM72_IMPEXP
|
||||
}
|
||||
|
||||
++Sdm72.read_state %= ARRAY_SIZE(sdm72_register);
|
||||
++Sdm72.read_state %= nitems(sdm72_register);
|
||||
if (0 == Sdm72.read_state && !isnan(Sdm72.total_active)) {
|
||||
EnergyUpdateTotal(Sdm72.total_active, true);
|
||||
}
|
||||
|
@ -2170,7 +2170,7 @@ uint32_t SML_getscriptsize(char *lp) {
|
||||
#endif
|
||||
|
||||
bool Gpio_used(uint8_t gpiopin) {
|
||||
if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) {
|
||||
if ((gpiopin < nitems(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -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<ARRAY_SIZE(NeoPoolReg); i++) {
|
||||
for(uint32_t i=0; i<nitems(NeoPoolReg); i++) {
|
||||
if (nullptr == NeoPoolReg[i].data) {
|
||||
NeoPoolReg[i].data = (uint16_t *)malloc(sizeof(uint16_t)*NeoPoolReg[i].cnt);
|
||||
if (nullptr != NeoPoolReg[i].data) {
|
||||
@ -1001,7 +1001,7 @@ uint8_t NeoPoolWriteRegister(uint16_t addr, uint16_t *data, uint16_t cnt)
|
||||
|
||||
uint16_t NeoPoolGetData(uint16_t addr)
|
||||
{
|
||||
for(uint32_t i=0; i<ARRAY_SIZE(NeoPoolReg); i++) {
|
||||
for(uint32_t i=0; i<nitems(NeoPoolReg); i++) {
|
||||
if (nullptr != NeoPoolReg[i].data && addr >= 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user