SystemK/NeoPixels/Animations/Health_Report.c
Joe Kearney f80cb59828 SystemK v1.00 (#9)
This change cleans up the final bits before the release of SystemK version 1.00.

It implements the [KTag Beacon Specification v0.12](https://ktag.clubk.club/Technology/BLE/KTag%20Beacon%20Specification%20v0.12.pdf).

Co-authored-by: Joe Kearney <joe@clubk.club>
Reviewed-on: #9
2025-11-30 21:20:05 +00:00

115 lines
3.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"
static uint8_t Health_in_percent;
static uint8_t On = 0xFF / 2;
static uint8_t Blink;
static uint8_t State = 0;
static uint16_t Time_in_Current_Scene_in_ms = 0;
static void Reset(void * Data)
{
Health_in_percent = *((uint8_t *)Data);
Time_in_Current_Scene_in_ms = 0;
}
static AnimationStepResult_T NextStep(void)
{
if (State > 1)
{
State = 0;
}
Blink = On * State;
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
if (Health_in_percent > 0) // 10
{
Set_Heart(Color(Blink, 0xFF, 0x00, 0x00));
}
if (Health_in_percent > 10) // 20 - 30
{
Set_Heart(Color(On, 0xFF, 0x00, 0x00));
}
if (Health_in_percent > 30) // 40
{
Set_Heart(Color(On, 0xFF, 0xFF, 0x00));
Set_Square(Color(Blink, 0xFF, 0xFF, 0x00));
}
if (Health_in_percent > 40) // 50
{
Set_Heart(Color(On, 0xFF, 0xFF, 0x00));
Set_Square(Color(On, 0xFF, 0xFF, 0x00));
}
if (Health_in_percent > 50) // 60
{
Set_Heart(Color(On, 0x00, 0xFF, 0x00));
Set_Square(Color(On, 0x00, 0xFF, 0x00));
Set_Circle(Color(Blink, 0x00, 0xFF, 0x00));
}
if (Health_in_percent > 60) // 70 - 80
{
Set_Heart(Color(On, 0x00, 0xFF, 0x00));
Set_Square(Color(On, 0x00, 0xFF, 0x00));
Set_Circle(Color(On, 0x00, 0xFF, 0x00));
}
if (Health_in_percent > 80) // 90 - 100
{
Set_Heart(Color(On, 0x00, 0xFF, 0x00));
Set_Square(Color(On, 0x00, 0xFF, 0x00));
Set_Circle(Color(On, 0x00, 0xFF, 0x00));
Set_Arrow(Color(Blink, 0x00, 0xFF, 0x00));
}
if (Health_in_percent == 100) // 100
{
Set_Heart(Color(On, 0x00, 0xFF, 0x00));
Set_Square(Color(On, 0x00, 0xFF, 0x00));
Set_Circle(Color(On, 0x00, 0xFF, 0x00));
Set_Arrow(Color(On, 0x00, 0xFF, 0x00));
}
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;
State++;
}
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
// TODO: Implement the "Health Report" animation for four NeoPixel channels.
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
return ANIMATION_ONGOING;
}
Animation_T Health_Report_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};