From e55185a7bb5512394dcc865c0fe429c2c50b5134 Mon Sep 17 00:00:00 2001 From: toyboxZ <6660197+toyboxZ@users.noreply.github.com> Date: Sat, 2 Jan 2021 23:03:48 +0800 Subject: [PATCH] add rec screen button --- cereal/log.capnp | 4 ++-- common/dp_conf.py | 2 +- selfdrive/dragonpilot/dashcam.py | 4 ++++ selfdrive/dragonpilot/systemd.py | 5 +++++ selfdrive/ui/android/ui.cc | 22 +++++++++++++++------- selfdrive/ui/paint.cc | 3 +++ selfdrive/ui/paint_dp.cc | 20 +++++++++++++++++++- selfdrive/ui/paint_dp.hpp | 3 ++- selfdrive/ui/ui.cc | 1 + selfdrive/ui/ui.hpp | 6 ++++++ 10 files changed, 58 insertions(+), 12 deletions(-) diff --git a/cereal/log.capnp b/cereal/log.capnp index 61ec1f0b3..deb315c89 100644 --- a/cereal/log.capnp +++ b/cereal/log.capnp @@ -2160,7 +2160,7 @@ struct DragonConf { dpAppHr @6 :Bool; dpAppHrManual @7 :Int8; dpDashcam @8 :Bool; - dpDashcamHoursStored @9 :UInt8; + dpDashcamUi @9 :Bool; dpAutoShutdown @10 :Bool; dpAthenad @11 :Bool; dpUploader @12 :Bool; @@ -2226,4 +2226,4 @@ struct DragonConf { dpDischargingAt @72 :UInt8; dpIsUpdating @73 :Bool; dpTimebombAssist @74 :Bool; -} \ No newline at end of file +} diff --git a/common/dp_conf.py b/common/dp_conf.py index 4690f0601..c2fce49ce 100644 --- a/common/dp_conf.py +++ b/common/dp_conf.py @@ -26,7 +26,7 @@ confs = [ {'name': 'dp_app_hr_manual', 'default': 0, 'type': 'Int8', 'min': -1, 'max': 1, 'depends': [{'name': 'dp_app_hr', 'vals': [True]}], 'conf_type': ['param', 'struct']}, # dashcam related {'name': 'dp_dashcam', 'default': 0, 'type': 'Bool', 'conf_type': ['param', 'struct']}, - {'name': 'dp_dashcam_hours_stored', 'default': 24, 'type': 'UInt8', 'min': 1, 'max': 255, 'depends': [{'name': 'dp_dashcam', 'vals': [True]}], 'conf_type': ['param', 'struct']}, + {'name': 'dp_dashcam_ui', 'default': 0, 'type': 'Bool', 'conf_type': ['param', 'struct']}, # auto shutdown {'name': 'dp_auto_shutdown', 'default': False, 'type': 'Bool', 'conf_type': ['param', 'struct']}, {'name': 'dp_auto_shutdown_in', 'default': 90, 'type': 'UInt16', 'min': 1, 'max': 65535, 'depends': [{'name': 'dp_auto_shutdown', 'vals': [True]}], 'conf_type': ['param']}, diff --git a/selfdrive/dragonpilot/dashcam.py b/selfdrive/dragonpilot/dashcam.py index f9915ebb3..e02607868 100644 --- a/selfdrive/dragonpilot/dashcam.py +++ b/selfdrive/dragonpilot/dashcam.py @@ -28,6 +28,10 @@ class Dashcam(): self.record() self.clean_up() + def stop(self): + os.system("killall -SIGINT screenrecord") + self.dashcam_next_time = 0 + def make_folder(self): if not self.dashcam_folder_exists and self.dashcam_mkdir_retry <= 5: # create dashcam folder if not exist diff --git a/selfdrive/dragonpilot/systemd.py b/selfdrive/dragonpilot/systemd.py index 954624443..240125046 100644 --- a/selfdrive/dragonpilot/systemd.py +++ b/selfdrive/dragonpilot/systemd.py @@ -42,6 +42,7 @@ def confd_thread(): last_charging_ctrl = False last_started = False dashcam = Dashcam() + last_dashcam_recorded = False while True: start_sec = sec_since_boot() @@ -147,6 +148,10 @@ def confd_thread(): ''' if msg.dragonConf.dpDashcam and frame % HERTZ == 0: dashcam.run(started, free_space) + last_dashcam_recorded = True + if last_dashcam_recorded and not msg.dragonConf.dpDashcam: + dashcam.stop() + last_dashcam_recorded = False ''' =================================================== finalise diff --git a/selfdrive/ui/android/ui.cc b/selfdrive/ui/android/ui.cc index 72058db70..af668b701 100644 --- a/selfdrive/ui/android/ui.cc +++ b/selfdrive/ui/android/ui.cc @@ -70,6 +70,7 @@ static void handle_display_state(UIState *s, bool user_input) { } static bool handle_dp_btn_touch(UIState *s, int touch_x, int touch_y) { + bool update_dp_last_modified = false ; //dfButton manager // code below thanks to kumar: https://github.com/arne182/openpilot/commit/71d5aac9f8a3f5942e89634b20cbabf3e19e3e78 if (s->started && s->active_app != cereal::UiLayoutState::App::SETTINGS) { if (s->scene.dpDynamicFollow > 0 && touch_x >= df_btn_x && touch_x <= (df_btn_x + df_btn_w) && touch_y >= df_btn_y && touch_y <= (df_btn_y + df_btn_h)) { @@ -82,11 +83,8 @@ static bool handle_dp_btn_touch(UIState *s, int touch_x, int touch_y) { char str[2] = {0}; sprintf(str, "%d", val); Params().write_db_value("dp_dynamic_follow", str, 1); - - char time_str[11]; - snprintf(time_str, 11, "%lu", time(NULL)); - Params().write_db_value("dp_last_modified", time_str, 11); - return true; + update_dp_last_modified = true; + } else if (s->scene.dpAccelProfile > 0 && touch_x >= ap_btn_x && touch_x <= (ap_btn_x + ap_btn_w) && touch_y >= ap_btn_y && touch_y <= (ap_btn_y + ap_btn_h)) { int val = s->scene.dpAccelProfile; val++; @@ -97,13 +95,23 @@ static bool handle_dp_btn_touch(UIState *s, int touch_x, int touch_y) { char str[2] = {0}; sprintf(str, "%d", val); Params().write_db_value("dp_accel_profile", str, 1); - + update_dp_last_modified = true; + + } else if (s->scene.dpDashcamUi && touch_x >= rec_btn_x && touch_x <= (rec_btn_x + rec_btn_w) && touch_y >= rec_btn_y && touch_y <= (rec_btn_y + rec_btn_h)) { + char str[2] = {0}; + sprintf(str, "%d", !s->scene.dpDashcam); + Params().write_db_value("dp_dashcam", str, 1); + update_dp_last_modified = true; + } + } + + if ( update_dp_last_modified ) { char time_str[11]; snprintf(time_str, 11, "%lu", time(NULL)); Params().write_db_value("dp_last_modified", time_str, 11); return true; - } } + return false; } diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 2adcf3971..dbbb75fd6 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -498,6 +498,9 @@ static void ui_draw_vision_footer(UIState *s) { } else { ui_draw_blindspots(s, false); } + if (s->scene.dpDashcamUi) { + ui_draw_rec_button(s); + } } static void ui_draw_vision_alert(UIState *s) { diff --git a/selfdrive/ui/paint_dp.cc b/selfdrive/ui/paint_dp.cc index 1a0515699..048dc1eb2 100644 --- a/selfdrive/ui/paint_dp.cc +++ b/selfdrive/ui/paint_dp.cc @@ -362,4 +362,22 @@ void ui_draw_bbui(UIState *s) { bb_ui_draw_measures_right(s, bb_dml_x, bb_dml_y, bb_dml_w); bb_ui_draw_measures_left(s, bb_dmr_x, bb_dmr_y, bb_dmr_w); -} \ No newline at end of file +} + +void ui_draw_rec_button(UIState *s) { + nvgBeginPath(s->vg); + nvgRoundedRect(s->vg, rec_btn_x, rec_btn_y, rec_btn_w, rec_btn_h, 20); + nvgStrokeColor(s->vg, COLOR_WHITE_ALPHA(80)); + nvgStrokeWidth(s->vg, 6); + nvgStroke(s->vg); + + nvgFontSize(s->vg, 80); + if (s->scene.dpDashcam) { + nvgFillColor(s->vg, nvgRGBA(255,0,0,255)); + } + else { + nvgFillColor(s->vg, nvgRGBA(255, 255, 255, 255)); + } + nvgTextAlign(s->vg, NVG_ALIGN_CENTER); + nvgText(s->vg, rec_btn_x + rec_btn_w / 2, rec_btn_y + (rec_btn_h / 2)+20,"REC",NULL); +} diff --git a/selfdrive/ui/paint_dp.hpp b/selfdrive/ui/paint_dp.hpp index 6dd307607..ec0dae553 100644 --- a/selfdrive/ui/paint_dp.hpp +++ b/selfdrive/ui/paint_dp.hpp @@ -3,6 +3,7 @@ void ui_draw_df_button(UIState *s); void ui_draw_ap_button(UIState *s); +void ui_draw_rec_button(UIState *s); void ui_draw_infobar(UIState *s); void ui_draw_blindspots(UIState *s, bool hasInfobar); -void ui_draw_bbui(UIState *s); \ No newline at end of file +void ui_draw_bbui(UIState *s); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 47b3a624f..0202c7f4e 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -245,6 +245,7 @@ void update_sockets(UIState *s) { if (sm.updated("dragonConf")) { auto data = sm["dragonConf"].getDragonConf(); scene.dpDashcam = data.getDpDashcam(); + scene.dpDashcamUi = data.getDpDashcamUi(); scene.dpFullScreenApp = data.getDpAppWaze() || data.getDpAppHr(); scene.dpDrivingUi = data.getDpDrivingUi(); scene.dpUiScreenOffReversing = data.getDpUiScreenOffReversing(); diff --git a/selfdrive/ui/ui.hpp b/selfdrive/ui/ui.hpp index 097e37527..a4758dbe3 100644 --- a/selfdrive/ui/ui.hpp +++ b/selfdrive/ui/ui.hpp @@ -71,6 +71,11 @@ const int ap_btn_w = 180; const int ap_btn_x = 1450; const int ap_btn_y = 750; const int info_bar_h = 80; +// dp - rec btn +const int rec_btn_h = 130; +const int rec_btn_w = 180; +const int rec_btn_x = 870; +const int rec_btn_y = 800; typedef enum NetStatus { NET_CONNECTED, @@ -140,6 +145,7 @@ typedef struct UIScene { // dp bool dpDashcam; + bool dpDashcamUi; bool dpFullScreenApp; bool dpDrivingUi; bool dpUiScreenOffReversing;