Better feedback (lights and sounds) for reentry #4
2 changed files with 93 additions and 5 deletions
|
@ -23,7 +23,10 @@
|
||||||
|
|
||||||
static color_t All_On_Color = COLOR_WHITE;
|
static color_t All_On_Color = COLOR_WHITE;
|
||||||
static DisplayStyle_T All_On_Style = DISPLAY_STYLE_DEFAULT;
|
static DisplayStyle_T All_On_Style = DISPLAY_STYLE_DEFAULT;
|
||||||
static uint32_t Time_in_Animation_in_ms = 0;
|
static uint8_t Heartbeat_Phase = 0;
|
||||||
|
static const uint8_t MIN_HEARTBEAT_BRIGHTNESS = 50;
|
||||||
|
|
||||||
|
static uint16_t Time_in_Animation_in_ms = 0;
|
||||||
|
|
||||||
static void Reset(void *Data)
|
static void Reset(void *Data)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +96,29 @@ static AnimationStepResult_T NextStep(void)
|
||||||
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
|
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (All_On_Style == DISPLAY_STYLE_BLINK)
|
||||||
|
{
|
||||||
|
if ((Time_in_Animation_in_ms % 200) < 100)
|
||||||
|
{
|
||||||
|
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, All_On_Color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, COLOR_BLACK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (All_On_Style == DISPLAY_STYLE_HEARTBEAT)
|
||||||
|
{
|
||||||
|
uint8_t Brightness = Sine8[Heartbeat_Phase];
|
||||||
|
Heartbeat_Phase += 2;
|
||||||
|
|
||||||
|
if (Brightness < MIN_HEARTBEAT_BRIGHTNESS)
|
||||||
|
{
|
||||||
|
Brightness = MIN_HEARTBEAT_BRIGHTNESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(All_On_Color, Brightness));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, All_On_Color);
|
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, All_On_Color);
|
||||||
|
|
|
@ -24,6 +24,37 @@
|
||||||
|
|
||||||
static const char *KLOG_TAG = "STATE_PLAYING__TAGGED_OUT";
|
static const char *KLOG_TAG = "STATE_PLAYING__TAGGED_OUT";
|
||||||
|
|
||||||
|
static TimerHandle_t TriggerLongPressTimer = NULL;
|
||||||
|
static StaticTimer_t xTriggerLongPressTimerBuffer;
|
||||||
|
static TickType_t xTriggerLongPressTimerPeriod = (1000 / portTICK_PERIOD_MS);
|
||||||
|
static uint_fast8_t SecondsUntilReentry = 6;
|
||||||
|
|
||||||
|
static void TriggerLongPressTimerCallback(TimerHandle_t xTimer)
|
||||||
|
{
|
||||||
|
SecondsUntilReentry--;
|
||||||
|
|
||||||
|
if (SecondsUntilReentry == 0)
|
||||||
|
{
|
||||||
|
static All_On_Data_T data;
|
||||||
|
data.color = ApplyMask(COLOR_GREEN, 0x70);
|
||||||
|
data.style = DISPLAY_STYLE_HEARTBEAT;
|
||||||
|
|
||||||
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_ON, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&data};
|
||||||
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (xTimerStart(TriggerLongPressTimer, 0) != pdPASS)
|
||||||
|
{
|
||||||
|
KLOG_ERROR(KLOG_TAG, "Couldn't start the TriggerLongPressTimer!");
|
||||||
|
}
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Reset_Bombs()
|
static void Reset_Bombs()
|
||||||
{
|
{
|
||||||
uint8_t n_bombs;
|
uint8_t n_bombs;
|
||||||
|
@ -70,6 +101,24 @@ static void Playing__Tagged_Out_Entry(StateMachineContext_T * context)
|
||||||
BLE_UpdateStatusPacket(STATE_PLAYING__TAGGED_OUT);
|
BLE_UpdateStatusPacket(STATE_PLAYING__TAGGED_OUT);
|
||||||
|
|
||||||
Increment_Times_Tagged_Out();
|
Increment_Times_Tagged_Out();
|
||||||
|
|
||||||
|
SecondsUntilReentry = 6;
|
||||||
|
|
||||||
|
if (TriggerLongPressTimer == NULL)
|
||||||
|
{
|
||||||
|
TriggerLongPressTimer = xTimerCreateStatic(
|
||||||
|
"TaggedOutTriggerLongPress",
|
||||||
|
xTriggerLongPressTimerPeriod,
|
||||||
|
pdFALSE,
|
||||||
|
(void *)0,
|
||||||
|
TriggerLongPressTimerCallback,
|
||||||
|
&xTriggerLongPressTimerBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TriggerLongPressTimer == NULL)
|
||||||
|
{
|
||||||
|
KLOG_ERROR(KLOG_TAG, "Couldn't create the TriggerLongPressTimer!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Executes the Tagged Out substate.
|
//! Executes the Tagged Out substate.
|
||||||
|
@ -108,18 +157,31 @@ static void Playing__Tagged_Out_Do(StateMachineContext_T * context)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEVENT_TRIGGER_SWITCH_PRESSED:
|
||||||
|
{
|
||||||
|
if (xTimerStart(TriggerLongPressTimer, 0) != pdPASS)
|
||||||
|
{
|
||||||
|
KLOG_ERROR(KLOG_TAG, "Couldn't start the TriggerLongPressTimer!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case KEVENT_TRIGGER_SWITCH_RELEASED:
|
case KEVENT_TRIGGER_SWITCH_RELEASED:
|
||||||
{
|
{
|
||||||
uint32_t duration_of_press_in_ms = (uint32_t)Event.Data;
|
xTimerStop(TriggerLongPressTimer, 0);
|
||||||
|
|
||||||
// Was it a "long" press?
|
// Was it in fact a "long" press?
|
||||||
if (duration_of_press_in_ms > 5000)
|
if (SecondsUntilReentry == 0)
|
||||||
{
|
{
|
||||||
|
// Reenter the game.
|
||||||
Set_Health(Get_Max_Health());
|
Set_Health(Get_Max_Health());
|
||||||
Reset_Bombs();
|
Reset_Bombs();
|
||||||
Transition_For_Event(context, STATE_PLAYING__INTERACTING, &Event);
|
Transition_For_Event(context, STATE_PLAYING__INTERACTING, &Event);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SecondsUntilReentry = 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue