162 lines
5.2 KiB
C
162 lines
5.2 KiB
C
|
|
/*
|
|
* This program source code file is part of SystemK, a library in the KTag project.
|
|
*
|
|
* 🛡️ <https://ktag.clubk.club> 🃞
|
|
*
|
|
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
* later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
* details.
|
|
*
|
|
* There should be a copy of the GNU Affero General Public License in the LICENSE
|
|
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "SystemK.h"
|
|
|
|
typedef enum
|
|
{
|
|
STEP_LONG_DARK,
|
|
STEP_BLINK_ONE,
|
|
STEP_BLINK_TWO,
|
|
STEP_BLINK_THREE,
|
|
STEP_HEARTBEAT_GLOW
|
|
} TeamColorsStep_T;
|
|
|
|
static DisplayStyle_T Style = DISPLAY_STYLE_BLINK;
|
|
static TeamColorsStep_T Step = STEP_LONG_DARK;
|
|
static uint16_t Time_in_Animation_Step_in_ms = 0;
|
|
static color_t Team_Color = COLOR_BLACK;
|
|
static uint8_t Brightness = 0;
|
|
static uint8_t Phase = 0;
|
|
static const uint8_t LOW_BRIGHTNESS = 10;
|
|
static const uint8_t HIGH_BRIGHTNESS = 50;
|
|
static const uint16_t LONG_DARK_TIME_IN_ms = 20000;
|
|
static const uint16_t BLINK_TIME_ON_IN_ms = 100;
|
|
static const uint16_t BLINK_TIME_OFF_IN_ms = 100;
|
|
|
|
static void Reset(void * Data)
|
|
{
|
|
// Start just before the dawn.
|
|
Time_in_Animation_Step_in_ms = LONG_DARK_TIME_IN_ms;
|
|
Style = NeoPixels_ToDisplayStyle(Data);
|
|
Team_Color = HW_NeoPixels_Get_My_Color();
|
|
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, COLOR_BLACK);
|
|
}
|
|
|
|
static AnimationStepResult_T NextStep(void)
|
|
{
|
|
Time_in_Animation_Step_in_ms += CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
|
|
|
|
switch (Step)
|
|
{
|
|
default:
|
|
case STEP_LONG_DARK:
|
|
Brightness = LOW_BRIGHTNESS;
|
|
if (Time_in_Animation_Step_in_ms > LONG_DARK_TIME_IN_ms)
|
|
{
|
|
Time_in_Animation_Step_in_ms = 0;
|
|
if (Style == DISPLAY_STYLE_HEARTBEAT)
|
|
{
|
|
Step = STEP_HEARTBEAT_GLOW;
|
|
Phase = 0;
|
|
}
|
|
else
|
|
{
|
|
Step = STEP_BLINK_ONE;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case STEP_BLINK_ONE:
|
|
if (Time_in_Animation_Step_in_ms > (BLINK_TIME_ON_IN_ms + BLINK_TIME_OFF_IN_ms))
|
|
{
|
|
Brightness = HIGH_BRIGHTNESS;
|
|
Time_in_Animation_Step_in_ms = 0;
|
|
Step = STEP_BLINK_TWO;
|
|
}
|
|
else if (Time_in_Animation_Step_in_ms > BLINK_TIME_ON_IN_ms)
|
|
{
|
|
Brightness = LOW_BRIGHTNESS;
|
|
}
|
|
else
|
|
{
|
|
Brightness = HIGH_BRIGHTNESS;
|
|
}
|
|
break;
|
|
|
|
case STEP_BLINK_TWO:
|
|
if (Time_in_Animation_Step_in_ms > (BLINK_TIME_ON_IN_ms + BLINK_TIME_OFF_IN_ms))
|
|
{
|
|
Brightness = HIGH_BRIGHTNESS;
|
|
Time_in_Animation_Step_in_ms = 0;
|
|
Step = STEP_BLINK_THREE;
|
|
}
|
|
else if (Time_in_Animation_Step_in_ms > BLINK_TIME_ON_IN_ms)
|
|
{
|
|
Brightness = LOW_BRIGHTNESS;
|
|
}
|
|
else
|
|
{
|
|
Brightness = HIGH_BRIGHTNESS;
|
|
}
|
|
break;
|
|
|
|
case STEP_BLINK_THREE:
|
|
if (Time_in_Animation_Step_in_ms > (BLINK_TIME_ON_IN_ms + BLINK_TIME_OFF_IN_ms))
|
|
{
|
|
Brightness = LOW_BRIGHTNESS;
|
|
Time_in_Animation_Step_in_ms = 0;
|
|
Step = STEP_LONG_DARK;
|
|
}
|
|
else if (Time_in_Animation_Step_in_ms > BLINK_TIME_ON_IN_ms)
|
|
{
|
|
Brightness = LOW_BRIGHTNESS;
|
|
}
|
|
else
|
|
{
|
|
Brightness = HIGH_BRIGHTNESS;
|
|
}
|
|
break;
|
|
|
|
case STEP_HEARTBEAT_GLOW:
|
|
Brightness = Sine8[Phase] / 2;
|
|
Phase++;
|
|
|
|
if (Phase == 0)
|
|
{
|
|
Brightness = LOW_BRIGHTNESS;
|
|
Time_in_Animation_Step_in_ms = 0;
|
|
Step = STEP_LONG_DARK;
|
|
}
|
|
break;
|
|
}
|
|
|
|
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
|
|
Set_Barrel_Flash(ApplyMask(Team_Color, Brightness));
|
|
Set_Heart(COLOR_BLACK);
|
|
Set_Square(COLOR_BLACK);
|
|
Set_Circle(COLOR_BLACK);
|
|
Set_Arrow(COLOR_BLACK);
|
|
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
|
|
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RECEIVER_INDICATOR_PIXEL, ApplyMask(Team_Color, Brightness));
|
|
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RIGHT_RECEIVER_INDICATOR_PIXEL, ApplyMask(Team_Color, Brightness));
|
|
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, LEFT_RECEIVER_INDICATOR_PIXEL, ApplyMask(Team_Color, Brightness));
|
|
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
|
|
|
|
return ANIMATION_ONGOING;
|
|
}
|
|
|
|
Animation_T Team_Colors_Animation =
|
|
{
|
|
.Reset = Reset,
|
|
.NextStep = NextStep
|
|
};
|