164 lines
5.5 KiB
C
164 lines
5.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"
|
|
|
|
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);
|
|
}
|
|
}
|