Skip to content

Commit

Permalink
fixes, debug, add an ability to fire event on UART string receive
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Oct 16, 2022
1 parent f699c57 commit 22f65b8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/cmnds/cmd_eventHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ void EventHandlers_FireEvent_String(byte eventCode, const char *argument) {

while(ev) {
if(eventCode==ev->eventCode) {
if(argument == ev->requiredArgument) {
ADDLOG_INFO(LOG_FEATURE_EVENT, "EventHandlers_ProcessVariableChange_Integer: executing command %s",ev->command);
CMD_ExecuteCommand(ev->command, COMMAND_FLAG_SOURCE_SCRIPT);
if(ev->requiredArgumentText != 0) {
if(!stricmp(argument,ev->requiredArgumentText)) {
ADDLOG_INFO(LOG_FEATURE_EVENT, "EventHandlers_FireEvent_String: executing command %s",ev->command);
CMD_ExecuteCommand(ev->command, COMMAND_FLAG_SOURCE_SCRIPT);
}
}
}
ev = ev->next;
Expand Down
6 changes: 6 additions & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ void RepeatingEvents_Init();
void RepeatingEvents_OnEverySecond();
// cmd_eventHandlers.c
void EventHandlers_Init();
// This is useful to fire an event when a certain UART string command is received.
// For example, you can fire an event while getting 55 AA 01 02 00 03 FF 01 01 06 on UART..
void EventHandlers_FireEvent_String(byte eventCode, const char *argument);
// This is useful to fire an event when, for example, a button is pressed.
// Then eventCode is a BUTTON_PRESS and argument is a button index.
void EventHandlers_FireEvent(byte eventCode, int argument);
// This is more advanced event handler. It will only fire handlers when a variable state changes from one to another.
// For example, you can watch for Voltage from BL0942 to change below 230, and it will fire event only when it becomes below 230.
void EventHandlers_ProcessVariableChange_Integer(byte eventCode, int oldValue, int newValue);
// cmd_tasmota.c
int taslike_commands_init();
Expand Down
35 changes: 34 additions & 1 deletion src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,28 @@ void TuyaMCU_ProcessIncoming(const byte *data, int len) {
else if (checkLen == 2)
{
self_processing_mode = false;
}
}
else
{
int dataCount;
// https://github.com/openshwprojects/OpenBK7231T_App/issues/291
// header ver TUYA_CMD_MCU_CONF LENGHT Chksum
// Pushing
// 55 AA 01 02 00 03 FF 01 01 06
// 55 AA 01 02 00 03 FF 01 00 05
// Rotating down
// 55 AA 01 02 00 05 01 24 02 01 0A 39
// 55 AA 01 02 00 03 01 09 00 0F
// Rotating up
// 55 AA 01 02 00 05 01 24 01 01 0A 38
// 55 AA 01 02 00 03 01 09 01 10
dataCount = data[5];
if(5 + dataCount + 1 != len) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF had wrong data lenght?");
} else {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!");
}
}
break;
case TUYA_CMD_WIFI_STATE:
wifi_state_valid = true;
Expand Down Expand Up @@ -974,6 +995,18 @@ void TuyaMCU_RunFrame() {
strcat_safe(buffer_for_log,buffer2,sizeof(buffer_for_log));
}
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"TUYAMCU received: %s\n", buffer_for_log);
#if 1
// redo sprintf without spaces
buffer_for_log[0] = 0;
for(i = 0; i < len; i++) {
sprintf(buffer2,"%02X",data[i]);
strcat_safe(buffer_for_log,buffer2,sizeof(buffer_for_log));
}
// fire string event, as we already have it sprintfed
// This is so we can have event handlers that fire
// when an UART string is received...
EventHandlers_FireEvent_String(CMD_EVENT_ON_UART,buffer_for_log);
#endif
TuyaMCU_ProcessIncoming(data,len);
} else {
break;
Expand Down

0 comments on commit 22f65b8

Please sign in to comment.