Implement ARRAY_SIZE macro

This commit is contained in:
Theo Arends 2020-04-25 11:37:36 +02:00
parent 14040f601c
commit 104e3c4838
10 changed files with 34 additions and 34 deletions

View File

@ -741,7 +741,7 @@ void SettingsDefaultSet2(void)
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
Settings.module = MODULE; Settings.module = MODULE;
ModuleDefault(WEMOS); ModuleDefault(WEMOS);
// for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { Settings.my_gp.io[i] = GPIO_NONE; } // for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
SettingsUpdateText(SET_FRIENDLYNAME1, FRIENDLY_NAME); SettingsUpdateText(SET_FRIENDLYNAME1, FRIENDLY_NAME);
SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2"); SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2");
SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3"); SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3");
@ -1098,7 +1098,7 @@ void SettingsDelta(void)
Settings.switchmode[i] = SWITCH_MODE; Settings.switchmode[i] = SWITCH_MODE;
} }
} }
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1 if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
Settings.my_gp.io[i] += 4; Settings.my_gp.io[i] += 4;
} }

View File

@ -1122,10 +1122,10 @@ void ModuleGpios(myio *gp)
{ {
//#ifdef ESP8266 //#ifdef ESP8266
uint8_t *dest = (uint8_t *)gp; uint8_t *dest = (uint8_t *)gp;
uint8_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])]; uint8_t src[ARRAY_SIZE(Settings.user_template.gp.io)];
//#else //#else
// uint16_t *dest = (uint16_t *)gp; // uint16_t *dest = (uint16_t *)gp;
// uint16_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])]; // uint16_t src[ARRAY_SIZE(Settings.user_template.gp.io)];
//#endif //#endif
memset(dest, GPIO_NONE, sizeof(myio)); memset(dest, GPIO_NONE, sizeof(myio));
@ -1143,7 +1143,7 @@ void ModuleGpios(myio *gp)
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio)); // AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
uint32_t j = 0; uint32_t j = 0;
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
if (6 == i) { j = 9; } if (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
dest[j] = src[i]; dest[j] = src[i];
@ -1316,7 +1316,7 @@ bool JsonTemplate(const char* dataBuf)
SettingsUpdateText(SET_TEMPLATE_NAME, name); SettingsUpdateText(SET_TEMPLATE_NAME, name);
} }
if (obj[D_JSON_GPIO].success()) { if (obj[D_JSON_GPIO].success()) {
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0; Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
} }
} }
@ -1335,7 +1335,7 @@ bool JsonTemplate(const char* dataBuf)
void TemplateJson(void) void TemplateJson(void)
{ {
Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME)); Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME));
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
ResponseAppend_P(PSTR("%s%d"), (i>0)?",":"", Settings.user_template.gp.io[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); ResponseAppend_P(PSTR("],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), Settings.user_template.flag, Settings.user_template_base +1);

View File

@ -1006,7 +1006,7 @@ void CmndModule(void)
Settings.module = XdrvMailbox.payload; Settings.module = XdrvMailbox.payload;
SetModuleType(); SetModuleType();
if (Settings.last_module != XdrvMailbox.payload) { if (Settings.last_module != XdrvMailbox.payload) {
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} }
} }
@ -1042,7 +1042,7 @@ void CmndModules(void)
void CmndGpio(void) void CmndGpio(void)
{ {
if (XdrvMailbox.index < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0])) { if (XdrvMailbox.index < ARRAY_SIZE(Settings.my_gp.io)) {
myio cmodule; myio cmodule;
ModuleGpios(&cmodule); ModuleGpios(&cmodule);
if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) { if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) {
@ -1052,7 +1052,7 @@ void CmndGpio(void)
if (midx == XdrvMailbox.payload) { present = true; } if (midx == XdrvMailbox.payload) { present = true; }
} }
if (present) { if (present) {
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) { if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} }
@ -1063,7 +1063,7 @@ void CmndGpio(void)
} }
Response_P(PSTR("{")); Response_P(PSTR("{"));
bool jsflg = false; bool jsflg = false;
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) { if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) {
if (jsflg) { ResponseAppend_P(PSTR(",")); } if (jsflg) { ResponseAppend_P(PSTR(",")); }
jsflg = true; jsflg = true;
@ -1143,7 +1143,7 @@ void CmndTemplate(void)
} }
SettingsUpdateText(SET_TEMPLATE_NAME, "Merged"); SettingsUpdateText(SET_TEMPLATE_NAME, "Merged");
uint32_t j = 0; uint32_t j = 0;
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
if (6 == i) { j = 9; } if (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
if (my_module.io[j] > GPIO_NONE) { if (my_module.io[j] > GPIO_NONE) {

View File

@ -1354,7 +1354,7 @@ void GpioInit(void)
Settings.serial_config = TS_SERIAL_8N1; Settings.serial_config = TS_SERIAL_8N1;
} }
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
if ((Settings.user_template.gp.io[i] >= GPIO_SENSOR_END) && (Settings.user_template.gp.io[i] < GPIO_USER)) { 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 Settings.user_template.gp.io[i] = GPIO_USER; // Fix not supported sensor ids in template
} }
@ -1362,7 +1362,7 @@ void GpioInit(void)
myio def_gp; myio def_gp;
ModuleGpios(&def_gp); ModuleGpios(&def_gp);
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if ((Settings.my_gp.io[i] >= GPIO_SENSOR_END) && (Settings.my_gp.io[i] < GPIO_USER)) { 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 Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
} }
@ -1388,7 +1388,7 @@ void GpioInit(void)
for (uint32_t i = 0; i < GPIO_MAX; i++) { for (uint32_t i = 0; i < GPIO_MAX; i++) {
pin[i] = 99; pin[i] = 99;
} }
for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
mpin = ValidPin(i, my_module.io[i]); mpin = ValidPin(i, my_module.io[i]);
DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin); DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
@ -1465,7 +1465,7 @@ void GpioInit(void)
// Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
// Doing it here solves relay toggles at restart. // Doing it here solves relay toggles at restart.
for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(my_module.io); i++) {
mpin = ValidPin(i, my_module.io[i]); mpin = ValidPin(i, my_module.io[i]);
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin); // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface

