87 lines
2.7 KiB
C
87 lines
2.7 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 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
|
|
};
|