Fixed motor time of day functionality
This commit is contained in:
parent
e4d9a389c3
commit
40f3a9f817
|
@ -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=-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
|
SET CommonLinkerFlags= -opt:ref -incremental:no
|
||||||
|
|
||||||
|
|
|
@ -486,9 +486,6 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
|
||||||
|
|
||||||
gs_string DebugStr = PushString(State->Transient, 256);
|
gs_string DebugStr = PushString(State->Transient, 256);
|
||||||
|
|
||||||
bool SendMotorCommand = false;
|
|
||||||
blumen_packet MotorCommand = {};
|
|
||||||
|
|
||||||
while (MessageQueue_CanRead(BLState->IncomingMsgQueue))
|
while (MessageQueue_CanRead(BLState->IncomingMsgQueue))
|
||||||
{
|
{
|
||||||
gs_data PacketData = MessageQueue_Read(&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) &&
|
if (MessageQueue_CanWrite(BLState->OutgoingMsgQueue) &&
|
||||||
!BLState->IgnoreTimeOfDay_MotorState)
|
!BLState->IgnoreTimeOfDay_MotorState)
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
bool SendOpen = false;
|
bool SendOpen = false;
|
||||||
for (u32 i = 0; i < MotorOpenTimesCount; i++)
|
for (u32 i = 0; i < MotorOpenTimesCount; i++)
|
||||||
{
|
{
|
||||||
time_range Range = MotorOpenTimes[i];
|
time_range Range = MotorOpenTimes[i];
|
||||||
|
|
||||||
bool CurrTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Current, Range);
|
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) {
|
if (CurrTimeInRange) {
|
||||||
SendOpen = true;
|
NewMotorState = MotorState_Open;
|
||||||
// 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 (NewMotorState != BLState->LastSendState)
|
||||||
|
{
|
||||||
|
ShouldSendCurrentState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShouldSendCurrentState)
|
if (ShouldSendCurrentState)
|
||||||
{
|
{
|
||||||
|
BLState->LastSendTime = Context->SystemTime_Current;
|
||||||
|
BLState->LastSendState = NewMotorState;
|
||||||
|
|
||||||
if (SendOpen)
|
blumen_packet Packet = {};
|
||||||
{
|
Packet.Type = PacketType_MotorState;
|
||||||
BLState->LastSendTime = Context->SystemTime_Current;
|
Packet.MotorPacket.FlowerPositions[0] = NewMotorState;
|
||||||
BLState->LastSendState = MotorState_Open;
|
Packet.MotorPacket.FlowerPositions[1] = NewMotorState;
|
||||||
OutputDebugString("Motors: Open\n");
|
Packet.MotorPacket.FlowerPositions[2] = NewMotorState;
|
||||||
|
|
||||||
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);
|
gs_data Msg = StructToData(&Packet, blumen_packet);
|
||||||
MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg);
|
MessageQueue_Write(&BLState->OutgoingMsgQueue, Msg);
|
||||||
DEBUG_SentMotorCommand(MotorCommand.MotorPacket, Context->ThreadContext);
|
DEBUG_SentMotorCommand(Packet.MotorPacket, Context->ThreadContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,10 +137,23 @@ typedef struct time_range
|
||||||
internal bool
|
internal bool
|
||||||
SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
|
SystemTimeIsInTimeRange(system_time SysTime, time_range Range)
|
||||||
{
|
{
|
||||||
bool Result = (SysTime.Hour >= Range.StartHour &&
|
bool Result = false;
|
||||||
SysTime.Minute >= Range.StartMinute &&
|
if (SysTime.Hour >= Range.StartHour &&
|
||||||
SysTime.Hour <= Range.EndHour &&
|
SysTime.Hour <= Range.EndHour)
|
||||||
SysTime.Minute <= Range.EndMinute);
|
{
|
||||||
|
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;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue