From 747a2debf292fc466fea30e6c22b616989653392 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Sun, 26 Sep 2021 17:25:47 -0400 Subject: [PATCH] removing false check --- src/app/ss_blumen_lumen/blumen_lumen.cpp | 40 +++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index 5b0ea40..c3f0af5 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -706,7 +706,45 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) else if (MotorPos == MotorState_Closed || MotorPos == MotorState_HalfOpen) { - BLState->ShouldDimUpperLeds[i] = false; + bool SendMotorCommand = false; + + u64 NanosSinceLastSend = Context->SystemTime_Current.NanosSinceEpoch - BLState->LastSendTime.NanosSinceEpoch; + r32 SecondsSinceLastSend = (r64)NanosSinceLastSend * NanosToSeconds; + bool ShouldSendCurrentState = SecondsSinceLastSend >= MotorResendStatePeriod; + + bl_motor_state_value NewMotorState = MotorState_Closed; + bool SendOpen = false; + for (u32 i = 0; i < MotorOpenTimesCount; i++) + { + time_range Range = MotorOpenTimes[i]; + bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range); + if (CurrTimeInRange) { + NewMotorState = MotorState_Open; + } + } + + + if (NewMotorState != BLState->LastSendState) + { + ShouldSendCurrentState = true; + } + + + if (ShouldSendCurrentState) + { + BLState->LastSendTime = Context->SystemTime_Current; + BLState->LastSendState = NewMotorState; + + blumen_packet Packet = {}; + Packet.Type = PacketType_MotorState; + Packet.MotorPacket.FlowerPositions[0] = NewMotorState; + Packet.MotorPacket.FlowerPositions[1] = NewMotorState; + Packet.MotorPacket.FlowerPositions[2] = NewMotorState; + gs_data Msg = StructToData(&Packet, blumen_packet); + MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg); + + DEBUG_SentMotorCommand(Packet.MotorPacket, Context->ThreadContext); + } } }