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

121 lines
4.5 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 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;
My_Color = HW_NeoPixels_Get_My_Color();
}
static AnimationStepResult_T NextStep(void)
{
switch (Scene)
{
default:
case 0:
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, ApplyMask(COLOR_WHITE, 0x70));
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RECEIVER_INDICATOR_PIXEL, ApplyMask(COLOR_WHITE, 0x70));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 1:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(COLOR_WHITE, 0x70));
Set_Heart(COLOR_BLACK);
Set_Square(ApplyMask(My_Color, 0x70));
Set_Circle(COLOR_BLACK);
Set_Arrow(ApplyMask(My_Color, 0x70));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
for (uint_fast8_t pixel = 0; pixel < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; pixel++)
{
if (pixel % 2)
{
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
break;
case 2:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(COLOR_WHITE, 0x70));
Set_Heart(ApplyMask(My_Color, 0x70));
Set_Square(COLOR_BLACK);
Set_Circle(ApplyMask(My_Color, 0x70));
Set_Arrow(COLOR_BLACK);
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
for (uint_fast8_t pixel = 0; pixel < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; pixel++)
{
if (pixel % 2)
{
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);
}
else
{
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));
}
}
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RECEIVER_INDICATOR_PIXEL, ApplyMask(COLOR_WHITE, 0x70));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
}
Time_in_Current_Scene_in_ms += CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
if (Time_in_Current_Scene_in_ms > 500)
{
Time_in_Current_Scene_in_ms = 0;
Scene++;
if (Scene > 2)
{
Scene = 1;
}
}
return ANIMATION_ONGOING;
}
Animation_T Idle_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};