SystemK/NeoPixels/Animations/Menu_Animation.c
2025-01-25 13:45:14 -06:00

115 lines
3.9 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"
static uint8_t Scene = 0;
static uint8_t N_SCENES = 4;
static uint16_t Time_in_Current_Scene_in_ms = 0;
static color_t My_Color = COLOR_BLACK;
static void Reset(void * Data)
{
Time_in_Current_Scene_in_ms = 0;
Scene = 0;
}
static AnimationStepResult_T NextStep(void)
{
My_Color = HW_NeoPixels_Get_My_Color();
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
switch (Scene)
{
default:
case 0:
Set_Barrel_Flash(Color(0x70, 0xFF, 0xFF, 0xFF));
Set_Heart(Color(0x00, 0x00, 0x00, 0x00));
Set_Square(Color(0x00, 0x00, 0x00, 0x00));
Set_Circle(Color(0x00, 0x00, 0x00, 0x00));
Set_Arrow(ApplyMask(My_Color, 0x70));
break;
case 1:
Set_Barrel_Flash(Color(0x00, 0x00, 0x00, 0x00));
Set_Heart(Color(0x00, 0x00, 0x00, 0x00));
Set_Square(Color(0x00, 0x00, 0x00, 0x00));
Set_Circle(ApplyMask(My_Color, 0x70));
Set_Arrow(Color(0x00, 0x00, 0x00, 0x00));
break;
case 2:
Set_Barrel_Flash(Color(0x70, 0xFF, 0xFF, 0xFF));
Set_Heart(Color(0x00, 0x00, 0x00, 0x00));
Set_Square(ApplyMask(My_Color, 0x70));
Set_Circle(Color(0x00, 0x00, 0x00, 0x00));
Set_Arrow(Color(0x00, 0x00, 0x00, 0x00));
break;
case 3:
Set_Barrel_Flash(Color(0x00, 0x00, 0x00, 0x00));
Set_Heart(ApplyMask(My_Color, 0x70));
Set_Square(Color(0x00, 0x00, 0x00, 0x00));
Set_Circle(Color(0x00, 0x00, 0x00, 0x00));
Set_Arrow(Color(0x00, 0x00, 0x00, 0x00));
break;
}
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, ApplyMask(COLOR_WHITE, 0x70));
for (uint_fast8_t pixel = 0; pixel < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; pixel++)
{
if ((pixel % N_SCENES) == Scene)
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, pixel, ApplyMask(My_Color, 0x70));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, pixel, ApplyMask(My_Color, 0x70));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, pixel, ApplyMask(My_Color, 0x70));
}
else
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, pixel, COLOR_BLACK);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, pixel, COLOR_BLACK);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, pixel, COLOR_BLACK);
}
}
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RECEIVER_INDICATOR_PIXEL, ApplyMask(COLOR_WHITE, 0x70));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
Time_in_Current_Scene_in_ms += CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
if (Time_in_Current_Scene_in_ms > 100)
{
Time_in_Current_Scene_in_ms = 0;
Scene++;
if (Scene >= N_SCENES)
{
Scene = 0;
}
}
return ANIMATION_ONGOING;
}
Animation_T Menu_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};