Skip to content

Commit

Permalink
Merge pull request #7 from LexxPluss/feature/led_status
Browse files Browse the repository at this point in the history
Feature/led status for FastCharge
  • Loading branch information
takurot authored Apr 29, 2024
2 parents cf0cae8 + cbd6502 commit be83821
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lexxpluss_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class led_controller {
void poll() {
if (charging) {
if (level < 0)
fill_breath();
fill_breath(); //always fill_breath during the idle state of manual charege
else
fill_charging(level);
} else {
fill(CRGB{CRGB::Black});
fill(status_color);
}
FastLED.show();
++counter;
Expand All @@ -54,6 +54,10 @@ class led_controller {
this->charging = enable;
this->level = level;
}

void set_led_status(CRGB color) {
status_color = color;
}
private:
void fill(const CRGB &color) {
for (auto &i : led)
Expand Down Expand Up @@ -84,13 +88,14 @@ class led_controller {
percent = counter * 100 / thres;
else
percent = (thres * 2 - counter) * 100 / thres;
CRGB color{CRGB::OrangeRed};
CRGB color{status_color};
for (auto &i : color.raw)
i = i * percent / 100;
fill(color);
}
static constexpr uint32_t NUM_LEDS{45};
CRGB led[NUM_LEDS];
CRGB status_color{CRGB::Green}; //Green at startup
uint32_t counter{0};
int32_t level{0};
bool charging{false};
Expand Down Expand Up @@ -264,17 +269,20 @@ class power_controller {
if (elapsed_ms > 10000) {
Serial.println("heartbeat timeout, stop charging.");
set_auto_enable(false);
led.set_led_status(CRGB::Blue);
}
if (terminal.is_overheat()) {
Serial.println("terminal overheat, stop charging.");
set_auto_enable(false);
led.set_led_status(CRGB::Red);
}
}
if (relay.is_manual_mode()) {
auto elapsed_ms{manual_charging_timer.read_ms()};
if (elapsed_ms > 7200000) {
Serial.println("manual charging timeout, stop charging.");
set_manual_enable(false);
led.set_led_status(CRGB::HotPink);
}
}
}
Expand All @@ -287,6 +295,7 @@ class power_controller {
relay.set_enable(true, CHARGING_MODE::AUTO);
led.set_charging(true, level);
fan.set_charging(true);
led.set_led_status(CRGB::Green); //back to default color when enabled
} else {
relay.set_enable(false);
led.set_charging(false);
Expand All @@ -301,6 +310,7 @@ class power_controller {
if (enable) {
manual_charging_timer.reset();
manual_charging_timer.start();
led.set_led_status(CRGB::Green); //back to default color when enabled
} else {
manual_charging_timer.stop();
manual_charging_timer.reset();
Expand Down Expand Up @@ -336,10 +346,14 @@ class charging_board {
sw.poll();
power.poll();
auto sw_state{sw.get_state()};
if (sw_state == manual_switch::STATE::PUSHED)
if (sw_state == manual_switch::STATE::PUSHED) {
power.set_manual_enable(true);
else if (sw_state == manual_switch::STATE::LONG_PUSHED)
Serial.println("Manual Charge");
}
else if (sw_state == manual_switch::STATE::LONG_PUSHED) {
power.set_manual_enable(false);
Serial.println("Auto Charge");
}
sw.set_led(power.get_manual_enable());
while (Serial1.available()) {
if (irda_timer.read_ms() > 1000)
Expand Down

0 comments on commit be83821

Please sign in to comment.