bug fixing

This commit is contained in:
PS 2021-09-26 16:31:55 -05:00
parent 747a2debf2
commit 9e474fe846
1 changed files with 35 additions and 36 deletions

View File

@ -706,45 +706,44 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
else if (MotorPos == MotorState_Closed || else if (MotorPos == MotorState_Closed ||
MotorPos == MotorState_HalfOpen) MotorPos == MotorState_HalfOpen)
{ {
bool SendMotorCommand = false; bool SendMotorCommand = false;
u64 NanosSinceLastSend = Context->SystemTime_Current.NanosSinceEpoch - BLState->LastSendTime.NanosSinceEpoch; u64 NanosSinceLastSend = Context->SystemTime_Current.NanosSinceEpoch - BLState->LastSendTime.NanosSinceEpoch;
r32 SecondsSinceLastSend = (r64)NanosSinceLastSend * NanosToSeconds; r32 SecondsSinceLastSend = (r64)NanosSinceLastSend * NanosToSeconds;
bool ShouldSendCurrentState = SecondsSinceLastSend >= MotorResendStatePeriod; bool ShouldSendCurrentState = SecondsSinceLastSend >= MotorResendStatePeriod;
bl_motor_state_value NewMotorState = MotorState_Closed; bl_motor_state_value NewMotorState = MotorState_Closed;
bool SendOpen = false; bool SendOpen = false;
for (u32 i = 0; i < MotorOpenTimesCount; i++) for (u32 j = 0; j < MotorOpenTimesCount; j++)
{ {
time_range Range = MotorOpenTimes[i]; time_range Range = MotorOpenTimes[j];
bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range); bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range);
if (CurrTimeInRange) { if (CurrTimeInRange) {
NewMotorState = MotorState_Open; NewMotorState = MotorState_Open;
}
} }
}
if (NewMotorState != BLState->LastSendState) if (NewMotorState != BLState->LastSendState)
{ {
ShouldSendCurrentState = true; ShouldSendCurrentState = true;
} }
if (ShouldSendCurrentState)
{
BLState->LastSendTime = Context->SystemTime_Current;
BLState->LastSendState = NewMotorState;
if (ShouldSendCurrentState) blumen_packet Packet = {};
{ Packet.Type = PacketType_MotorState;
BLState->LastSendTime = Context->SystemTime_Current; Packet.MotorPacket.FlowerPositions[0] = NewMotorState;
BLState->LastSendState = NewMotorState; Packet.MotorPacket.FlowerPositions[1] = NewMotorState;
Packet.MotorPacket.FlowerPositions[2] = NewMotorState;
gs_data Msg = StructToData(&Packet, blumen_packet);
MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg);
blumen_packet Packet = {}; DEBUG_SentMotorCommand(Packet.MotorPacket, Context->ThreadContext);
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);
}
} }
} }