Skip to content

Commit

Permalink
Merge pull request commaai#98 from CHaucke89/frog-softreboot-pr
Browse files Browse the repository at this point in the history
Soft Reboot 2
  • Loading branch information
FrogAi authored Feb 21, 2024
2 parents 77020c0 + ef86688 commit bf62e45
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"DisableOnroadUploads", PERSISTENT},
{"DisableVTSCSmoothing", PERSISTENT},
{"DisengageVolume", PERSISTENT},
{"DoSoftReboot", CLEAR_ON_MANAGER_START},
{"DragonPilotTune", PERSISTENT},
{"DriverCamera", PERSISTENT},
{"DriveStats", PERSISTENT},
Expand Down
6 changes: 4 additions & 2 deletions selfdrive/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def manager_thread() -> None:

# Exit main loop when uninstall/shutdown/reboot is needed
shutdown = False
for param in ("DoUninstall", "DoShutdown", "DoReboot"):
for param in ("DoUninstall", "DoShutdown", "DoReboot", "DoSoftReboot"):
if params.get_bool(param):
shutdown = True
params.put("LastManagerExitReason", f"{param} {datetime.datetime.now()}")
Expand Down Expand Up @@ -419,7 +419,9 @@ def main() -> None:
elif params.get_bool("DoShutdown"):
cloudlog.warning("shutdown")
HARDWARE.shutdown()

elif params.get_bool("DoSoftReboot"):
cloudlog.warning("softreboot")
HARDWARE.soft_reboot()

if __name__ == "__main__":
unblock_stdout()
Expand Down
23 changes: 21 additions & 2 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
QHBoxLayout *power_layout = new QHBoxLayout();
power_layout->setSpacing(30);

QPushButton *softreboot_btn = new QPushButton(tr("Soft Reboot"));
softreboot_btn->setObjectName("softreboot_btn");
power_layout->addWidget(softreboot_btn);
QObject::connect(softreboot_btn, &QPushButton::clicked, this, &DevicePanel::softreboot);

QPushButton *reboot_btn = new QPushButton(tr("Reboot"));
reboot_btn->setObjectName("reboot_btn");
power_layout->addWidget(reboot_btn);
Expand All @@ -319,8 +324,10 @@ DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) {
}

setStyleSheet(R"(
#reboot_btn { height: 120px; border-radius: 15px; background-color: #393939; }
#reboot_btn:pressed { background-color: #4a4a4a; }
#softreboot_btn { height: 120px; border-radius: 15px; background-color: #e2e22c; }
#softreboot_btn:pressed { background-color: #ffe224; }
#reboot_btn { height: 120px; border-radius: 15px; background-color: #e2872c; }
#reboot_btn:pressed { background-color: #ff9724; }
#poweroff_btn { height: 120px; border-radius: 15px; background-color: #E22C2C; }
#poweroff_btn:pressed { background-color: #FF2424; }
)");
Expand Down Expand Up @@ -364,6 +371,18 @@ void DevicePanel::reboot() {
}
}

void DevicePanel::softreboot() {
if (!uiState()->engaged()) {
if (ConfirmationDialog::confirm(tr("Are you sure you want to soft reboot?"), tr("Soft Reboot"), this)) {
if (!uiState()->engaged()) {
params.putBool("DoSoftReboot", true);
}
}
} else {
ConfirmationDialog::alert(tr("Disengage to Soft Reboot"), this);
}
}

void DevicePanel::poweroff() {
if (!uiState()->engaged()) {
if (ConfirmationDialog::confirm(tr("Are you sure you want to power off?"), tr("Power Off"), this)) {
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/offroad/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DevicePanel : public ListWidget {
private slots:
void poweroff();
void reboot();
void softreboot();
void updateCalibDescription();

private:
Expand Down
1 change: 1 addition & 0 deletions system/hardware/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HardwareNone {
}

static void reboot() {}
static void soft_reboot() {}
static void poweroff() {}
static void set_brightness(int percent) {}
static void set_display_power(bool on) {}
Expand Down
4 changes: 4 additions & 0 deletions system/hardware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def booted(self) -> bool:
def reboot(self, reason=None):
pass

@abstractmethod
def soft_reboot(self):
pass

@abstractmethod
def uninstall(self):
pass
Expand Down
1 change: 1 addition & 0 deletions system/hardware/tici/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HardwareTici : public HardwareNone {
}

static void reboot() { std::system("sudo reboot"); }
static void soft_reboot() { std::system("sudo systemctl restart comma"); }
static void poweroff() { std::system("sudo poweroff"); }
static void set_brightness(int percent) {
std::string max = util::read_file("/sys/class/backlight/panel0-backlight/max_brightness");
Expand Down
8 changes: 8 additions & 0 deletions system/hardware/tici/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ def get_sound_card_online(self):
def reboot(self, reason=None):
subprocess.check_output(["sudo", "reboot"])

def soft_reboot(self):
# Reload the touchscreen driver to reset touch_count and avoid triggering a system reset prompt
sudo_write("894000.i2c", "/sys/bus/platform/drivers/i2c_geni/unbind")
time.sleep(0.5)
sudo_write("894000.i2c", "/sys/bus/platform/drivers/i2c_geni/bind")
time.sleep(0.5)
os.system("sudo systemctl restart comma")

def uninstall(self):
Path("/data/__system_reset__").touch()
os.sync()
Expand Down

0 comments on commit bf62e45

Please sign in to comment.