Skip to content

Commit

Permalink
Added poweroff timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
tunefs committed Jul 12, 2022
1 parent 4436155 commit d2877f4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ class state_controller {
AUTO_CHARGE,
MANUAL_CHARGE,
LOCKDOWN,
TIMEROFF,
};
void poll() {
auto wheel_relay_control = [&](){
Expand All @@ -770,6 +771,10 @@ class state_controller {
case POWER_STATE::OFF:
set_new_state(mc.is_plugged() ? POWER_STATE::POST : POWER_STATE::WAIT_SW);
break;
case POWER_STATE::TIMEROFF:
if (timer_poweroff.elapsed_time() > 5s)
set_new_state(POWER_STATE::OFF);
break;
case POWER_STATE::WAIT_SW:
if (psw.get_state() != power_switch::STATE::RELEASED) {
poweron_by_switch = true;
Expand All @@ -796,7 +801,7 @@ class state_controller {
if (!dcdc.is_ok() || psw_state == power_switch::STATE::LONG_PUSHED) {
set_new_state(POWER_STATE::OFF);
} else if (mbd.is_dead()) {
set_new_state(wait_shutdown ? POWER_STATE::OFF : POWER_STATE::LOCKDOWN);
set_new_state(wait_shutdown ? POWER_STATE::TIMEROFF : POWER_STATE::LOCKDOWN);
} else if (psw_state == power_switch::STATE::PUSHED || mbd.power_off_from_ros() ||
mbd.is_overheat() || !bmu.is_ok() || !temp.is_ok()) {
if (wait_shutdown) {
Expand Down Expand Up @@ -956,6 +961,11 @@ class state_controller {
while (true) // wait power off
continue;
break;
case POWER_STATE::TIMEROFF:
LOG("enter TIMEROFF\n");
timer_poweroff.reset();
timer_poweroff.start();
break;
case POWER_STATE::WAIT_SW:
LOG("enter WAIT_SW\n");
break;
Expand Down Expand Up @@ -1104,7 +1114,7 @@ class state_controller {
POWERBOARD_TEMP,
BMU,
} shutdown_reason{SHUTDOWN_REASON::NONE};
Timer timer_post, timer_shutdown;
Timer timer_post, timer_shutdown, timer_poweroff;
Timeout current_check_timeout, charge_guard_timeout;
bool poweron_by_switch{false}, wait_shutdown{false}, current_check_enable{false}, charge_guard_asserted{false},
last_wheel_poweroff{false};
Expand Down

0 comments on commit d2877f4

Please sign in to comment.