View File

@ -260,7 +260,7 @@ void setup(void)
Settings.rule_enabled = 0; // Disable all rules Settings.rule_enabled = 0; // Disable all rules
} }
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
} }
Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors

View File

@ -1466,7 +1466,7 @@ void HandleTemplateConfiguration(void)
} }
WSContentSend_P(PSTR("}1")); // Field separator WSContentSend_P(PSTR("}1")); // Field separator
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255 for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
if (!FlashPin(i)) { if (!FlashPin(i)) {
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]); WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]);
} }
@ -1518,7 +1518,7 @@ void TemplateSaveSettings(void)
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
uint32_t j = 0; uint32_t j = 0;
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) {
if (6 == i) { j = 9; } if (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j); snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j);
@ -1604,7 +1604,7 @@ void HandleModuleConfiguration(void)
WSContentStart_P(S_CONFIGURE_MODULE); WSContentStart_P(S_CONFIGURE_MODULE);
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE); WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module); WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module);
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) { if (ValidGPIO(i, cmodule.io[i])) {
WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16 WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16
} }
@ -1612,7 +1612,7 @@ void HandleModuleConfiguration(void)
WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0); WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0);
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str()); WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str());
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
if (ValidGPIO(i, cmodule.io[i])) { if (ValidGPIO(i, cmodule.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(stemp, 3, PINS_WEMOS +i*2);
#ifdef ESP8266 #ifdef ESP8266
@ -1652,7 +1652,7 @@ void ModuleSaveSettings(void)
myio cmodule; myio cmodule;
ModuleGpios(&cmodule); ModuleGpios(&cmodule);
String gpios = ""; String gpios = "";
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(cmodule.io); i++) {
if (Settings.last_module != new_module) { if (Settings.last_module != new_module) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} else { } else {

View File

@ -569,7 +569,7 @@ void TuyaNormalPowerModePacketProcess(void)
uint8_t key1_gpio = Tuya.buffer[7]; uint8_t key1_gpio = Tuya.buffer[7];
bool key1_set = false; bool key1_set = false;
bool led1_set = false; bool led1_set = false;
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Settings.my_gp.io); i++) {
if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true; if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true;
else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true; else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true;
} }

View File

@ -86,7 +86,7 @@ const uint16_t Z_ClusterNumber[] PROGMEM = {
// convert a 1 byte cluster code to the actual cluster number // convert a 1 byte cluster code to the actual cluster number
uint16_t fromClusterCode(uint8_t c) { uint16_t fromClusterCode(uint8_t c) {
if (c >= sizeof(Z_ClusterNumber)/sizeof(Z_ClusterNumber[0])) { if (c >= ARRAY_SIZE(Z_ClusterNumber)) {
return 0xFFFF; // invalid return 0xFFFF; // invalid
} }
return pgm_read_word(&Z_ClusterNumber[c]); return pgm_read_word(&Z_ClusterNumber[c]);
@ -94,7 +94,7 @@ uint16_t fromClusterCode(uint8_t c) {
// convert a cluster number to 1 byte, or 0xFF if not in table // convert a cluster number to 1 byte, or 0xFF if not in table
uint8_t toClusterCode(uint16_t c) { uint8_t toClusterCode(uint16_t c) {
for (uint32_t i = 0; i < sizeof(Z_ClusterNumber)/sizeof(Z_ClusterNumber[0]); i++) { for (uint32_t i = 0; i < ARRAY_SIZE(Z_ClusterNumber); i++) {
if (c == pgm_read_word(&Z_ClusterNumber[i])) { if (c == pgm_read_word(&Z_ClusterNumber[i])) {
return i; return i;
} }

View File

@ -52,7 +52,7 @@ uint8_t Z_getDatatypeLen(uint8_t t) {
if ( ((t >= 0x08) && (t <= 0x0F)) || // data8 - data64 if ( ((t >= 0x08) && (t <= 0x0F)) || // data8 - data64
((t >= 0x18) && (t <= 0x2F)) ) { // map/uint/int ((t >= 0x18) && (t <= 0x2F)) ) { // map/uint/int
return (t & 0x07) + 1; return (t & 0x07) + 1;
} }
switch (t) { switch (t) {
case Zbool: case Zbool:
case Zenum8: case Zenum8:
@ -574,7 +574,7 @@ typedef struct Z_AttributeConverter {
enum Cx_cluster_short { enum Cx_cluster_short {
Cx0000, Cx0001, Cx0002, Cx0003, Cx0004, Cx0005, Cx0006, Cx0007, Cx0000, Cx0001, Cx0002, Cx0003, Cx0004, Cx0005, Cx0006, Cx0007,
Cx0008, Cx0009, Cx000A, Cx000B, Cx000C, Cx000D, Cx000E, Cx000F, Cx0008, Cx0009, Cx000A, Cx000B, Cx000C, Cx000D, Cx000E, Cx000F,
Cx0010, Cx0011, Cx0012, Cx0013, Cx0014, Cx001A, Cx0020, Cx0100, Cx0010, Cx0011, Cx0012, Cx0013, Cx0014, Cx001A, Cx0020, Cx0100,
Cx0101, Cx0102, Cx0300, Cx0400, Cx0401, Cx0402, Cx0403, Cx0404, Cx0101, Cx0102, Cx0300, Cx0400, Cx0401, Cx0402, Cx0403, Cx0404,
Cx0405, Cx0406, Cx0B01, Cx0B05, Cx0405, Cx0406, Cx0B01, Cx0B05,
@ -582,14 +582,14 @@ enum Cx_cluster_short {
const uint16_t Cx_cluster[] PROGMEM = { const uint16_t Cx_cluster[] PROGMEM = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x001A, 0x0020, 0x0100, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x001A, 0x0020, 0x0100,
0x0101, 0x0102, 0x0300, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0101, 0x0102, 0x0300, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404,
0x0405, 0x0406, 0x0B01, 0x0B05, 0x0405, 0x0406, 0x0B01, 0x0B05,
}; };
uint16_t CxToCluster(uint8_t cx) { uint16_t CxToCluster(uint8_t cx) {
if (cx < sizeof(Cx_cluster)/sizeof(Cx_cluster[0])) { if (cx < ARRAY_SIZE(Cx_cluster)) {
return pgm_read_word(&Cx_cluster[cx]); return pgm_read_word(&Cx_cluster[cx]);
} }
return 0xFFFF; return 0xFFFF;
@ -909,7 +909,7 @@ const Z_AttributeConverter Z_PostProcess[] PROGMEM = {
{ Zuint16, Cx0101, 0x0503, Z(AqaraVibrationsOrAngle), &Z_Copy }, { Zuint16, Cx0101, 0x0503, Z(AqaraVibrationsOrAngle), &Z_Copy },
{ Zuint32, Cx0101, 0x0505, Z(AqaraVibration505), &Z_Copy }, { Zuint32, Cx0101, 0x0505, Z(AqaraVibration505), &Z_Copy },
{ Zuint48, Cx0101, 0x0508, Z(AqaraAccelerometer), &Z_AqaraVibration }, { Zuint48, Cx0101, 0x0508, Z(AqaraAccelerometer), &Z_AqaraVibration },
// Window Covering cluster // Window Covering cluster
{ Zenum8, Cx0102, 0x0000, Z(WindowCoveringType), &Z_Copy }, { Zenum8, Cx0102, 0x0000, Z(WindowCoveringType), &Z_Copy },
{ Zuint16, Cx0102, 0x0001, Z(PhysicalClosedLimitLift),&Z_Copy }, { Zuint16, Cx0102, 0x0001, Z(PhysicalClosedLimitLift),&Z_Copy },
@ -975,7 +975,7 @@ const Z_AttributeConverter Z_PostProcess[] PROGMEM = {
// Illuminance Level Sensing cluster // Illuminance Level Sensing cluster
{ Zenum8, Cx0401, 0x0000, Z(IlluminanceLevelStatus), &Z_Copy }, // Illuminance (in Lux) { Zenum8, Cx0401, 0x0000, Z(IlluminanceLevelStatus), &Z_Copy }, // Illuminance (in Lux)
{ Zenum8, Cx0401, 0x0001, Z(IlluminanceLightSensorType), &Z_Copy }, // LightSensorType { Zenum8, Cx0401, 0x0001, Z(IlluminanceLightSensorType), &Z_Copy }, // LightSensorType
{ Zuint16, Cx0401, 0x0010, Z(IlluminanceTargetLevel), &Z_Copy }, // { Zuint16, Cx0401, 0x0010, Z(IlluminanceTargetLevel), &Z_Copy }, //
{ Zunk, Cx0401, 0xFFFF, nullptr, &Z_Remove }, // Remove all other values { Zunk, Cx0401, 0xFFFF, nullptr, &Z_Remove }, // Remove all other values
// Temperature Measurement cluster // Temperature Measurement cluster

View File

@ -420,7 +420,7 @@ ZI_SEND(ZBS_STARTUPFROMAPP) // start coordinator
ZI_SEND(ZBS_PERMITJOINREQ_CLOSE) // Closing the Permit Join ZI_SEND(ZBS_PERMITJOINREQ_CLOSE) // Closing the Permit Join
ZI_WAIT_RECV(1000, ZBR_PERMITJOINREQ) ZI_WAIT_RECV(1000, ZBR_PERMITJOINREQ)
ZI_WAIT_UNTIL(1000, ZBR_PERMITJOIN_AREQ_RSP) ZI_WAIT_UNTIL(1000, ZBR_PERMITJOIN_AREQ_RSP)
ZI_LABEL(ZIGBEE_LABEL_READY) ZI_LABEL(ZIGBEE_LABEL_READY)
ZI_MQTT_STATE(ZIGBEE_STATUS_OK, kStarted) ZI_MQTT_STATE(ZIGBEE_STATUS_OK, kStarted)
ZI_LOG(LOG_LEVEL_INFO, kZigbeeStarted) ZI_LOG(LOG_LEVEL_INFO, kZigbeeStarted)
@ -491,7 +491,7 @@ void ZigbeeGotoLabel(uint8_t label) {
uint8_t cur_d8 = 0; uint8_t cur_d8 = 0;
uint8_t cur_instr_len = 1; // size of current instruction in words uint8_t cur_instr_len = 1; // size of current instruction in words
for (uint32_t i = 0; i < sizeof(zb_prog)/sizeof(zb_prog[0]); i += cur_instr_len) { for (uint32_t i = 0; i < ARRAY_SIZE(zb_prog); i += cur_instr_len) {
const Zigbee_Instruction *cur_instr_line = &zb_prog[i]; const Zigbee_Instruction *cur_instr_line = &zb_prog[i];
cur_instr = pgm_read_byte(&cur_instr_line->i.i); cur_instr = pgm_read_byte(&cur_instr_line->i.i);
cur_d8 = pgm_read_byte(&cur_instr_line->i.d8); cur_d8 = pgm_read_byte(&cur_instr_line->i.d8);
@ -550,7 +550,7 @@ void ZigbeeStateMachine_Run(void) {
zigbee.recv_until = false; zigbee.recv_until = false;
zigbee.state_no_timeout = false; // reset the no_timeout for next instruction zigbee.state_no_timeout = false; // reset the no_timeout for next instruction
if (zigbee.pc > (sizeof(zb_prog)/sizeof(zb_prog[0]))) { if (zigbee.pc > ARRAY_SIZE(zb_prog)) {
AddLog_P2(LOG_LEVEL_ERROR, PSTR(D_LOG_ZIGBEE "Invalid pc: %d, aborting"), zigbee.pc); AddLog_P2(LOG_LEVEL_ERROR, PSTR(D_LOG_ZIGBEE "Invalid pc: %d, aborting"), zigbee.pc);
zigbee.pc = -1; zigbee.pc = -1;
} }