From 00406b7ddcce01369744e40b3c6e0b9ef992c5e7 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 20 Sep 2025 13:45:26 -0500 Subject: [PATCH] IR LEDs using the Dubuque Protocol can survive with a 100ms holdoff. --- States/Playing/State_Playing__Interacting.c | 33 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/States/Playing/State_Playing__Interacting.c b/States/Playing/State_Playing__Interacting.c index 767d644..4dc017c 100644 --- a/States/Playing/State_Playing__Interacting.c +++ b/States/Playing/State_Playing__Interacting.c @@ -39,6 +39,7 @@ const StateActivity_T STATE_PLAYING__INTERACTING_Activities = }; static TickType_t Time_Of_Last_Shot = 0; +static const uint32_t DUBUQUE_PROTOCOL_HOLDOFF_in_ms = 100; static const uint32_t FIXED_SHOT_HOLDOFF_in_ms = 3000; static const uint32_t RANDOM_SHOT_HOLDOFF_in_ms = 1000; static TickType_t Shot_Holdoff_Time; @@ -69,7 +70,8 @@ static void Playing__Interacting_Entry(StateMachineContext_T * context) * \param context Context in which this substate is being run. */ static void Playing__Interacting_Do(StateMachineContext_T * context) -{ +{ + static Protocol_T Protocol_Of_Last_Sent_Tag = UNKNOWN_PROTOCOL; portBASE_TYPE xStatus; static KEvent_T Event; @@ -92,6 +94,19 @@ static void Playing__Interacting_Do(StateMachineContext_T * context) KEvent_T misfire_event = { .ID = KEVENT_MISFIRE, .Data = (void *)0x00 }; Post_KEvent(&misfire_event); } + else + { + uint8_t weapon_ID; + if (SETTINGS_get_uint8_t(SYSTEMK_SETTING_WEAPONID, &weapon_ID) != SYSTEMK_RESULT_SUCCESS) + { + KLOG_ERROR(KLOG_TAG, "Error reading weapon ID from settings!"); + } + else + { + Weapon_t weapon = GetWeaponFromID(weapon_ID); + Protocol_Of_Last_Sent_Tag = weapon.Protocol; + } + } } else { @@ -198,9 +213,19 @@ static void Playing__Interacting_Do(StateMachineContext_T * context) case KEVENT_TAG_SENT: { - // "Flip ya'? Double or nuthin'!" - uint32_t holdoff_in_ms = (rand() % 2) * RANDOM_SHOT_HOLDOFF_in_ms; - holdoff_in_ms += FIXED_SHOT_HOLDOFF_in_ms; + // Calculate the shot holdoff time: + // - The Dubuque Protocol uses a very small holdoff time to protect the IR lEDs from heat damage. + // - All the other protocols require this, plus an additional random holdoff to resolve duels. + uint32_t holdoff_in_ms = 0; + if (Protocol_Of_Last_Sent_Tag == DUBUQUE_PROTOCOL) + { + holdoff_in_ms = DUBUQUE_PROTOCOL_HOLDOFF_in_ms; + } + else + { + holdoff_in_ms = (rand() % 2) * RANDOM_SHOT_HOLDOFF_in_ms; + holdoff_in_ms += FIXED_SHOT_HOLDOFF_in_ms; + } Shot_Holdoff_Time = (holdoff_in_ms / portTICK_PERIOD_MS); #ifdef LOG_INTERACTING_SUBSTATE KLOG_INFO(KLOG_TAG, "Tag sent. Holdoff: %lu ms", holdoff_in_ms); -- 2.47.3