Initial public release of SystemK.

This commit is contained in:
Joe Kearney 2025-01-25 13:45:14 -06:00
parent 387f57cdda
commit 6f51f5b006
129 changed files with 11654 additions and 2 deletions

39
NeoPixels/Animation.h Normal file
View file

@ -0,0 +1,39 @@
/*
* 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/>.
*/
#ifndef ANIMATION_H
#define ANIMATION_H
typedef enum
{
ANIMATION_ONGOING,
ANIMATION_COMPLETE
} AnimationStepResult_T;
typedef struct
{
void (*Reset)(void * Data);
AnimationStepResult_T (*NextStep)(void);
} Animation_T;
#endif // ANIMATION_H

View file

@ -0,0 +1,40 @@
/*
* 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 void Reset(void * Data)
{
}
static AnimationStepResult_T NextStep(void)
{
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, COLOR_BLACK);
return ANIMATION_COMPLETE;
}
Animation_T All_Off_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef ALL_OFF_H
#define ALL_OFF_H
extern Animation_T All_Off_Animation;
#endif // ALL_OFF_H

View file

@ -0,0 +1,108 @@
/*
* 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 color_t All_On_Color = COLOR_WHITE;
static DisplayStyle_T All_On_Style = DISPLAY_STYLE_DEFAULT;
static uint32_t Time_in_Animation_in_ms = 0;
static void Reset(void *Data)
{
All_On_Color = ((All_On_Data_T *)Data)->color;
All_On_Style = ((All_On_Data_T *)Data)->style;
Time_in_Animation_in_ms = 0;
}
static AnimationStepResult_T NextStep(void)
{
if (All_On_Style == DISPLAY_STYLE_ALTERNATE)
{
if ((Time_in_Animation_in_ms % 500) < 250)
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(All_On_Color);
Set_Heart(COLOR_BLACK);
Set_Square(All_On_Color);
Set_Circle(COLOR_BLACK);
Set_Arrow(All_On_Color);
#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_BARREL, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, pixel, All_On_Color);
}
else
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, pixel, COLOR_BLACK);
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);
}
}
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
}
else
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(COLOR_BLACK);
Set_Heart(All_On_Color);
Set_Square(COLOR_BLACK);
Set_Circle(All_On_Color);
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_BARREL, pixel, COLOR_BLACK);
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_BARREL, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, pixel, All_On_Color);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, pixel, All_On_Color);
}
}
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
}
}
else
{
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, All_On_Color);
}
Time_in_Animation_in_ms += CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
return ANIMATION_ONGOING;
}
Animation_T All_On_Animation =
{
.Reset = Reset,
.NextStep = NextStep};

View file

@ -0,0 +1,27 @@
/*
* 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/>.
*/
#ifndef ALL_ON_H
#define ALL_ON_H
extern Animation_T All_On_Animation;
#endif // ALL_ON_H

View file

@ -0,0 +1,87 @@
/*
* 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 BLENearby_T * RXd_Data;
static inline uint8_t RSSItoBrightness(int8_t RSSI)
{
uint8_t brightness = 255;
if (RSSI < 0)
{
brightness += (2*RSSI);
}
return brightness;
}
static void Reset(void * Data)
{
RXd_Data = (BLENearby_T *)Data;
}
static AnimationStepResult_T NextStep(void)
{
AnimationStepResult_T result = ANIMATION_COMPLETE;
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
// TODO: Implement the "BLE Nearby" animation for a single NeoPixel channel.
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
for (uint_fast8_t slot = 0; slot < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; slot++)
{
if (RXd_Data->neighbors[slot].TimeToLive_in_ms > 0)
{
//NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, slot, ApplyMask(RXd_Data->neighbors[slot].Color, RSSItoBrightness(RXd_Data->neighbors[slot].RSSI)));
// TODO: Set a low brightness, and a blink rate proportional to RSSI.
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, slot, ApplyMask(RXd_Data->neighbors[slot].Color, 25));
}
else
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, slot, COLOR_BLACK);
}
}
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
for (uint_fast8_t slot = 0; slot < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; slot++)
{
if (RXd_Data->neighbors[slot].TimeToLive_in_ms > CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms)
{
result = ANIMATION_ONGOING;
RXd_Data->neighbors[slot].TimeToLive_in_ms -= CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
}
else
{
RXd_Data->neighbors[slot].TimeToLive_in_ms = 0;
}
}
return result;
}
Animation_T BLE_Nearby_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,42 @@
/*
* 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/>.
*/
#ifndef BLE_NEARBY_H
#define BLE_NEARBY_H
typedef struct
{
uint8_t BD_ADDR[6];
int8_t RSSI;
color_t Color;
uint16_t TimeToLive_in_ms;
} BLENeighbor_T;
typedef struct
{
BLENeighbor_T neighbors[CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL];
} BLENearby_T;
extern Animation_T BLE_Nearby_Animation;
#endif // BLE_NEARBY_H

View file

