Skip to content

Commit f20b111

Browse files
committed
feat: add cyberpunk Data Drop idle animation
- Integrate the Cyberpunk-themed Data Drop LED idle animation - Remove other selectable idle styles and their configuration settings from web interface and backend
1 parent c051c40 commit f20b111

4 files changed

Lines changed: 77 additions & 90 deletions

File tree

‎src/Led.cpp‎

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ AnimationReturnType Animation_VoltageWarning(const bool startNewAnimation, CRGBS
830830
AnimationReturnType Animation_Webstream(const bool startNewAnimation, CRGBSet &leds) {
831831
// return values
832832
bool animationActive = false;
833-
bool refresh = false;
833+
bool animationRefresh = false;
834834
int32_t animationDelay = 0;
835835
// static vars
836836
static uint8_t ledPosWebstream = 0;
@@ -852,7 +852,7 @@ AnimationReturnType Animation_Webstream(const bool startNewAnimation, CRGBSet &l
852852
}
853853
animationDelay = 10;
854854
timerProgress = 0; // directly show new animation after pause
855-
refresh = true;
855+
animationRefresh = true;
856856
} else {
857857
if (startNewAnimation || timerProgress == 0) {
858858
leds = CRGB::Black;
@@ -880,15 +880,15 @@ AnimationReturnType Animation_Webstream(const bool startNewAnimation, CRGBSet &l
880880
}
881881
}
882882
}
883-
refresh = true;
883+
animationRefresh = true;
884884
}
885885
timerProgress--;
886886
animationDelay = 45;
887887
if (timerProgress > 0) {
888888
animationActive = true;
889889
}
890890
}
891-
return AnimationReturnType(animationActive, animationDelay, refresh);
891+
return AnimationReturnType(animationActive, animationDelay, animationRefresh);
892892
}
893893

