diff --git a/build/build_app_msvc_win32_debug.bat b/build/build_app_msvc_win32_debug.bat index eec2df0..7494131 100644 --- a/build/build_app_msvc_win32_debug.bat +++ b/build/build_app_msvc_win32_debug.bat @@ -8,7 +8,7 @@ call %MyPath%\setup_cl.bat SET CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except- -IC:\programs-dev\gs_libs\src -SET CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -I%CommonLibs% -O2 %CommonCompilerFlags% +SET CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -I%CommonLibs% -Od %CommonCompilerFlags% SET CommonLinkerFlags= -opt:ref -incremental:no diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index bbc7fe1..fc21fa3 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -486,9 +486,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) gs_string DebugStr = PushString(State->Transient, 256); - bool SendMotorCommand = false; - blumen_packet MotorCommand = {}; - while (MessageQueue_CanRead(BLState->IncomingMsgQueue)) { gs_data PacketData = MessageQueue_Read(&BLState->IncomingMsgQueue); @@ -624,101 +621,42 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) if (MessageQueue_CanWrite(BLState->OutgoingMsgQueue) && !BLState->IgnoreTimeOfDay_MotorState) { + 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); - - bool LastSendTimeInRange = SystemTimeIsInTimeRange(BLState->LastSendTime, Range); - - bool LastTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Last, Range); - -#if 0 - bool SendOpen = CurrTimeInRange && !LastSendTimeInRange; - bool SendClose = !CurrTimeInRange && LastSendTimeInRange; - //SendOpen = SecondsSinceLastSend > 2; - if (SendOpen) - { - SendMotorCommand = true; - - BLState->LastSendTime = Context->SystemTime_Current; - 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; - break; - } - else if (SendClose) - { - SendMotorCommand = true; - BLState->LastSendTime = Context->SystemTime_Current; - 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; - 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; + NewMotorState = MotorState_Open; } -#endif + } + + if (NewMotorState != BLState->LastSendState) + { + ShouldSendCurrentState = true; } if (ShouldSendCurrentState) { + BLState->LastSendTime = Context->SystemTime_Current; + BLState->LastSendState = NewMotorState; - 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; - } + 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(&MotorCommand, blumen_packet); + gs_data Msg = StructToData(&Packet, blumen_packet); MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg); - DEBUG_SentMotorCommand(MotorCommand.MotorPacket, Context->ThreadContext); + DEBUG_SentMotorCommand(Packet.MotorPacket, Context->ThreadContext); } } diff --git a/src/app/ss_blumen_lumen/blumen_lumen.h b/src/app/ss_blumen_lumen/blumen_lumen.h index e05d83a..c5822a8 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.h +++ b/src/app/ss_blumen_lumen/blumen_lumen.h @@ -137,10 +137,23 @@ typedef struct time_range internal bool SystemTimeIsInTimeRange(system_time SysTime, time_range Range) { - bool Result = (SysTime.Hour >= Range.StartHour && - SysTime.Minute >= Range.StartMinute && - SysTime.Hour <= Range.EndHour && - SysTime.Minute <= Range.EndMinute); + bool Result = false; + if (SysTime.Hour >= Range.StartHour && + SysTime.Hour <= Range.EndHour) + { + if (SysTime.Hour == Range.StartHour) + { + Result = (SysTime.Minute >= Range.StartMinute); + } + else if (SysTime.Hour == Range.EndHour) + { + Result = (SysTime.Minute <= Range.EndMinute); + } + else + { + Result = true; + } + } return Result; }