@ -0,0 +1,53 @@
/*
* 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 color_t RSSSIColor = (color_t) 0x00000000;
static uint8_t Brightness = 255;
static void Reset(void * Data)
{
RSSSIColor = *((color_t *)Data);
Brightness = 255 + *((int8_t *)Data) + *((int8_t *)Data);
}
static AnimationStepResult_T NextStep(void)
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(Color(0x00, 0x00, 0x00, 0x00));
Set_Heart(ApplyMask(RSSSIColor, Brightness));
Set_Square(ApplyMask(RSSSIColor, Brightness));
Set_Circle(ApplyMask(RSSSIColor, Brightness));
Set_Arrow(ApplyMask(RSSSIColor, Brightness));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL-1, ApplyMask(RSSSIColor, Brightness));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
return ANIMATION_ONGOING;
}
Animation_T BLE_RSSI_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef BLE_RSSI_H
#define BLE_RSSI_H
extern Animation_T BLE_RSSI_Animation;
#endif // BLE_RSSI_H

View file

@ -0,0 +1,165 @@
/*
* 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 N_Lights;
static color_t My_Color = COLOR_BLACK;
static const uint8_t BRIGHTNESS = 0x7F;
static void Reset(void *Data)
{
N_Lights = *((uint8_t *)Data);
My_Color = HW_NeoPixels_Get_My_Color();
}
static AnimationStepResult_T NextStep(void)
{
switch (N_Lights)
{
case 0:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, 0x00));
Set_Heart(ApplyMask(My_Color, 0x00));
Set_Square(ApplyMask(My_Color, 0x00));
Set_Circle(ApplyMask(My_Color, 0x00));
Set_Arrow(ApplyMask(My_Color, 0x00));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_RECEIVER, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 1:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, 0x00));
Set_Heart(ApplyMask(My_Color, 0x00));
Set_Square(ApplyMask(My_Color, 0x00));
Set_Circle(ApplyMask(My_Color, 0x00));
Set_Arrow(ApplyMask(My_Color, BRIGHTNESS));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RIGHT_RECEIVER_INDICATOR_PIXEL, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, LEFT_RECEIVER_INDICATOR_PIXEL, COLOR_BLACK);
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 4, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 4, ApplyMask(My_Color, BRIGHTNESS));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 2:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, 0x00));
Set_Heart(ApplyMask(My_Color, 0x00));
Set_Square(ApplyMask(My_Color, 0x00));
Set_Circle(ApplyMask(My_Color, BRIGHTNESS));
Set_Arrow(ApplyMask(My_Color, BRIGHTNESS));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RIGHT_RECEIVER_INDICATOR_PIXEL, COLOR_BLACK);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, LEFT_RECEIVER_INDICATOR_PIXEL, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 4, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 4, ApplyMask(My_Color, BRIGHTNESS));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 3:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, 0x00));
Set_Heart(ApplyMask(My_Color, 0x00));
Set_Square(ApplyMask(My_Color, BRIGHTNESS));
Set_Circle(ApplyMask(My_Color, BRIGHTNESS));
Set_Arrow(ApplyMask(My_Color, BRIGHTNESS));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RIGHT_RECEIVER_INDICATOR_PIXEL, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, LEFT_RECEIVER_INDICATOR_PIXEL, COLOR_BLACK);
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 2, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 4, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 2, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 4, ApplyMask(My_Color, BRIGHTNESS));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 4:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, 0x00));
Set_Heart(ApplyMask(My_Color, BRIGHTNESS));
Set_Square(ApplyMask(My_Color, BRIGHTNESS));
Set_Circle(ApplyMask(My_Color, BRIGHTNESS));
Set_Arrow(ApplyMask(My_Color, BRIGHTNESS));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RIGHT_RECEIVER_INDICATOR_PIXEL, COLOR_BLACK);
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, LEFT_RECEIVER_INDICATOR_PIXEL, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 1, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 2, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_DISPLAY, 4, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, 0x00));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 1, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 2, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 3, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_EFFECTS, 4, ApplyMask(My_Color, BRIGHTNESS));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
case 5:
default:
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(My_Color, BRIGHTNESS));
Set_Heart(ApplyMask(My_Color, BRIGHTNESS));
Set_Square(ApplyMask(My_Color, BRIGHTNESS));
Set_Circle(ApplyMask(My_Color, BRIGHTNESS));
Set_Arrow(ApplyMask(My_Color, BRIGHTNESS));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_RECEIVER, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_DISPLAY, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, BRIGHTNESS));
NeoPixels_Set_Color_Range(NEOPIXEL_CHANNEL_EFFECTS, 0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, ApplyMask(My_Color, BRIGHTNESS));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
break;
}
return ANIMATION_ONGOING;
}
Animation_T Countdown_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef COUNTDOWN_H
#define COUNTDOWN_H
extern Animation_T Countdown_Animation;
#endif // COUNTDOWN_H

View file

@ -0,0 +1,107 @@
/*
* 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"
#define RED_DELTA_MAX 15
#define GREEN_DELTA_MAX 8
#define MAX_RED 128
#define MIN_RED RED_DELTA_MAX
#define MIN_GREEN 1
#define LESS_GREEN_THAN_RED 20
static int16_t RedLevel = 0;
static int16_t GreenLevel = 0;
// From https://stackoverflow.com/a/1180465
static uint8_t lfsr113_Bits (uint32_t min, uint32_t max)
{
static uint32_t z1 = 12345, z2 = 12345, z3 = 12345, z4 = 12345;
uint32_t b;
b = ((z1 << 6) ^ z1) >> 13;
z1 = ((z1 & 4294967294U) << 18) ^ b;
b = ((z2 << 2) ^ z2) >> 27;
z2 = ((z2 & 4294967288U) << 2) ^ b;
b = ((z3 << 13) ^ z3) >> 21;
z3 = ((z3 & 4294967280U) << 7) ^ b;
b = ((z4 << 3) ^ z4) >> 12;
z4 = ((z4 & 4294967168U) << 13) ^ b;
uint64_t raw = (z1 ^ z2 ^ z3 ^ z4);
uint32_t scaled = ((((max - min) * raw) + (UINT32_MAX / 2)) / UINT32_MAX) + min;
return (uint8_t) scaled;
}
static void Reset(void * Data)
{
RedLevel = MIN_RED;
GreenLevel = MIN_GREEN;
}
// TODO: Need to reimplement this with HSB--see https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/
static AnimationStepResult_T NextStep(void)
{
// get our next changes in red and green
int16_t delta_red = (lfsr113_Bits(0, RED_DELTA_MAX*2) - RED_DELTA_MAX);
int16_t delta_green = (lfsr113_Bits(0, GREEN_DELTA_MAX*2) - GREEN_DELTA_MAX);
RedLevel = RedLevel + delta_red;
if (RedLevel > MAX_RED)
{
RedLevel = MAX_RED;
}
else if (RedLevel < MIN_RED)
{
RedLevel = MIN_RED;
}
RedLevel = (uint8_t) RedLevel;
GreenLevel = GreenLevel + delta_green;
// Green has to be less than red, to keep the flame red-orange-yellow.
if (RedLevel > LESS_GREEN_THAN_RED)
{
if (GreenLevel > (RedLevel - LESS_GREEN_THAN_RED))
{
GreenLevel = (RedLevel - LESS_GREEN_THAN_RED);
}
else if (GreenLevel < MIN_GREEN)
{
GreenLevel = MIN_GREEN;
}
}
else
{
GreenLevel = MIN_GREEN;
}
GreenLevel = (uint8_t) GreenLevel;
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, Color(0xFF, RedLevel, GreenLevel, 0x00));
return ANIMATION_ONGOING;
}
Animation_T Flamethrower_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef FLAMETHROWER_H
#define FLAMETHROWER_H
extern Animation_T Flamethrower_Animation;
#endif // FLAMETHROWER_H

View file

@ -0,0 +1,40 @@
/*
* 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 void Reset(void * Data)
{
}
static AnimationStepResult_T NextStep(void)
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, COLOR_WHITE);
return ANIMATION_ONGOING;
}
Animation_T Flashlight_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef FLASHLIGHT_H
#define FLASHLIGHT_H
extern Animation_T Flashlight_Animation;
#endif // FLASHLIGHT_H

View file

@ -0,0 +1,116 @@
/*
* 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
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef HEALTH_REPORT_H
#define HEALTH_REPORT_H
extern Animation_T Health_Report_Animation;
#endif // HEALTH_REPORT_H

View file

@ -0,0 +1,121 @@
/*
* 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
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef IDLE_ANIMATION_H
#define IDLE_ANIMATION_H
extern Animation_T Idle_Animation;
#endif // IDLE_ANIMATION_H

View file

@ -0,0 +1,115 @@
/*
* 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
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef MENU_ANIMATION_H
#define MENU_ANIMATION_H
extern Animation_T Menu_Animation;
#endif // MENU_ANIMATION_H

View file

@ -0,0 +1,59 @@
/*
* 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 uint16_t Time_in_Animation_in_ms = 0;
static color_t Flash_Color = COLOR_BLACK;
static void Reset(void * Data)
{
Time_in_Animation_in_ms = 0;
Flash_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)
{
AnimationStepResult_T result;
if (Time_in_Animation_in_ms < 250)
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, Flash_Color);
Time_in_Animation_in_ms += CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms;
result = ANIMATION_ONGOING;
}
else
{
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, COLOR_BLACK);
result = ANIMATION_COMPLETE;
}
return result;
}
Animation_T Shot_Fired_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef SHOT_FIRED_H
#define SHOT_FIRED_H
extern Animation_T Shot_Fired_Animation;
#endif // SHOT_FIRED_H

View file

@ -0,0 +1,70 @@
/*
* 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 uint16_t Time_in_Animation_in_ms = 0;
static color_t TagTeamColor = (color_t) 0x00000000;
static uint8_t Fade = 0x40;
static void Reset(void * Data)
{
Time_in_Animation_in_ms = 0;
TagTeamColor = *((color_t *)Data);
Fade = 128;
}
static AnimationStepResult_T NextStep(void)
{
AnimationStepResult_T result;
if (Fade < 255)
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(ApplyMask(TagTeamColor, Sine8[Fade]));
Set_Heart(ApplyMask(TagTeamColor, Sine8[Fade]));
Set_Square(ApplyMask(TagTeamColor, Sine8[Fade]));
Set_Circle(ApplyMask(TagTeamColor, Sine8[Fade]));
Set_Arrow(ApplyMask(TagTeamColor, Sine8[Fade]));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, ApplyMask(TagTeamColor, Sine8[Fade]));
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_RECEIVER, RECEIVER_INDICATOR_PIXEL, ApplyMask(TagTeamColor, Sine8[Fade]));
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
Fade += 1;
result = ANIMATION_ONGOING;
}
else
{
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, COLOR_BLACK);
result = ANIMATION_COMPLETE;
}
return result;
}
Animation_T Tag_Received_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef TAG_RECEIVED_H
#define TAG_RECEIVED_H
extern Animation_T Tag_Received_Animation;
#endif // TAG_RECEIVED_H

View file

@ -0,0 +1,82 @@
/*
* 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 Fade = 0xFF;
static color_t My_Color = COLOR_BLACK;
static void Reset(void * Data)
{
Fade = 0xFF;
My_Color = HW_NeoPixels_Get_My_Color();
}
static AnimationStepResult_T NextStep(void)
{
uint8_t phase_0 = Fade;
uint8_t phase_1 = phase_0 - (uint8_t)64;
uint8_t phase_2 = phase_1 - (uint8_t)64;
uint8_t phase_3 = phase_2 - (uint8_t)64;
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
Set_Barrel_Flash(Color(Sine8[phase_0], 0xFF, 0x00, 0x00));
Set_Heart(Color(Sine8[phase_1], 0xFF, 0x00, 0x00));
Set_Square(Color(Sine8[phase_2], 0xFF, 0x00, 0x00));
Set_Circle(Color(Sine8[phase_3], 0xFF, 0x00, 0x00));
Set_Arrow(Color(Sine8[phase_0], 0xFF, 0x00, 0x00));
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
for (uint_fast8_t pixel = 0; pixel < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; pixel++)
{
switch (pixel % 4)
{
default:
case 0:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(My_Color, Sine8[phase_0]));
break;
case 1:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(My_Color, Sine8[phase_1]));
break;
case 2:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(My_Color, Sine8[phase_2]));
break;
case 3:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(My_Color, Sine8[phase_3]));
break;
}
}
NeoPixels_Set_Color(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, COLOR_WHITE);
#endif // CONFIG_KTAG_N_NEOPIXEL_CHANNELS
Fade += 2;
return ANIMATION_ONGOING;
}
Animation_T Tagged_Out_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef TAGGED_OUT_H
#define TAGGED_OUT_H
extern Animation_T Tagged_Out_Animation;
#endif // TAGGED_OUT_H

View file

@ -0,0 +1,162 @@
/*
* 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
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef TEAM_COLORS_H
#define TEAM_COLORS_H
extern Animation_T Team_Colors_Animation;
#endif // TEAM_COLORS_H

View file

@ -0,0 +1,116 @@
/*
* 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 void Reset(void * Data)
{
Time_in_Current_Scene_in_ms = 0;
Scene = 0;
}
static AnimationStepResult_T NextStep(void)
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
switch (Scene)
{
default:
case 0:
Set_Barrel_Flash(Color(0xFF, 0xFF, 0x00, 0x00));
Set_Heart(Color(0xFF / 2, 0xFF, 0x00, 0x00));
Set_Square(Color(0xFF / 2, 0x00, 0xFF, 0x00));
Set_Circle(Color(0xFF / 2, 0xFF, 0x00, 0xFF));
Set_Arrow(Color(0xFF / 2, 0xFF, 0xFF, 0x00));
break;
case 1:
Set_Barrel_Flash(Color(0xFF, 0xFF, 0xFF, 0xFF));
Set_Heart(Color(0xFF / 2, 0xFF, 0xFF, 0x00));
Set_Square(Color(0xFF / 2, 0xFF, 0x00, 0x00));
Set_Circle(Color(0xFF / 2, 0x00, 0xFF, 0x00));
Set_Arrow(Color(0xFF / 2, 0xFF, 0x00, 0xFF));
break;
case 2:
Set_Barrel_Flash(Color(0xFF, 0x00, 0x00, 0xFF));
Set_Heart(Color(0xFF / 2, 0xFF, 0x00, 0xFF));
Set_Square(Color(0xFF / 2, 0xFF, 0xFF, 0x00));
Set_Circle(Color(0xFF / 2, 0xFF, 0x00, 0x00));
Set_Arrow(Color(0xFF / 2, 0x00, 0xFF, 0x00));
break;
case 3:
Set_Barrel_Flash(Color(0xFF, 0x00, 0x00, 0x00));
Set_Heart(Color(0xFF / 2, 0x00, 0xFF, 0x00));
Set_Square(Color(0xFF / 2, 0xFF, 0x00, 0xFF));
Set_Circle(Color(0xFF / 2, 0xFF, 0xFF, 0x00));
Set_Arrow(Color(0xFF / 2, 0xFF, 0x00, 0x00));
break;
}
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
for (uint_fast8_t pixel = 0; pixel < CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL; pixel++)
{
switch ((pixel + Scene) % 4)
{
default:
case 0:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(COLOR_RED, 0xFF / 2));
break;
case 1:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(COLOR_WHITE, 0xFF / 2));
break;
case 2:
NeoPixels_Set_Color_On_All_Channels(pixel, ApplyMask(COLOR_BLUE, 0xFF / 2));
break;
case 3:
NeoPixels_Set_Color_On_All_Channels(pixel, COLOR_BLACK);
break;
}
}
#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 > 3)
{
Scene = 0;
}
}
return ANIMATION_ONGOING;
}
Animation_T Test_Pattern_Animation =
{
.Reset = Reset,
.NextStep = NextStep
};

View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef TEST_PATTERN_H
#define TEST_PATTERN_H
extern Animation_T Test_Pattern_Animation;
#endif // TEST_PATTERN_H

48
NeoPixels/Displays.h Normal file
View file

@ -0,0 +1,48 @@
/*
* 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/>.
*/
#ifndef DISPLAYS_H
#define DISPLAYS_H
#include "Gamma.h"
#include "Sine.h"
#include "Animation.h"
#include "NeoPixel_Hardware_Config.h"
#include "NeoPixels.h"
#include "Animations/All_Off.h"
#include "Animations/BLE_Nearby.h"
#include "Animations/BLE_RSSI.h"
#include "Animations/Countdown.h"
#include "Animations/Flamethrower.h"
#include "Animations/Flashlight.h"
#include "Animations/Health_Report.h"
#include "Animations/Idle_Animation.h"
#include "Animations/Menu_Animation.h"
#include "Animations/Shot_Fired.h"
#include "Animations/Tag_Received.h"
#include "Animations/Tagged_Out.h"
#include "Animations/Team_Colors.h"
#include "Animations/Test_Pattern.h"
#endif // DISPLAYS_H

