IR LEDs using the Dubuque Protocol can survive with a 100ms holdoff.

This commit is contained in:
Joe Kearney 2025-09-20 13:45:26 -05:00
parent 430aec54b8
commit 00406b7ddc

View file

@ -39,6 +39,7 @@ const StateActivity_T STATE_PLAYING__INTERACTING_Activities =
}; };
static TickType_t Time_Of_Last_Shot = 0; 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 FIXED_SHOT_HOLDOFF_in_ms = 3000;
static const uint32_t RANDOM_SHOT_HOLDOFF_in_ms = 1000; static const uint32_t RANDOM_SHOT_HOLDOFF_in_ms = 1000;
static TickType_t Shot_Holdoff_Time; static TickType_t Shot_Holdoff_Time;
@ -70,6 +71,7 @@ static void Playing__Interacting_Entry(StateMachineContext_T * context)
*/ */
static void Playing__Interacting_Do(StateMachineContext_T * context) static void Playing__Interacting_Do(StateMachineContext_T * context)
{ {
static Protocol_T Protocol_Of_Last_Sent_Tag = UNKNOWN_PROTOCOL;
portBASE_TYPE xStatus; portBASE_TYPE xStatus;
static KEvent_T Event; 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 }; KEvent_T misfire_event = { .ID = KEVENT_MISFIRE, .Data = (void *)0x00 };
Post_KEvent(&misfire_event); 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 else
{ {
@ -198,9 +213,19 @@ static void Playing__Interacting_Do(StateMachineContext_T * context)
case KEVENT_TAG_SENT: case KEVENT_TAG_SENT:
{ {
// "Flip ya'? Double or nuthin'!" // Calculate the shot holdoff time:
uint32_t holdoff_in_ms = (rand() % 2) * RANDOM_SHOT_HOLDOFF_in_ms; // - The Dubuque Protocol uses a very small holdoff time to protect the IR lEDs from heat damage.
holdoff_in_ms += FIXED_SHOT_HOLDOFF_in_ms; // - 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); Shot_Holdoff_Time = (holdoff_in_ms / portTICK_PERIOD_MS);
#ifdef LOG_INTERACTING_SUBSTATE #ifdef LOG_INTERACTING_SUBSTATE
KLOG_INFO(KLOG_TAG, "Tag sent. Holdoff: %lu ms", holdoff_in_ms); KLOG_INFO(KLOG_TAG, "Tag sent. Holdoff: %lu ms", holdoff_in_ms);