Working on fixing motor commands

This commit is contained in:
Peter Slattery 2021-04-12 21:21:47 -04:00
parent 00a4cb5e39
commit e4d9a389c3
3 changed files with 45 additions and 6 deletions

View File

@ -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);

View File

@ -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];

View File

@ -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