Skip to content

Commit

Permalink
Make LED modes customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat committed Feb 24, 2025
1 parent 6523967 commit 69af825
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
8 changes: 8 additions & 0 deletions Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
// 3000 = 300.0V, Target discharge voltage (Value can be tuned on the fly via webserver). Not used unless BATTERY_USE_VOLTAGE_LIMITS = true
#define BATTERY_MAX_DISCHARGE_VOLTAGE 3000

/* LED settings. Optional customization for how the blinking pattern on the LED should behave.
* CLASSIC - Slow up/down ramp. If CLASSIC, then a ramp up and ramp down will finish in LED_PERIOD_MS milliseconds
* FLOW - Ramp up/down depending on flow of energy
* HEARTBEAT - Heartbeat-like LED pattern that reacts to the system state with color and BPM
*/
#define LED_MODE HEARTBEAT
#define LED_PERIOD_MS 3000

/* Do not change any code below this line */
/* Only change battery specific settings above and in "USER_SETTINGS.cpp" */
typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CANFD_ADDON_MCP2518 = 3 } CAN_Interface;
Expand Down
4 changes: 4 additions & 0 deletions Software/src/datalayer/datalayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ typedef struct {

/** The current battery status, which for now has the name real_bms_status */
real_bms_status_enum real_bms_status = BMS_DISCONNECTED;

/** LED mode, customizable by user */
led_mode_enum led_mode = LED_MODE;

} DATALAYER_BATTERY_STATUS_TYPE;

typedef struct {
Expand Down
10 changes: 5 additions & 5 deletions Software/src/devboard/utils/led_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const float heartbeat_peak1 = 0.80;
static const float heartbeat_peak2 = 0.55;
static const float heartbeat_deviation = 0.05;

static LED led(LED_MODE_DEFAULT);
static LED led(datalayer.battery.status.led_mode);

void led_init(void) {
led.init();
Expand All @@ -31,14 +31,14 @@ led_color led_get_color() {
void LED::exe(void) {

// Update brightness
switch (mode) {
case led_mode::FLOW:
switch (datalayer.battery.status.led_mode) {
case led_mode_enum::FLOW:
flow_run();
break;
case led_mode::HEARTBEAT:
case led_mode_enum::HEARTBEAT:
heartbeat_run();
break;
case led_mode::CLASSIC:
case led_mode_enum::CLASSIC:
default:
classic_run();
break;
Expand Down
8 changes: 3 additions & 5 deletions Software/src/devboard/utils/led_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "../../include.h"
#include "../../lib/adafruit-Adafruit_NeoPixel/Adafruit_NeoPixel.h"

enum led_mode { CLASSIC, FLOW, HEARTBEAT };

class LED {
public:
led_color color = led_color::GREEN;
Expand All @@ -14,9 +12,9 @@ class LED {
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
max_brightness(LED_MAX_BRIGHTNESS),
brightness(LED_MAX_BRIGHTNESS),
mode(led_mode::CLASSIC) {}
mode(led_mode_enum::CLASSIC) {}

LED(led_mode mode)
LED(led_mode_enum mode)
: pixels(1, LED_PIN, NEO_GRB + NEO_KHZ800),
max_brightness(LED_MAX_BRIGHTNESS),
brightness(LED_MAX_BRIGHTNESS),
Expand All @@ -29,7 +27,7 @@ class LED {
Adafruit_NeoPixel pixels;
uint8_t max_brightness;
uint8_t brightness;
led_mode mode;
led_mode_enum mode;

void classic_run(void);
void flow_run(void);
Expand Down
1 change: 1 addition & 0 deletions Software/src/devboard/utils/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum bms_status_enum { STANDBY = 0, INACTIVE = 1, DARKSTART = 2, ACTIVE = 3, FAU
enum real_bms_status_enum { BMS_DISCONNECTED = 0, BMS_STANDBY = 1, BMS_ACTIVE = 2, BMS_FAULT = 3 };
enum battery_chemistry_enum { NCA, NMC, LFP };
enum led_color { GREEN, YELLOW, RED, BLUE };
enum led_mode_enum { CLASSIC, FLOW, HEARTBEAT };
enum PrechargeState {
AUTO_PRECHARGE_IDLE,
AUTO_PRECHARGE_START,
Expand Down
17 changes: 0 additions & 17 deletions Software/src/system_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,4 @@
*/
#define MAX_AMOUNT_CELLS 192

/** LED
*
* Parameter: LED_MODE_DEFAULT
* Description:
* The default LED mode. Available modes:
* CLASSIC - slow up/down ramp
* FLOW - slow ramp up or down depending on flow of energy
* HEARTBEAT - Heartbeat-like LED pattern that reacts to the system state with color and BPM
*
* Parameter: LED_PERIOD_MS
* 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
*/
#define LED_MODE_DEFAULT FLOW
#define LED_PERIOD_MS 3000

#endif

0 comments on commit 69af825

Please sign in to comment.