Skip to content

Commit

Permalink
Set only first channel by type in VCP tuyaMCU (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
iglooom authored Dec 21, 2023
1 parent 429276a commit 0acb820
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,13 +1407,13 @@ void TuyaMCU_ParseStateMessage(const byte* data, int len) {
if (sectorLen == 8 || sectorLen == 10) {
// voltage
iVal = data[ofs + 0 + 4] << 8 | data[ofs + 1 + 4];
CHANNEL_SetAllChannelsByType(ChType_Voltage_div10, iVal);
CHANNEL_SetFirstChannelByType(ChType_Voltage_div10, iVal);
// current
iVal = data[ofs + 3 + 4] << 8 | data[ofs + 4 + 4];
CHANNEL_SetAllChannelsByType(ChType_Current_div1000, iVal);
CHANNEL_SetFirstChannelByType(ChType_Current_div1000, iVal);
// power
iVal = data[ofs + 6 + 4] << 8 | data[ofs + 7 + 4];
CHANNEL_SetAllChannelsByType(ChType_Power, iVal);
CHANNEL_SetFirstChannelByType(ChType_Power, iVal);
}
else {

Expand All @@ -1428,13 +1428,13 @@ void TuyaMCU_ParseStateMessage(const byte* data, int len) {
else {
// FREQ??
iVal = data[ofs + 8 + 4] << 8 | data[ofs + 9 + 4];
//CHANNEL_SetAllChannelsByType(QQQQQQ, iVal);
//CHANNEL_SetFirstChannelByType(QQQQQQ, iVal);
// 06 46 = 1606 => A x 100? ?
iVal = data[ofs + 11 + 4] << 8 | data[ofs + 12 + 4];
CHANNEL_SetAllChannelsByType(ChType_Current_div1000, iVal);
CHANNEL_SetFirstChannelByType(ChType_Current_div1000, iVal);
// Voltage?
iVal = data[ofs + 13 + 4] << 8 | data[ofs + 14 + 4];
CHANNEL_SetAllChannelsByType(ChType_Voltage_div10, iVal);
CHANNEL_SetFirstChannelByType(ChType_Voltage_div10, iVal);
}
}
break;
Expand Down
3 changes: 2 additions & 1 deletion src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,13 @@ void NEW_button_init(pinButton_s* handle, uint8_t(*pin_level)(void* self), uint8
handle->button_level = handle->hal_button_Level(handle);
handle->active_level = active_level;
}
void CHANNEL_SetAllChannelsByType(int requiredType, int newVal) {
void CHANNEL_SetFirstChannelByType(int requiredType, int newVal) {
int i;

for (i = 0; i < CHANNEL_MAX; i++) {
if (CHANNEL_GetType(i) == requiredType) {
CHANNEL_Set(i, newVal, 0);
return;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ bool CHANNEL_IsPowerRelayChannel(int ch);
// See: enum channelType_t
void CHANNEL_SetType(int ch, int type);
int CHANNEL_GetType(int ch);
void CHANNEL_SetAllChannelsByType(int requiredType, int newVal);
void CHANNEL_SetFirstChannelByType(int requiredType, int newVal);
// CHANNEL_SET_FLAG_*
void CHANNEL_SetAll(int iVal, int iFlags);
void CHANNEL_SetStateOnly(int iVal);
Expand Down

0 comments on commit 0acb820

Please sign in to comment.