Rapid Fire: The Dubuque Protocol now uses a 100ms holdoff! #6

Merged
Joe merged 1 commit from holdoff_reduction into main 2025-09-20 19:10:18 +00:00
Showing only changes of commit 00406b7ddc - Show all commits

View file

@ -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;
@ -70,6 +71,7 @@ static void Playing__Interacting_Entry(StateMachineContext_T * context)
*/
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);