mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Remove unreachable RGB function
This commit is contained in:
parent
b6d7217036
commit
d14af30028
4 changed files with 37 additions and 99 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "src/communication/can/comm_can.h"
|
||||
#include "src/communication/contactorcontrol/comm_contactorcontrol.h"
|
||||
#include "src/communication/equipmentstopbutton/comm_equipmentstopbutton.h"
|
||||
|
@ -19,6 +20,7 @@
|
|||
#include "src/devboard/utils/events.h"
|
||||
#include "src/devboard/utils/led_handler.h"
|
||||
#include "src/devboard/utils/logging.h"
|
||||
#include "src/devboard/utils/timer.h"
|
||||
#include "src/devboard/utils/value_mapping.h"
|
||||
#include "src/include.h"
|
||||
#include "src/lib/YiannisBourkelis-Uptime-Library/src/uptime.h"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "../../datalayer/datalayer.h"
|
||||
#include "../../include.h"
|
||||
#include "events.h"
|
||||
#include "timer.h"
|
||||
#include "value_mapping.h"
|
||||
|
||||
#define COLOR_GREEN(x) (((uint32_t)0 << 16) | ((uint32_t)x << 8) | 0)
|
||||
|
@ -30,58 +29,43 @@ led_color led_get_color() {
|
|||
}
|
||||
|
||||
void LED::exe(void) {
|
||||
// Don't run too often
|
||||
if (!timer.elapsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
// Update brightness
|
||||
switch (mode) {
|
||||
case led_mode::FLOW:
|
||||
flow_run();
|
||||
break;
|
||||
case led_mode::HEARTBEAT:
|
||||
heartbeat_run();
|
||||
break;
|
||||
case led_mode::CLASSIC:
|
||||
default:
|
||||
case LED_NORMAL:
|
||||
// Update brightness
|
||||
switch (mode) {
|
||||
case led_mode::FLOW:
|
||||
flow_run();
|
||||
break;
|
||||
case led_mode::HEARTBEAT:
|
||||
heartbeat_run();
|
||||
break;
|
||||
case led_mode::CLASSIC:
|
||||
default:
|
||||
classic_run();
|
||||
break;
|
||||
}
|
||||
|
||||
// Set color
|
||||
switch (get_event_level()) {
|
||||
case EVENT_LEVEL_INFO:
|
||||
color = led_color::GREEN;
|
||||
pixels.setPixelColor(0, COLOR_GREEN(brightness)); // Green pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_WARNING:
|
||||
color = led_color::YELLOW;
|
||||
pixels.setPixelColor(0, COLOR_YELLOW(brightness)); // Yellow pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_DEBUG:
|
||||
case EVENT_LEVEL_UPDATE:
|
||||
color = led_color::BLUE;
|
||||
pixels.setPixelColor(0, COLOR_BLUE(brightness)); // Blue pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_ERROR:
|
||||
color = led_color::RED;
|
||||
pixels.setPixelColor(0, COLOR_RED(LED_MAX_BRIGHTNESS)); // Red LED full brightness
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LED_COMMAND:
|
||||
break;
|
||||
case LED_RGB:
|
||||
rainbow_run();
|
||||
classic_run();
|
||||
break;
|
||||
}
|
||||
|
||||
// Set color
|
||||
switch (get_event_level()) {
|
||||
case EVENT_LEVEL_INFO:
|
||||
color = led_color::GREEN;
|
||||
pixels.setPixelColor(0, COLOR_GREEN(brightness)); // Green pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_WARNING:
|
||||
color = led_color::YELLOW;
|
||||
pixels.setPixelColor(0, COLOR_YELLOW(brightness)); // Yellow pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_DEBUG:
|
||||
case EVENT_LEVEL_UPDATE:
|
||||
color = led_color::BLUE;
|
||||
pixels.setPixelColor(0, COLOR_BLUE(brightness)); // Blue pulsing LED
|
||||
break;
|
||||
case EVENT_LEVEL_ERROR:
|
||||
color = led_color::RED;
|
||||
pixels.setPixelColor(0, COLOR_RED(LED_MAX_BRIGHTNESS)); // Red LED full brightness
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||
}
|
||||
|
||||
|
@ -133,7 +117,7 @@ void LED::heartbeat_run(void) {
|
|||
} else if (period_pct < 0.25) {
|
||||
brightness_f = map_float(period_pct, 0.20f, 0.25f, heartbeat_base - heartbeat_deviation * 2, heartbeat_peak1);
|
||||
} else if (period_pct < 0.30) {
|
||||
brightness_f = map_float(period_pct, 0.25f, 0.30f, heartbeat_peak1, heartbeat_base - heartbeat_deviation);
|
||||
brightness_f = map_floaled_exet(period_pct, 0.25f, 0.30f, heartbeat_peak1, heartbeat_base - heartbeat_deviation);
|
||||
} else if (period_pct < 0.40) {
|
||||
brightness_f = map_float(period_pct, 0.30f, 0.40f, heartbeat_base - heartbeat_deviation, heartbeat_peak2);
|
||||
} else if (period_pct < 0.55) {
|
||||
|
@ -145,39 +129,6 @@ void LED::heartbeat_run(void) {
|
|||
brightness = (uint8_t)(brightness_f * LED_MAX_BRIGHTNESS);
|
||||
}
|
||||
|
||||
void LED::rainbow_run(void) {
|
||||
brightness = LED_MAX_BRIGHTNESS / 2;
|
||||
|
||||
uint16_t ms = (uint16_t)(millis() % LED_PERIOD_MS);
|
||||
float value = ((float)ms) / LED_PERIOD_MS;
|
||||
|
||||
// Clamp the input value to the range [0.0, 1.0]
|
||||
value = value < 0.0f ? 0.0f : value;
|
||||
value = value > 1.0f ? 1.0f : value;
|
||||
|
||||
uint8_t r = 0, g = 0, b = 0;
|
||||
|
||||
// Scale the value to the range [0, 3), which will be used to transition through the colors
|
||||
float scaledValue = value * 3.0f;
|
||||
|
||||
if (scaledValue < 1.0f) {
|
||||
// From red to green
|
||||
r = static_cast<uint8_t>((1.0f - scaledValue) * brightness);
|
||||
g = static_cast<uint8_t>((scaledValue - 0.0f) * brightness);
|
||||
} else if (scaledValue < 2.0f) {
|
||||
// From green to blue
|
||||
g = static_cast<uint8_t>((2.0f - scaledValue) * brightness);
|
||||
b = static_cast<uint8_t>((scaledValue - 1.0f) * brightness);
|
||||
} else {
|
||||
// From blue back to red
|
||||
b = static_cast<uint8_t>((3.0f - scaledValue) * brightness);
|
||||
r = static_cast<uint8_t>((scaledValue - 2.0f) * brightness);
|
||||
}
|
||||
|
||||
// Assemble the color
|
||||
pixels.setPixelColor(0, pixels.Color(r, g, b)); // RGB
|
||||
}
|
||||
|
||||
uint8_t LED::up_down(float middle_point_f) {
|
||||
// Determine how bright the LED should be
|
||||
middle_point_f = CONSTRAIN(middle_point_f, 0.0f, 1.0f);
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include "../../include.h"
|
||||
#include "../../lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"
|
||||
#include "timer.h"
|
||||
|
||||
enum led_mode { CLASSIC, FLOW, HEARTBEAT };
|
||||
enum led_state { LED_NORMAL, LED_COMMAND, LED_RGB };
|
||||
|
||||
class LED {
|
||||
public:
|
||||
|
@ -16,17 +14,13 @@ class LED {
|
|||
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
|
||||
max_brightness(LED_MAX_BRIGHTNESS),
|
||||
brightness(LED_MAX_BRIGHTNESS),
|
||||
mode(led_mode::CLASSIC),
|
||||
state(LED_NORMAL),
|
||||
timer(LED_EXECUTION_FREQUENCY) {}
|
||||
mode(led_mode::CLASSIC) {}
|
||||
|
||||
LED(led_mode mode)
|
||||
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
|
||||
max_brightness(LED_MAX_BRIGHTNESS),
|
||||
brightness(LED_MAX_BRIGHTNESS),
|
||||
mode(mode),
|
||||
state(LED_NORMAL),
|
||||
timer(LED_EXECUTION_FREQUENCY) {}
|
||||
mode(mode) {}
|
||||
|
||||
void exe(void);
|
||||
void init(void) { pixels.begin(); }
|
||||
|
@ -36,12 +30,9 @@ class LED {
|
|||
uint8_t max_brightness;
|
||||
uint8_t brightness;
|
||||
led_mode mode;
|
||||
led_state state = LED_NORMAL;
|
||||
MyTimer timer;
|
||||
|
||||
void classic_run(void);
|
||||
void flow_run(void);
|
||||
void rainbow_run(void);
|
||||
void heartbeat_run(void);
|
||||
|
||||
uint8_t up_down(float middle_point_f);
|
||||
|
|
|
@ -50,14 +50,8 @@
|
|||
* Description:
|
||||
* The period of whatever LED mode is active. If CLASSIC, then a ramp up and ramp down will finish in
|
||||
* LED_PERIOD_MS milliseconds
|
||||
*
|
||||
* Parameter: LED_EXECUTION_FREQUENCY
|
||||
* Description:
|
||||
* Defines how often the LED handling will run, basically the FPS. The animation will honor its overall
|
||||
* frequency but the animation will be choppier
|
||||
*/
|
||||
#define LED_MODE_DEFAULT FLOW
|
||||
#define LED_PERIOD_MS 3000
|
||||
#define LED_EXECUTION_FREQUENCY 50
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue