Device shut down timer

Added toggle to shut down the device after being offroad for a specified amount of time.
This commit is contained in:
FrogAi
2024-02-27 16:34:47 -07:00
parent 3794b4f06b
commit c5b7bd3e08
4 changed files with 14 additions and 2 deletions

View File

@@ -244,6 +244,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"CustomTheme", PERSISTENT}, {"CustomTheme", PERSISTENT},
{"CydiaTune", PERSISTENT}, {"CydiaTune", PERSISTENT},
{"DecelerationProfile", PERSISTENT}, {"DecelerationProfile", PERSISTENT},
{"DeviceShutdown", PERSISTENT},
{"DisengageVolume", PERSISTENT}, {"DisengageVolume", PERSISTENT},
{"DriveStats", PERSISTENT}, {"DriveStats", PERSISTENT},
{"DynamicPathWidth", PERSISTENT}, {"DynamicPathWidth", PERSISTENT},

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -12,6 +12,7 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
{"CESignal", "Turn Signal When Below Highway Speeds", "Switch to 'Experimental Mode' when using turn signals below highway speeds to help assit with turns.", ""}, {"CESignal", "Turn Signal When Below Highway Speeds", "Switch to 'Experimental Mode' when using turn signals below highway speeds to help assit with turns.", ""},
{"CustomPersonalities", "Custom Driving Personalities", "Customize the driving personality profiles to your driving style.", "../frogpilot/assets/toggle_icons/icon_custom.png"}, {"CustomPersonalities", "Custom Driving Personalities", "Customize the driving personality profiles to your driving style.", "../frogpilot/assets/toggle_icons/icon_custom.png"},
{"DeviceShutdown", "Device Shutdown Timer", "Configure the timer for automatic device shutdown when offroad conserving energy and preventing battery drain.", "../frogpilot/assets/toggle_icons/icon_time.png"},
{"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"}, {"LateralTune", "Lateral Tuning", "Modify openpilot's steering behavior.", "../frogpilot/assets/toggle_icons/icon_lateral_tune.png"},
@@ -133,6 +134,13 @@ FrogPilotControlsPanel::FrogPilotControlsPanel(SettingsWindow *parent) : FrogPil
relaxedProfile = new FrogPilotDualParamControl(relaxedFollow, relaxedJerk, this, true); relaxedProfile = new FrogPilotDualParamControl(relaxedFollow, relaxedJerk, this, true);
addItem(relaxedProfile); addItem(relaxedProfile);
} else if (param == "DeviceShutdown") {
std::map<int, QString> shutdownLabels;
for (int i = 0; i <= 33; ++i) {
shutdownLabels[i] = i == 0 ? "Instant" : i <= 3 ? QString::number(i * 15) + " mins" : QString::number(i - 3) + (i == 4 ? " hour" : " hours");
}
toggle = new FrogPilotParamValueControl(param, title, desc, icon, 0, 33, shutdownLabels, this, false);
} else if (param == "LateralTune") { } else if (param == "LateralTune") {
FrogPilotParamManageControl *lateralTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this); FrogPilotParamManageControl *lateralTuneToggle = new FrogPilotParamManageControl(param, title, desc, icon, this);
QObject::connect(lateralTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() { QObject::connect(lateralTuneToggle, &FrogPilotParamManageControl::manageButtonClicked, this, [this]() {

View File

@@ -38,6 +38,9 @@ class PowerMonitoring:
self.car_battery_capacity_uWh = max((CAR_BATTERY_CAPACITY_uWh / 10), int(car_battery_capacity_uWh)) self.car_battery_capacity_uWh = max((CAR_BATTERY_CAPACITY_uWh / 10), int(car_battery_capacity_uWh))
# FrogPilot variables # FrogPilot variables
device_shutdown_setting = self.params.get_int("DeviceShutdown")
# If the toggle is set for < 1 hour, configure by 15 minute increments
self.device_shutdown_time = (device_shutdown_setting - 3) * 3600 if device_shutdown_setting >= 4 else device_shutdown_setting * (60 * 15)
# Calculation tick # Calculation tick
def calculate(self, voltage: Optional[int], ignition: bool): def calculate(self, voltage: Optional[int], ignition: bool):
@@ -119,13 +122,13 @@ class PowerMonitoring:
offroad_time = (now - offroad_timestamp) offroad_time = (now - offroad_timestamp)
low_voltage_shutdown = (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3) and low_voltage_shutdown = (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3) and
offroad_time > VOLTAGE_SHUTDOWN_MIN_OFFROAD_TIME_S) offroad_time > VOLTAGE_SHUTDOWN_MIN_OFFROAD_TIME_S)
should_shutdown |= offroad_time > MAX_TIME_OFFROAD_S should_shutdown |= offroad_time > self.device_shutdown_time
should_shutdown |= low_voltage_shutdown should_shutdown |= low_voltage_shutdown
should_shutdown |= (self.car_battery_capacity_uWh <= 0) should_shutdown |= (self.car_battery_capacity_uWh <= 0)
should_shutdown &= not ignition should_shutdown &= not ignition
should_shutdown &= (not self.params.get_bool("DisablePowerDown")) should_shutdown &= (not self.params.get_bool("DisablePowerDown"))
should_shutdown &= in_car should_shutdown &= in_car
should_shutdown &= offroad_time > DELAY_SHUTDOWN_TIME_S should_shutdown &= offroad_time > DELAY_SHUTDOWN_TIME_S if self.device_shutdown_time else True # If "Instant" is selected for the timer, shutdown immediately
should_shutdown |= self.params.get_bool("ForcePowerDown") should_shutdown |= self.params.get_bool("ForcePowerDown")
should_shutdown &= started_seen or (now > MIN_ON_TIME_S) should_shutdown &= started_seen or (now > MIN_ON_TIME_S)
return should_shutdown return should_shutdown