View file

@ -0,0 +1,60 @@
/*
* 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/>.
*/
// /\ /\\ /\ /\\ TM
// ( ) || || ( ) || || |''||''| '||''|. ..|'''.|
// // || || // || || || || || .|' '
// // || || // || || || ||...|' ||
// /( || || /( || || || || '|. .
// {___ \\/ {___ \\/ .||. .||. ''|....'
//
//
// _____ _____ _____ ___________ _ _
// |____ |/ __ \| ___/ ___| ___ \ (_) | |
// / /`' / /'| |__ \ `--.| |_/ /__ ___ _ __ _| |
// \ \ / / | __| `--. \ __/ _ \/ __| |/ _` | |
// .___/ /./ /___| |___/\__/ / | | __/ (__| | (_| | |
// \____/ \_____/\____/\____/\_| \___|\___|_|\__,_|_|
//! Zero-based index of the Barrel Flash NeoPixel in the sequence of NeoPixels.
#define BARREL_FLASH_PIXEL 0
//! Zero-based index of the Receiver Indicator NeoPixel in the sequence of NeoPixels.
#define RECEIVER_INDICATOR_PIXEL 0
//! Zero-based index of the right Receiver Indicator NeoPixel in the sequence of NeoPixels.
#define RIGHT_RECEIVER_INDICATOR_PIXEL 1
//! Zero-based index of the left Receiver Indicator NeoPixel in the sequence of NeoPixels.
#define LEFT_RECEIVER_INDICATOR_PIXEL 2
static inline __attribute__((always_inline)) void NeoPixels_Set_Color_On_All_Channels(uint8_t position, color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, position, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_RECEIVER, position, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_DISPLAY, position, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_EFFECTS, position, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
}