894894
// --------------------------------
@@ -897,7 +897,7 @@ AnimationReturnType Animation_Webstream(const bool startNewAnimation, CRGBSet &l
897897
AnimationReturnType Animation_Rewind(const bool startNewAnimation, CRGBSet &leds) {
898898
// return values
899899
bool animationActive = false;
900-
bool refresh = false;
900+
bool animationRefresh = false;
901901
int32_t animationDelay = 0;
902902
// static vars
903903
static uint16_t animationIndex = 0;
@@ -910,48 +910,44 @@ AnimationReturnType Animation_Rewind(const bool startNewAnimation, CRGBSet &leds
910910

911911
if (animationIndex < (leds.size())) {
912912
leds[Led_Address(leds.size() - 1 - animationIndex)] = CRGB::Black;
913-
refresh = true;
913+
animationRefresh = true;
914914
animationDelay = 30;
915915
animationIndex++;
916916
} else {
917917
animationActive = false;
918918
}
919919
}
920-
return AnimationReturnType(animationActive, animationDelay, refresh);
920+
return AnimationReturnType(animationActive, animationDelay, animationRefresh);
921921
}
922922

923923
// --------------------------------
924924
// Idle Animation
925925
// --------------------------------
926926
AnimationReturnType Animation_Idle(const bool startNewAnimation, CRGBSet &leds) {
927927
// return values
928-
int32_t animationDelay = 0;
928+
int32_t animationDelay = 120;
929929
bool animationActive = true;
930-
bool refresh = true;
930+
bool animationRefresh = true;
931+
931932
// static vars
932-
static int16_t ledIndex = 0;
933-
// this can be removed to always continue on the last position in idle
933+
static int16_t step = 0;
934+
934935
if (startNewAnimation) {
935-
ledIndex = 0;
936+
step = 0;
936937
}
937938

938-
if (ledIndex < leds.size()) {
939-
CRGB::HTMLColorCode idleColor = Led_GetIdleColor();
940-
leds = CRGB::Black;
941-
Led_DrawIdleDots(leds, ledIndex, idleColor);
942-
if (OPMODE_BLUETOOTH_SOURCE == System_GetOperationMode()) {
943-
// animate a bit faster in BT-Source to distinguish between the bluetooth modes
944-
animationDelay = 30 * 10;
945-
} else {
946-
animationDelay = 50 * 10;
939+
CRGB idleColor = (CRGB)Led_GetIdleColor();
940+
941+
leds.fadeToBlackBy(40);
942+
if (leds.size() > 0) {
943+
int16_t idx = (leds.size() - 1) - (step % leds.size());
944+
if (idx >= 0 && idx < leds.size()) {
945+
leds[idx] = idleColor;
947946
}
948-
ledIndex++;
949-
} else {
950-
animationActive = false;
951-
refresh = false;
952-
ledIndex = 0;
947+
step = (step + 1) % leds.size();
953948
}
954-
return AnimationReturnType(animationActive, animationDelay, refresh);
949+
950+
return AnimationReturnType(animationActive, animationDelay, animationRefresh);
955951
}
956952

957953
// --------------------------------
@@ -1245,7 +1241,7 @@ AnimationReturnType Animation_PlaylistProgress(const bool startNewAnimation, CRG
12451241
AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, CRGBSet &leds) {
12461242
// return-values
12471243
static bool animationActive = false;
1248-
bool refresh = false;
1244+
bool animationRefresh = false;
12491245
int32_t animationDelay = 0;
12501246
// static variables for animation
12511247
static float staticBatteryLevel = 0.0f; // variable to store the measured battery-voltage
@@ -1267,7 +1263,7 @@ AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, C
12671263
filledLedCount = 0;
12681264
animationActive = true;
12691265
leds = CRGB::Black;
1270-
refresh = true;
1266+
animationRefresh = true;
12711267
}
12721268
if (gLedSettings.numIndicatorLeds == 1) {
12731269
if (staticBatteryLevel < 0.3) {
@@ -1277,7 +1273,7 @@ AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, C
12771273
} else {
12781274
leds[0] = CRGB::Green;
12791275
}
1280-
refresh = true;
1276+
animationRefresh = true;
12811277

12821278
animationDelay = 20 * 100;
12831279
animationActive = false;
@@ -1293,7 +1289,7 @@ AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, C
12931289
} else {
12941290
leds[Led_Address(filledLedCount)] = CRGB::Green;
12951291
}
1296-
refresh = true;
1292+
animationRefresh = true;
12971293

12981294
filledLedCount++;
12991295
animationDelay = 20;
@@ -1302,7 +1298,7 @@ AnimationReturnType Animation_BatteryMeasurement(const bool startNewAnimation, C
13021298
animationActive = false;
13031299
}
13041300
}
1305-
return AnimationReturnType(animationActive, animationDelay, refresh);
1301+
return AnimationReturnType(animationActive, animationDelay, animationRefresh);
13061302
}
13071303
#endif
13081304

‎src/Led.h‎

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,32 @@ typedef enum class LedIndicator {
1212
} LedIndicatorType;
1313

1414
// ordered by priority
15-
enum class LedAnimationType {
16-
Boot = 0,
15+
enum class LedAnimationType : uint8_t {
16+
None = 0,
17+
Boot,
1718
Shutdown,
1819
Error,
1920
Ok,
2021
VoltageWarning,
2122
Volume,
23+
Battery,
2224
BatteryMeasurement,
25+
Webstream,
2326
Rewind,
2427
Playlist,
25-
Speech,
26-
Pause,
2728
Progress,
28-
Webstream,
2929
Idle,
3030
Busy,
31+
Speech,
32+
Pause,
3133
NoNewAnimation
3234
};
3335

34-
enum class LedPlaylistProgressStates {
35-
FillBar = 0,
36-
Wait,
37-
EmptyBar,
38-
EmptyBarToTarget,
39-
Done
40-
};
41-
42-
struct AnimationReturnType {
43-
bool animationActive;
36+
typedef struct {
37+
bool animationActive : 1;
4438
int32_t animationDelay;
45-
bool animationRefresh;
46-
47-
void clear() {
48-
animationActive = false;
49-
animationDelay = 0;
50-
}
51-
AnimationReturnType()
52-
: animationActive(false)
53-
, animationDelay(0)
54-
, animationRefresh(false) { }
55-
AnimationReturnType(bool active, int32_t delay, bool refresh = false)
56-
: animationActive(active)
57-
, animationDelay(delay)
58-
, animationRefresh(refresh) { }
59-
};
39+
bool animationRefresh : 1;
40+
} AnimationReturnType;
6041

6142
#ifdef NEOPIXEL_ENABLE
6243
#define LED_INITIAL_BRIGHTNESS 16u
@@ -66,28 +47,40 @@ struct AnimationReturnType {
6647

6748
#include <FastLED.h>
6849

69-
struct LedSettings {
70-
uint8_t numIndicatorLeds = NUM_INDICATOR_LEDS;
71-
uint8_t numControlLeds = NUM_CONTROL_LEDS;
72-
std::vector<uint32_t> controlLedColors;
73-
uint8_t numIdleDots = NUM_LEDS_IDLE_DOTS;
74-
uint32_t idleColor = IDLE_COLOR;
75-
bool offsetLedPause = OFFSET_PAUSE_LEDS;
76-
uint32_t progressColorStart = PROGRESS_COLOR_START;
77-
uint32_t progressColorEnd = PROGRESS_COLOR_END;
78-
int16_t atmoHue = ATMO_HUE;
79-
int16_t atmoSaturation = ATMO_SATURATION;
80-
uint8_t dimmableStates = DIMMABLE_STATES;
81-
bool neopixelReverseRotation;
82-
uint8_t ledOffset;
83-
bool Led_Pause = false; // Used to pause Neopixel-signalisation (while NVS-writes as this leads to exceptions; don't know why)
84-
bool Led_NightMode = false;
85-
bool Led_AmbientLight = false;
86-
uint8_t Led_InitialBrightness = LED_INITIAL_BRIGHTNESS;
87-
uint8_t Led_Brightness = LED_INITIAL_BRIGHTNESS;
88-
uint8_t Led_NightBrightness = LED_INITIAL_NIGHT_BRIGHTNESS;
89-
uint8_t Led_AmbientBrightness = LED_INITIAL_BRIGHTNESS;
90-
};
50+
enum class LedPlaylistProgressStates : uint8_t {
51+
FillBar = 0,
52+
Wait,
53+
EmptyBar,
54+
EmptyBarToTarget,
55+
Done
56+
};
57+
58+
struct LedSettings {
59+
uint8_t numIndicatorLeds = NUM_INDICATOR_LEDS;
60+
uint8_t numControlLeds = NUM_CONTROL_LEDS;
61+
std::vector<uint32_t> controlLedColors;
62+
uint8_t numIdleDots = NUM_LEDS_IDLE_DOTS;
63+
uint32_t idleColor = IDLE_COLOR;
64+
bool offsetLedPause = OFFSET_PAUSE_LEDS;
65+
uint32_t progressColorStart = PROGRESS_COLOR_START;
66+
uint32_t progressColorEnd = PROGRESS_COLOR_END;
67+
int16_t atmoHue = ATMO_HUE;
68+
int16_t atmoSaturation = ATMO_SATURATION;
69+
uint8_t dimmableStates = DIMMABLE_STATES;
70+
bool neopixelReverseRotation;
71+
uint8_t ledOffset;
72+
bool Led_Pause;
73+
74+
bool Led_NightMode = false;
75+
bool Led_AmbientLight = false;
76+
uint8_t Led_InitialBrightness = LED_INITIAL_BRIGHTNESS;
77+
uint8_t Led_Brightness = LED_INITIAL_BRIGHTNESS;
78+
uint8_t Led_NightBrightness = LED_INITIAL_NIGHT_BRIGHTNESS;
79+
uint8_t Led_AmbientBrightness = LED_INITIAL_BRIGHTNESS;
80+
};
81+
82+
bool Led_GetNightmode();
83+
bool Led_GetAmbientLight();
9184
#endif
9285

9386
void Led_Init(void);
@@ -102,8 +95,6 @@ void Led_TaskPause(void);
10295
void Led_TaskResume(void);
10396

10497
void Led_SetNightmode(bool enabled);
105-
bool Led_GetNightmode();
10698
void Led_ToggleNightmode();
10799
void Led_SetAmbientLight(bool enabled);
108-
bool Led_GetAmbientLight();
109100
void Led_ToggleAmbientLight();

‎src/Web.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,9 @@ static void settingsToJSON(JsonObject obj, const String section) {
10961096
ledObj["numControl"].set(numControlLeds);
10971097
if (numControlLeds > 0) {
10981098
// get control led colors from NVS
1099-
std::vector<CRGB::HTMLColorCode> controlLedColors = CONTROL_LEDS_COLORS;
1099+
std::vector<uint32_t> controlLedColors = CONTROL_LEDS_COLORS;
11001100
size_t keySize = gPrefsSettings.getBytesLength("controlColors");
1101-
if (keySize == (numControlLeds * sizeof(CRGB::HTMLColorCode))) {
1101+
if (keySize == (numControlLeds * sizeof(uint32_t))) {
11021102
controlLedColors.resize(numControlLeds);
11031103
gPrefsSettings.getBytes("controlColors", controlLedColors.data(), keySize);
11041104
}
@@ -1237,7 +1237,7 @@ static void settingsToJSON(JsonObject obj, const String section) {
12371237
ledSettings["offsetStart"].set(0);
12381238
#endif
12391239
JsonArray colorArr = ledSettings["controlColors"].to<JsonArray>();
1240-
std::vector<CRGB::HTMLColorCode> controlLedColors = CONTROL_LEDS_COLORS;
1240+
std::vector<uint32_t> controlLedColors = CONTROL_LEDS_COLORS;
12411241
for (uint8_t controlLed = 0; controlLed < controlLedColors.size(); controlLed++) {
12421242
colorArr.add(controlLedColors[controlLed]);
12431243
}

‎src/settings.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
#define CHIPSET WS2812B // type of Neopixel
220220
#define COLOR_ORDER GRB
221221
#define NUM_LEDS_IDLE_DOTS 4 // count of LEDs, which are shown when Idle
222-
#define IDLE_COLOR CRGB::White // color of the idle dots
222+
#define IDLE_COLOR 0xFFFFFF // color of the idle dots
223223
#define OFFSET_PAUSE_LEDS false // if true the pause-leds are centered in the mid of the LED-Strip
224224
#define PROGRESS_COLOR_START 0x00FF00 // start color of the progress bar
225225
#define PROGRESS_COLOR_END 0xFF0000 // end color of the progress bar

0 commit comments

Comments
 (0)