@@ -39,11 +39,11 @@ class led_controller {
39
39
void poll () {
40
40
if (charging) {
41
41
if (level < 0 )
42
- fill_breath ();
42
+ fill_breath (); // always fill_breath during the idle state of manual charege
43
43
else
44
44
fill_charging (level);
45
45
} else {
46
- fill (CRGB{CRGB::Black} );
46
+ fill (status_color );
47
47
}
48
48
FastLED.show ();
49
49
++counter;
@@ -54,6 +54,10 @@ class led_controller {
54
54
this ->charging = enable;
55
55
this ->level = level;
56
56
}
57
+
58
+ void set_led_status (CRGB color) {
59
+ status_color = color;
60
+ }
57
61
private:
58
62
void fill (const CRGB &color) {
59
63
for (auto &i : led)
@@ -84,13 +88,14 @@ class led_controller {
84
88
percent = counter * 100 / thres;
85
89
else
86
90
percent = (thres * 2 - counter) * 100 / thres;
87
- CRGB color{CRGB::OrangeRed };
91
+ CRGB color{status_color };
88
92
for (auto &i : color.raw )
89
93
i = i * percent / 100 ;
90
94
fill (color);
91
95
}
92
96
static constexpr uint32_t NUM_LEDS{45 };
93
97
CRGB led[NUM_LEDS];
98
+ CRGB status_color{CRGB::Green}; // Green at startup
94
99
uint32_t counter{0 };
95
100
int32_t level{0 };
96
101
bool charging{false };
@@ -264,17 +269,20 @@ class power_controller {
264
269
if (elapsed_ms > 10000 ) {
265
270
Serial.println (" heartbeat timeout, stop charging." );
266
271
set_auto_enable (false );
272
+ led.set_led_status (CRGB::Blue);
267
273
}
268
274
if (terminal.is_overheat ()) {
269
275
Serial.println (" terminal overheat, stop charging." );
270
276
set_auto_enable (false );
277
+ led.set_led_status (CRGB::Red);
271
278
}
272
279
}
273
280
if (relay.is_manual_mode ()) {
274
281
auto elapsed_ms{manual_charging_timer.read_ms ()};
275
282
if (elapsed_ms > 7200000 ) {
276
283
Serial.println (" manual charging timeout, stop charging." );
277
284
set_manual_enable (false );
285
+ led.set_led_status (CRGB::HotPink);
278
286
}
279
287
}
280
288
}
@@ -287,6 +295,7 @@ class power_controller {
287
295
relay.set_enable (true , CHARGING_MODE::AUTO);
288
296
led.set_charging (true , level);
289
297
fan.set_charging (true );
298
+ led.set_led_status (CRGB::Green); // back to default color when enabled
290
299
} else {
291
300
relay.set_enable (false );
292
301
led.set_charging (false );
@@ -301,6 +310,7 @@ class power_controller {
301
310
if (enable) {
302
311
manual_charging_timer.reset ();
303
312
manual_charging_timer.start ();
313
+ led.set_led_status (CRGB::Green); // back to default color when enabled
304
314
} else {
305
315
manual_charging_timer.stop ();
306
316
manual_charging_timer.reset ();
@@ -336,10 +346,14 @@ class charging_board {
336
346
sw.poll ();
337
347
power.poll ();
338
348
auto sw_state{sw.get_state ()};
339
- if (sw_state == manual_switch::STATE::PUSHED)
349
+ if (sw_state == manual_switch::STATE::PUSHED) {
340
350
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) {
342
354
power.set_manual_enable (false );
355
+ Serial.println (" Auto Charge" );
356
+ }
343
357
sw.set_led (power.get_manual_enable ());
344
358
while (Serial1.available ()) {
345
359
if (irda_timer.read_ms () > 1000 )
0 commit comments