diff --git a/src/cmnds/cmd_eventHandlers.c b/src/cmnds/cmd_eventHandlers.c index 0bccf9c63..56e19a551 100644 --- a/src/cmnds/cmd_eventHandlers.c +++ b/src/cmnds/cmd_eventHandlers.c @@ -376,8 +376,9 @@ void EventHandlers_FireEvent3(byte eventCode, int argument, int argument2, int a ev = ev->next; } } -void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) { +int EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) { struct eventHandler_s *ev; + int ret = 0; ev = g_eventHandlers; @@ -386,10 +387,12 @@ void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) { if(argument == ev->requiredArgument && argument2 == ev->requiredArgument2) { ADDLOG_INFO(LOG_FEATURE_EVENT, "EventHandlers_FireEvent2: executing command %s",ev->command); CMD_ExecuteCommand(ev->command, COMMAND_FLAG_SOURCE_SCRIPT); + ret++; } } ev = ev->next; } + return ret; } diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index 9e2b54cd0..593c7deca 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -233,7 +233,7 @@ 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); -void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2); +int EventHandlers_FireEvent2(byte eventCode, int argument, int argument2); void EventHandlers_FireEvent3(byte eventCode, int argument, int argument2, int argument3); // 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. diff --git a/src/selftest/selftest_cmd_startup.c b/src/selftest/selftest_cmd_startup.c index f44e8ded5..f9528098e 100644 --- a/src/selftest/selftest_cmd_startup.c +++ b/src/selftest/selftest_cmd_startup.c @@ -42,6 +42,21 @@ void Test_Commands_Startup() { CFG_SetShortStartupCommand(loremIpsum3); CMD_ExecuteCommand(CFG_GetShortStartupCommand(), 0); + SIM_ShutdownOBK(); + const char *t = "startDriver IR\n" + "setFlag 1 1\n" + "addEventHandler2 IR_NEC 0xC7EA 0x17 backlog IRSend NEC 0x0 0xA8; IRSend NEC 0x0 0xA8; IRSend NEC 0x0 0xA8\n" + "addEventHandler2 IR_NEC 0xC7EA 0xF backlog IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C\n" + "addEventHandler2 IR_NEC 0xC7EA 0x10 backlog IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C\n"; + + CFG_SetShortStartupCommand(t); + CFG_Save_IfThereArePendingChanges(); + // NOTE: THIS WILL RUN STARTUP COMMAND!!!! + SIM_StartOBK(0); + + SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0x17)); + SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0xF)); + SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0x10)); } diff --git a/src/sim/sim_import.h b/src/sim/sim_import.h index b307d7a82..1022260ff 100644 --- a/src/sim/sim_import.h +++ b/src/sim/sim_import.h @@ -19,6 +19,8 @@ extern "C" { void SIM_SetupNewFlashFile(const char *flashPath); void SIM_SetupEmptyFlashModeNoFile(); void SIM_ClearOBK(const char *flashPath); + void SIM_ShutdownOBK(); + void SIM_StartOBK(const char *flashPath); bool SIM_IsFlashModified(); float SIM_GetDeltaTimeSeconds(); #ifdef __cplusplus diff --git a/src/win_main.c b/src/win_main.c index 658304516..7b672afd2 100644 --- a/src/win_main.c +++ b/src/win_main.c @@ -140,12 +140,14 @@ void SIM_Hack_ClearSimulatedPinRoles(); void CHANNEL_FreeLabels(); -void SIM_ClearOBK(const char *flashPath) { +void SIM_ShutdownOBK() { if (bObkStarted) { DRV_ShutdownAllDrivers(); #if ENABLE_LITTLEFS release_lfs(); #endif + SVM_FreeAllFiles(); + SVM_StopAllScripts(); SIM_Hack_ClearSimulatedPinRoles(); WIN_ResetMQTT(); SPILED_Shutdown(); // won't hurt @@ -159,12 +161,19 @@ void SIM_ClearOBK(const char *flashPath) { // LOG deinit after main init so commands will be re-added LOG_DeInit(); } +} +void SIM_StartOBK(const char *flashPath) { + if (flashPath) { SIM_SetupFlashFileReading(flashPath); } bObkStarted = true; Main_Init(); } +void SIM_ClearOBK(const char *flashPath) { + SIM_ShutdownOBK(); + SIM_StartOBK(flashPath); +} void Win_DoUnitTests() { //SELFTEST_ASSERT_EXPRESSION("sqrt(4)", 2)