Remove unreachable RGB function

This commit is contained in:
Daniel Öster 2025-01-08 18:57:59 +02:00
parent b6d7217036
commit d14af30028
4 changed files with 37 additions and 99 deletions

View file

@ -8,6 +8,7 @@
#include "esp_timer.h" #include "esp_timer.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "src/communication/can/comm_can.h" #include "src/communication/can/comm_can.h"
#include "src/communication/contactorcontrol/comm_contactorcontrol.h" #include "src/communication/contactorcontrol/comm_contactorcontrol.h"
#include "src/communication/equipmentstopbutton/comm_equipmentstopbutton.h" #include "src/communication/equipmentstopbutton/comm_equipmentstopbutton.h"
@ -19,6 +20,7 @@
#include "src/devboard/utils/events.h" #include "src/devboard/utils/events.h"
#include "src/devboard/utils/led_handler.h" #include "src/devboard/utils/led_handler.h"
#include "src/devboard/utils/logging.h" #include "src/devboard/utils/logging.h"
#include "src/devboard/utils/timer.h"
#include "src/devboard/utils/value_mapping.h" #include "src/devboard/utils/value_mapping.h"
#include "src/include.h" #include "src/include.h"
#include "src/lib/YiannisBourkelis-Uptime-Library/src/uptime.h" #include "src/lib/YiannisBourkelis-Uptime-Library/src/uptime.h"

View file

@ -2,7 +2,6 @@
#include "../../datalayer/datalayer.h" #include "../../datalayer/datalayer.h"
#include "../../include.h" #include "../../include.h"
#include "events.h" #include "events.h"
#include "timer.h"
#include "value_mapping.h" #include "value_mapping.h"
#define COLOR_GREEN(x) (((uint32_t)0 << 16) | ((uint32_t)x << 8) | 0) #define COLOR_GREEN(x) (((uint32_t)0 << 16) | ((uint32_t)x << 8) | 0)
@ -30,14 +29,7 @@ led_color led_get_color() {
} }
void LED::exe(void) { void LED::exe(void) {
// Don't run too often
if (!timer.elapsed()) {
return;
}
switch (state) {
default:
case LED_NORMAL:
// Update brightness // Update brightness
switch (mode) { switch (mode) {
case led_mode::FLOW: case led_mode::FLOW:
@ -74,14 +66,6 @@ void LED::exe(void) {
default: default:
break; break;
} }
break;
case LED_COMMAND:
break;
case LED_RGB:
rainbow_run();
break;
}
pixels.show(); // This sends the updated pixel color to the hardware. 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) { } else if (period_pct < 0.25) {
brightness_f = map_float(period_pct, 0.20f, 0.25f, heartbeat_base - heartbeat_deviation * 2, heartbeat_peak1); brightness_f = map_float(period_pct, 0.20f, 0.25f, heartbeat_base - heartbeat_deviation * 2, heartbeat_peak1);
} else if (period_pct < 0.30) { } 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) { } else if (period_pct < 0.40) {
brightness_f = map_float(period_pct, 0.30f, 0.40f, heartbeat_base - heartbeat_deviation, heartbeat_peak2); brightness_f = map_float(period_pct, 0.30f, 0.40f, heartbeat_base - heartbeat_deviation, heartbeat_peak2);
} else if (period_pct < 0.55) { } else if (period_pct < 0.55) {
@ -145,39 +129,6 @@ void LED::heartbeat_run(void) {
brightness = (uint8_t)(brightness_f * LED_MAX_BRIGHTNESS); 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) { uint8_t LED::up_down(float middle_point_f) {
// Determine how bright the LED should be // Determine how bright the LED should be
middle_point_f = CONSTRAIN(middle_point_f, 0.0f, 1.0f); middle_point_f = CONSTRAIN(middle_point_f, 0.0f, 1.0f);

View file

@ -3,10 +3,8 @@
#include "../../include.h" #include "../../include.h"
#include "../../lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h" #include "../../lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "timer.h"
enum led_mode { CLASSIC, FLOW, HEARTBEAT }; enum led_mode { CLASSIC, FLOW, HEARTBEAT };
enum led_state { LED_NORMAL, LED_COMMAND, LED_RGB };
class LED { class LED {
public: public:
@ -16,17 +14,13 @@ class LED {
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800), : pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
max_brightness(LED_MAX_BRIGHTNESS), max_brightness(LED_MAX_BRIGHTNESS),
brightness(LED_MAX_BRIGHTNESS), brightness(LED_MAX_BRIGHTNESS),
mode(led_mode::CLASSIC), mode(led_mode::CLASSIC) {}
state(LED_NORMAL),
timer(LED_EXECUTION_FREQUENCY) {}
LED(led_mode mode) LED(led_mode mode)
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800), : pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
max_brightness(LED_MAX_BRIGHTNESS), max_brightness(LED_MAX_BRIGHTNESS),
brightness(LED_MAX_BRIGHTNESS), brightness(LED_MAX_BRIGHTNESS),
mode(mode), mode(mode) {}
state(LED_NORMAL),
timer(LED_EXECUTION_FREQUENCY) {}
void exe(void); void exe(void);
void init(void) { pixels.begin(); } void init(void) { pixels.begin(); }
@ -36,12 +30,9 @@ class LED {
uint8_t max_brightness; uint8_t max_brightness;
uint8_t brightness; uint8_t brightness;
led_mode mode; led_mode mode;
led_state state = LED_NORMAL;
MyTimer timer;
void classic_run(void); void classic_run(void);
void flow_run(void); void flow_run(void);
void rainbow_run(void);
void heartbeat_run(void); void heartbeat_run(void);
uint8_t up_down(float middle_point_f); uint8_t up_down(float middle_point_f);

View file

@ -50,14 +50,8 @@
* Description: * Description:
* The period of whatever LED mode is active. If CLASSIC, then a ramp up and ramp down will finish in * The period of whatever LED mode is active. If CLASSIC, then a ramp up and ramp down will finish in
* LED_PERIOD_MS milliseconds * 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_MODE_DEFAULT FLOW
#define LED_PERIOD_MS 3000 #define LED_PERIOD_MS 3000
#define LED_EXECUTION_FREQUENCY 50
#endif #endif