44
NeoPixels/Gamma.c Normal file
View file

@ -0,0 +1,44 @@
/*
* 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 <stdint.h>
#include "Gamma.h"
// https://learn.adafruit.com/led-tricks-gamma-correction/the-quick-fix
const uint_fast8_t Gamma8[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };

28
NeoPixels/Gamma.h Normal file
View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef GAMMA_H
#define GAMMA_H
extern const uint_fast8_t Gamma8[];
#endif // GAMMA_H

View file

@ -0,0 +1,30 @@
/*
* 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/>.
*/
#ifndef NEOPIXEL_HW_INTERFACE_H
#define NEOPIXEL_HW_INTERFACE_H
SystemKResult_T HW_NeoPixels_Init(void);
SystemKResult_T HW_NeoPixels_Set_RGB(NeoPixelsChannel_T channel, uint8_t position, uint8_t red, uint8_t green, uint8_t blue);
SystemKResult_T HW_NeoPixels_Publish(void);
color_t HW_NeoPixels_Get_My_Color(void);
#endif // NEOPIXEL_HW_INTERFACE_H

164
NeoPixels/NeoPixels.c Normal file
View file

@ -0,0 +1,164 @@
/*
* 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"
QueueHandle_t xQueueNeoPixels;
TaskHandle_t NeoPixels_Task_Handle;
SemaphoreHandle_t NeoPixels_Semaphore;
static const TickType_t Animation_Delay = CONFIG_KTAG_ANIMATION_STEP_TIME_IN_ms / portTICK_PERIOD_MS;
static Animation_T * Current_Foreground_Animation = &All_Off_Animation;
static Animation_T * Current_Background_Animation = &All_Off_Animation;
void NeoPixels_Task(void * pvParameters)
{
portBASE_TYPE xStatus;
TickType_t xLastWakeTime;
Animation_T * New_Animation;
xQueueNeoPixels = xQueueCreate(5, sizeof(NeoPixelsAction_T));
NeoPixels_Semaphore = xSemaphoreCreateBinary();
xSemaphoreGive(NeoPixels_Semaphore);
// TODO: Wait for NVM to be initialized and configurations read.
vTaskDelay(pdMS_TO_TICKS(1000));
HW_NeoPixels_Init();
NeoPixels_Set_Color_Range_On_All_Channels(0, CONFIG_KTAG_MAX_NEOPIXELS_PER_CHANNEL - 1, COLOR_BLACK);
// Initialize the xLastWakeTime variable with the current time.
xLastWakeTime = xTaskGetTickCount();
while (true)
{
NeoPixelsAction_T action;
// Check for a new animation.
xStatus = xQueueReceive(xQueueNeoPixels, &action, 0);
if (xStatus == pdPASS)
{
switch (action.ID)
{
case NEOPIXELS_ALL_OFF:
default:
New_Animation = &All_Off_Animation;
break;
case NEOPIXELS_ALL_ON:
New_Animation = &All_On_Animation;
break;
case NEOPIXELS_TEST_PATTERN:
New_Animation = &Test_Pattern_Animation;
break;
case NEOPIXELS_PLAY_SHOT_FIRED:
New_Animation = &Shot_Fired_Animation;
break;
case NEOPIXELS_FLASHLIGHT_ON:
New_Animation = &Flashlight_Animation;
break;
case NEOPIXELS_FLAMETHROWER:
New_Animation = &Flamethrower_Animation;
break;
case NEOPIXELS_TAG_RECEIVED:
New_Animation = &Tag_Received_Animation;
break;
case NEOPIXELS_TAGGED_OUT:
New_Animation = &Tagged_Out_Animation;
break;
case NEOPIXELS_MENU:
New_Animation = &Menu_Animation;
break;
case NEOPIXELS_HEALTH_REPORT:
New_Animation = &Health_Report_Animation;
break;
case NEOPIXELS_BLE_RSSI:
New_Animation = &BLE_RSSI_Animation;
break;
case NEOPIXELS_IDLE:
New_Animation = &Idle_Animation;
break;
case NEOPIXELS_COUNTDOWN:
New_Animation = &Countdown_Animation;
break;
case NEOPIXELS_TEAM_COLORS:
New_Animation = &Team_Colors_Animation;
break;
case NEOPIXELS_BLE_NEARBY:
New_Animation = &BLE_Nearby_Animation;
break;
}
if (New_Animation != NULL)
{
New_Animation->Reset(action.Data);
if (action.Prominence == NEOPIXELS_FOREGROUND)
{
Current_Foreground_Animation = New_Animation;
}
if (action.Prominence == NEOPIXELS_BACKGROUND)
{
Current_Background_Animation = New_Animation;
}
}
}
if (Current_Foreground_Animation != NULL)
{
AnimationStepResult_T result = Current_Foreground_Animation->NextStep();
if (result == ANIMATION_COMPLETE)
{
Current_Foreground_Animation = NULL;
}
}
else if (Current_Background_Animation != NULL)
{
AnimationStepResult_T result = Current_Background_Animation->NextStep();
if (result == ANIMATION_COMPLETE)
{
Current_Background_Animation = NULL;
}
}
// The animation has conigured all the colors. Now send them to the NeoPixels.
HW_NeoPixels_Publish();
vTaskDelayUntil(&xLastWakeTime, Animation_Delay);
}
}

211
NeoPixels/NeoPixels.h Normal file
View file

@ -0,0 +1,211 @@
/*
* 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/>.
*/
/** \file
* \brief This file defines the interface to the NeoPixels used by the KTag system (SystemK).
*
*/
#ifndef NEOPIXELS_H
#define NEOPIXELS_H
#include <stdint.h>
#ifdef ESP_PLATFORM
#include "sdkconfig.h"
#endif // ESP_PLATFORM
#ifdef PSOC_PLATFORM
#include "CONFIG.h"
#endif // PSOC_PLATFORM
#include "Gamma.h"
#include "Sine.h"
#include "Animation.h"
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
typedef enum
{
// The Lil' Bruv and the Little Boy BLuE only have one NeoPixel channel.
NEOPIXEL_CHANNEL_BARREL = 0,
NEOPIXEL_CHANNEL_RECEIVER = 0,
NEOPIXEL_CHANNEL_DISPLAY = 0,
NEOPIXEL_CHANNEL_EFFECTS = 0,
NEOPIXEL_CHANNEL_ALL = 100,
NEOPIXEL_CHANNEL_NONE = 200
} NeoPixelsChannel_T;
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
typedef enum
{
// The 2020TPC and the 32ESPecial have four NeoPixel channels.
NEOPIXEL_CHANNEL_BARREL = 0,
NEOPIXEL_CHANNEL_RECEIVER = 1,
NEOPIXEL_CHANNEL_DISPLAY = 2,
NEOPIXEL_CHANNEL_EFFECTS = 3,
NEOPIXEL_CHANNEL_ALL = 100,
NEOPIXEL_CHANNEL_NONE = 200
} NeoPixelsChannel_T;
#else
#error "Unsupported number of NeoPixel channels defined. Supported configurations are 1 and 4."
#endif
#include "NeoPixel_HW_Interface.h"
#include "Animations/All_Off.h"
#include "Animations/All_On.h"
#include "Animations/BLE_Nearby.h"
#include "Animations/BLE_RSSI.h"
#include "Animations/Countdown.h"
#include "Animations/Flamethrower.h"
#include "Animations/Flashlight.h"
#include "Animations/Health_Report.h"
#include "Animations/Idle_Animation.h"
#include "Animations/Menu_Animation.h"
#include "Animations/Shot_Fired.h"
#include "Animations/Tag_Received.h"
#include "Animations/Tagged_Out.h"
#include "Animations/Team_Colors.h"
#include "Animations/Test_Pattern.h"
extern QueueHandle_t xQueueNeoPixels;
extern TaskHandle_t NeoPixels_Task_Handle;
extern SemaphoreHandle_t NeoPixels_Semaphore;
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 1)
#include "Single_Channel_Helpers.h"
#elif (CONFIG_KTAG_N_NEOPIXEL_CHANNELS == 4)
#include "Four_Channel_Helpers.h"
#else
#error "Unsupported number of NeoPixel channels defined. Supported configurations are 1 and 4."
#endif
typedef enum
{
COLOR_ORDER_RGB = 0,
COLOR_ORDER_RBG = 1,
COLOR_ORDER_GRB = 2,
COLOR_ORDER_GBR = 3,
COLOR_ORDER_BRG = 4,
COLOR_ORDER_BGR = 5
} ColorOrder_T;
typedef enum
{
DISPLAY_STYLE_DEFAULT = 0,
DISPLAY_STYLE_SOLID = 1,
DISPLAY_STYLE_ALTERNATE = 2,
DISPLAY_STYLE_BLINK = 3,
DISPLAY_STYLE_HEARTBEAT = 4,
//-----------------------------------------------
FIRST_DISPLAY_STYLE = DISPLAY_STYLE_DEFAULT,
LAST_DISPLAY_STYLE = DISPLAY_STYLE_HEARTBEAT
} DisplayStyle_T;
typedef enum
{
NEOPIXELS_ALL_OFF,
NEOPIXELS_ALL_ON,
NEOPIXELS_TEST_PATTERN,
NEOPIXELS_PLAY_SHOT_FIRED,
NEOPIXELS_FLASHLIGHT_ON,
NEOPIXELS_FLAMETHROWER,
NEOPIXELS_TAG_RECEIVED,
NEOPIXELS_TAGGED_OUT,
NEOPIXELS_MENU,
NEOPIXELS_HEALTH_REPORT,
NEOPIXELS_BLE_RSSI,
NEOPIXELS_IDLE,
NEOPIXELS_COUNTDOWN,
//! For #NEOPIXELS_TEAM_COLORS, #NeoPixelsAction_T::Data is a #DisplayStyle_T.
NEOPIXELS_TEAM_COLORS,
//! For #NEOPIXELS_TEAM_COLORS, #NeoPixelsAction_T::Data is a #BLENearby_T.
NEOPIXELS_BLE_NEARBY
} NeoPixelsActionID_T;
typedef enum
{
NEOPIXELS_FOREGROUND,
NEOPIXELS_BACKGROUND,
} NeoPixelsProminence_T;
typedef struct
{
NeoPixelsActionID_T ID;
NeoPixelsProminence_T Prominence;
void * Data;
} NeoPixelsAction_T;
typedef struct
{
color_t color;
DisplayStyle_T style;
} All_On_Data_T;
void NeoPixels_Task(void * pvParameters);
static inline __attribute__((always_inline)) void NeoPixels_Set_Color(NeoPixelsChannel_T channel, uint8_t position, color_t color)
{
HW_NeoPixels_Set_RGB(channel, position, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
}
static inline void NeoPixel_Set_Range(NeoPixelsChannel_T channel, uint8_t start, uint8_t end, uint8_t red, uint8_t green ,uint8_t blue)
{
for (uint_fast8_t position = start; position <= end; position++)
{
HW_NeoPixels_Set_RGB(channel, position, red, green, blue);
}
}
static inline __attribute__((always_inline)) void NeoPixels_Set_Color_Range(NeoPixelsChannel_T channel, uint8_t start, uint8_t end, color_t color)
{
NeoPixel_Set_Range(channel, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
}
static inline __attribute__((always_inline)) void NeoPixels_Set_Color_Range_On_All_Channels(uint8_t start, uint8_t end, color_t color)
{
#if (CONFIG_KTAG_N_NEOPIXEL_CHANNELS > 1)
NeoPixel_Set_Range(NEOPIXEL_CHANNEL_BARREL, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
NeoPixel_Set_Range(NEOPIXEL_CHANNEL_RECEIVER, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
NeoPixel_Set_Range(NEOPIXEL_CHANNEL_DISPLAY, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
NeoPixel_Set_Range(NEOPIXEL_CHANNEL_EFFECTS, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
#else // (CONFIG_KTAG_N_NEOPIXEL_CHANNELS > 1)
NeoPixel_Set_Range(NEOPIXEL_CHANNEL_BARREL, start, end, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
#endif // (CONFIG_KTAG_N_NEOPIXEL_CHANNELS > 1)
}
static inline __attribute__((always_inline)) DisplayStyle_T NeoPixels_ToDisplayStyle(void * value)
{
DisplayStyle_T result = FIRST_DISPLAY_STYLE;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
if (((DisplayStyle_T)value >= FIRST_DISPLAY_STYLE) && ((DisplayStyle_T)value <= LAST_DISPLAY_STYLE))
{
result = (DisplayStyle_T)value;
}
#pragma GCC diagnostic pop
return result;
}
#endif // NEOPIXELS_H

42
NeoPixels/Sine.c Normal file
View file

@ -0,0 +1,42 @@
/*
* 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 <stdint.h>
#include "Sine.h"
const uint_fast8_t Sine8[] = {
0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9,
10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35,
37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
79, 82, 85, 88, 90, 93, 97,100,103,106,109,112,115,118,121,124,
128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173,
176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215,
218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244,
245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255,
255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246,
245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220,
218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179,
176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131,
128,124,121,118,115,112,109,106,103,100, 97, 93, 90, 88, 85, 82,
79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40,
37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11,
10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0};

28
NeoPixels/Sine.h Normal file
View file

@ -0,0 +1,28 @@
/*
* 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/>.
*/
#ifndef SINE_H
#define SINE_H
extern const uint_fast8_t Sine8[];
#endif // SINE_H

View file

@ -0,0 +1,87 @@
/*
* 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/>.
*/
// '||' || '|| '||''|. TM
// || ... || || || ... .. ... ... .... ...
// || || || ||'''|. ||' '' || || '|. |
// || || || || || || || || '|.|
// .||.....| .||. .||. .||...|' .||. '|..'|. '|
//! Zero-based index of the Barrel Flash NeoPixel in the sequence of NeoPixels.
#define BARREL_FLASH_PIXEL 0
//! Zero-based index of the Heart NeoPixel in the sequence of NeoPixels.
#define HEART_PIXEL 1
//! Zero-based index of the Square NeoPixel in the sequence of NeoPixels.
#define SQUARE_PIXEL 2
//! Zero-based index of the Circle NeoPixel in the sequence of NeoPixels.
#define CIRCLE_PIXEL 3
//! Zero-based index of the Arrow NeoPixel in the sequence of NeoPixels.
#define ARROW_PIXEL 4
//! Sets the color of the Barrel Flash NeoPixel, applying gamma correction.
/*!
* \note The diffused 5mm LEDs (from AdaFruit and Ali Express) for barrel flash have a different color order (RGB vs. GRB)!
*/
static inline __attribute__((always_inline)) void Set_Barrel_Flash(color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, BARREL_FLASH_PIXEL, Gamma8[Red(color)], Gamma8[Green(color)], Gamma8[Blue(color)]);
}
//! Sets the color of the Heart NeoPixel, applying gamma correction.
/*!
* \note The [WS2812B NeoPixels](https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf) use a GRB color order.
*/
static inline __attribute__((always_inline)) void Set_Heart(color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, HEART_PIXEL, Gamma8[Green(color)], Gamma8[Red(color)], Gamma8[Blue(color)]);
}
//! Sets the color of the Square NeoPixel, applying gamma correction.
/*!
* \note The [WS2812B NeoPixels](https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf) use a GRB color order.
*/
static inline __attribute__((always_inline)) void Set_Square(color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, SQUARE_PIXEL, Gamma8[Green(color)], Gamma8[Red(color)], Gamma8[Blue(color)]);
}
//! Sets the color of the Circle NeoPixel, applying gamma correction.
/*!
* \note The [WS2812B NeoPixels](https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf) use a GRB color order.
*/
static inline __attribute__((always_inline)) void Set_Circle(color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, CIRCLE_PIXEL, Gamma8[Green(color)], Gamma8[Red(color)], Gamma8[Blue(color)]);
}
//! Sets the color of the Arrow NeoPixel, applying gamma correction.
/*!
* \note The [WS2812B NeoPixels](https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf) use a GRB color order.
*/
static inline __attribute__((always_inline)) void Set_Arrow(color_t color)
{
HW_NeoPixels_Set_RGB(NEOPIXEL_CHANNEL_BARREL, ARROW_PIXEL, Gamma8[Green(color)], Gamma8[Red(color)], Gamma8[Blue(color)]);
}