From e4d9a389c317f8910cc5b132cd846e2568047a61 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Mon, 12 Apr 2021 21:21:47 -0400 Subject: [PATCH] Working on fixing motor commands --- src/app/ss_blumen_lumen/blumen_lumen.cpp | 47 +++++++++++++++++-- src/app/ss_blumen_lumen/blumen_lumen.h | 1 + .../ss_blumen_lumen/blumen_lumen_settings.h | 3 +- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index d711f23..bbc7fe1 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -628,6 +628,7 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) r32 SecondsSinceLastSend = (r64)NanosSinceLastSend * NanosToSeconds; bool ShouldSendCurrentState = SecondsSinceLastSend >= MotorResendStatePeriod; + bool SendOpen = false; for (u32 i = 0; i < MotorOpenTimesCount; i++) { time_range Range = MotorOpenTimes[i]; @@ -641,10 +642,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) #if 0 bool SendOpen = CurrTimeInRange && !LastSendTimeInRange; bool SendClose = !CurrTimeInRange && LastSendTimeInRange; -#else - bool SendOpen = CurrTimeInRange && ShouldSendCurrentState; - bool SendClose = !CurrTimeInRange && ShouldSendCurrentState; -#endif //SendOpen = SecondsSinceLastSend > 2; if (SendOpen) { @@ -675,10 +672,50 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) MotorCommand = Packet; break; } +#else + if (CurrTimeInRange) { + SendOpen = true; + // if the current state isn't what we want, we want to + // send immediately, rather than wait for the periodic time out + if (BLState->LastSendState != MotorState_Open) + { + ShouldSendCurrentState = true; + } + break; + } +#endif } - if (SendMotorCommand) + if (ShouldSendCurrentState) { + + if (SendOpen) + { + BLState->LastSendTime = Context->SystemTime_Current; + BLState->LastSendState = MotorState_Open; + OutputDebugString("Motors: Open\n"); + + blumen_packet Packet = {}; + Packet.Type = PacketType_MotorState; + Packet.MotorPacket.FlowerPositions[0] = 2; + Packet.MotorPacket.FlowerPositions[1] = 2; + Packet.MotorPacket.FlowerPositions[2] = 2; + MotorCommand = Packet; + } + else + { + BLState->LastSendTime = Context->SystemTime_Current; + BLState->LastSendState = MotorState_Closed; + OutputDebugString("Motors: Close\n"); + + blumen_packet Packet = {}; + Packet.Type = PacketType_MotorState; + Packet.MotorPacket.FlowerPositions[0] = 1; + Packet.MotorPacket.FlowerPositions[1] = 1; + Packet.MotorPacket.FlowerPositions[2] = 1; + MotorCommand = Packet; + } + gs_data Msg = StructToData(&MotorCommand, blumen_packet); MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg); DEBUG_SentMotorCommand(MotorCommand.MotorPacket, Context->ThreadContext); diff --git a/src/app/ss_blumen_lumen/blumen_lumen.h b/src/app/ss_blumen_lumen/blumen_lumen.h index db52256..e05d83a 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.h +++ b/src/app/ss_blumen_lumen/blumen_lumen.h @@ -171,6 +171,7 @@ struct blumen_lumen_state system_time LastStatusUpdateTime; system_time LastSendTime; + bl_motor_state_value LastSendState; phrase_hue StandardPatternHues; r32 AssemblyColorsTransitionTimeLeft[BL_FLOWER_COUNT]; diff --git a/src/app/ss_blumen_lumen/blumen_lumen_settings.h b/src/app/ss_blumen_lumen/blumen_lumen_settings.h index 184df19..2c4858c 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen_settings.h +++ b/src/app/ss_blumen_lumen/blumen_lumen_settings.h @@ -38,7 +38,8 @@ gs_const_string VoicePatternFolder = ConstString("data/blumen_animations/audio_r global time_range MotorOpenTimes[] = { { 8, 00, 12, 00 }, { 12, 30, 13, 00 }, - { 18, 00, 22, 00 }, // 7:00pm to 11:00pm + { 18, 00, 22, 00 }, // 6:00pm to 10:00pm + { 23, 05, 23, 53 }, }; global u32 MotorOpenTimesCount = CArrayLength(MotorOpenTimes); // do not edit