From 37c30e1cb21f7ddeb2adc0d4011b9161806510f0 Mon Sep 17 00:00:00 2001 From: PS Date: Fri, 9 Apr 2021 14:59:55 -1000 Subject: [PATCH] Lumenarium now repeatedly sends the current motor position desired based on a variable in settings --- src/app/ss_blumen_lumen/blumen_lumen.cpp | 12 +++++++++++- src/app/ss_blumen_lumen/blumen_lumen_settings.h | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/ss_blumen_lumen/blumen_lumen.cpp b/src/app/ss_blumen_lumen/blumen_lumen.cpp index b36653c..1a91994 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen.cpp +++ b/src/app/ss_blumen_lumen/blumen_lumen.cpp @@ -616,6 +616,10 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) if (MessageQueue_CanWrite(BLState->OutgoingMsgQueue) && !BLState->IgnoreTimeOfDay_MotorState) { + u64 NanosSinceLastSend = Context->SystemTime_Current.NanosSinceEpoch - BLState->LastSendTime.NanosSinceEpoch; + r32 SecondsSinceLastSend = (r64)NanosSinceLastSend * NanosToSeconds; + bool ShouldSendCurrentState = SecondsSinceLastSend >= MotorResendStatePeriod; + for (u32 i = 0; i < MotorOpenTimesCount; i++) { time_range Range = MotorOpenTimes[i]; @@ -626,9 +630,13 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) bool LastTimeInRange = SystemTimeIsInTimeRange(Context->SystemTime_Last, Range); +#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) { @@ -643,6 +651,7 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) Packet.MotorPacket.FlowerPositions[1] = 2; Packet.MotorPacket.FlowerPositions[2] = 2; MotorCommand = Packet; + break; } else if (SendClose) { @@ -656,6 +665,7 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context) Packet.MotorPacket.FlowerPositions[1] = 1; Packet.MotorPacket.FlowerPositions[2] = 1; MotorCommand = Packet; + break; } } diff --git a/src/app/ss_blumen_lumen/blumen_lumen_settings.h b/src/app/ss_blumen_lumen/blumen_lumen_settings.h index b33a224..a55ce1b 100644 --- a/src/app/ss_blumen_lumen/blumen_lumen_settings.h +++ b/src/app/ss_blumen_lumen/blumen_lumen_settings.h @@ -41,6 +41,11 @@ global time_range MotorOpenTimes[] = { }; global u32 MotorOpenTimesCount = CArrayLength(MotorOpenTimes); // do not edit +// Lumenarium repeatedly resends the current motor state to the python +// server. This variable determines how much time elapses between each +// message. +global r32 MotorResendStatePeriod = 90.0f; // seconds + // The times of day when the leds should be on // Search for @TimeFormat to find documentation global time_range LedOnTimes[] = {