Skip to content

Commit be83821

Browse files
authored
Merge pull request #7 from LexxPluss/feature/led_status
Feature/led status for FastCharge
2 parents cf0cae8 + cbd6502 commit be83821

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lexxpluss_main.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class led_controller {
3939
void poll() {
4040
if (charging) {
4141
if (level < 0)
42-
fill_breath();
42+
fill_breath(); //always fill_breath during the idle state of manual charege
4343
else
4444
fill_charging(level);
4545
} else {
46-
fill(CRGB{CRGB::Black});
46+
fill(status_color);
4747
}
4848
FastLED.show();
4949
++counter;
@@ -54,6 +54,10 @@ class led_controller {
5454
this->charging = enable;
5555
this->level = level;
5656
}
57+
58+
void set_led_status(CRGB color) {
59+
status_color = color;
60+
}
5761
private:
5862
void fill(const CRGB &color) {
5963
for (auto &i : led)
@@ -84,13 +88,14 @@ class led_controller {
8488
percent = counter * 100 / thres;
8589
else
8690
percent = (thres * 2 - counter) * 100 / thres;
87-
CRGB color{CRGB::OrangeRed};
91+
CRGB color{status_color};
8892
for (auto &i : color.raw)
8993
i = i * percent / 100;
9094
fill(color);
9195
}
9296
static constexpr uint32_t NUM_LEDS{45};
9397
CRGB led[NUM_LEDS];
98+
CRGB status_color{CRGB::Green}; //Green at startup
9499
uint32_t counter{0};
95100
int32_t level{0};
96101
bool charging{false};
@@ -264,17 +269,20 @@ class power_controller {
264269
if (elapsed_ms > 10000) {
265270
Serial.println("heartbeat timeout, stop charging.");
266271
set_auto_enable(false);
272+
led.set_led_status(CRGB::Blue);
267273
}
268274
if (terminal.is_overheat()) {
269275
Serial.println("terminal overheat, stop charging.");
270276
set_auto_enable(false);
277+
led.set_led_status(CRGB::Red);
271278
}
272279
}
273280
if (relay.is_manual_mode()) {
274281
auto elapsed_ms{manual_charging_timer.read_ms()};
275282
if (elapsed_ms > 7200000) {
276283
Serial.println("manual charging timeout, stop charging.");
277284
set_manual_enable(false);
285+
led.set_led_status(CRGB::HotPink);
278286
}
279287
}
280288
}
@@ -287,6 +295,7 @@ class power_controller {
287295
relay.set_enable(true, CHARGING_MODE::AUTO);
288296
led.set_charging(true, level);
289297
fan.set_charging(true);
298+
led.set_led_status(CRGB::Green); //back to default color when enabled
290299
} else {
291300
relay.set_enable(false);
292301
led.set_charging(false);
@@ -301,6 +310,7 @@ class power_controller {
301310
if (enable) {
302311
manual_charging_timer.reset();
303312
manual_charging_timer.start();
313+
led.set_led_status(CRGB::Green); //back to default color when enabled
304314
} else {
305315
manual_charging_timer.stop();
306316
manual_charging_timer.reset();
@@ -336,10 +346,14 @@ class charging_board {
336346
sw.poll();
337347
power.poll();
338348
auto sw_state{sw.get_state()};
339-
if (sw_state == manual_switch::STATE::PUSHED)
349+
if (sw_state == manual_switch::STATE::PUSHED) {
340350
power.set_manual_enable(true);
341-
else if (sw_state == manual_switch::STATE::LONG_PUSHED)
351+
Serial.println("Manual Charge");
352+
}
353+
else if (sw_state == manual_switch::STATE::LONG_PUSHED) {
342354
power.set_manual_enable(false);
355+
Serial.println("Auto Charge");
356+
}
343357
sw.set_led(power.get_manual_enable());
344358
while (Serial1.available()) {
345359
if (irda_timer.read_ms() > 1000)

0 commit comments

Comments
 (0)