diff --git a/release/files_common b/release/files_common index d4f3e0cbd8..9106f42fa9 100644 --- a/release/files_common +++ b/release/files_common @@ -263,12 +263,15 @@ selfdrive/controls/lib/longitudinal_mpc_model/libmpc_py.py selfdrive/controls/lib/longitudinal_mpc_model/longitudinal_mpc.c selfdrive/hardware/__init__.py +selfdrive/hardware/base.h selfdrive/hardware/base.py selfdrive/hardware/hw.h selfdrive/hardware/eon/__init__.py selfdrive/hardware/eon/apk.py +selfdrive/hardware/eon/hardware.h selfdrive/hardware/eon/hardware.py selfdrive/hardware/tici/__init__.py +selfdrive/hardware/tici/hardware.h selfdrive/hardware/tici/hardware.py selfdrive/hardware/tici/pins.py selfdrive/hardware/tici/agnos.py diff --git a/selfdrive/common/framebuffer.h b/selfdrive/common/framebuffer.h index 1285b67c64..d60424d6ad 100644 --- a/selfdrive/common/framebuffer.h +++ b/selfdrive/common/framebuffer.h @@ -1,35 +1,9 @@ #pragma once - #include +#include "hardware/hwcomposer_defs.h" bool set_brightness(int brightness); -/* Display power modes */ -enum { - /* The display is turned off (blanked). */ - HWC_POWER_MODE_OFF = 0, - /* The display is turned on and configured in a low power state - * that is suitable for presenting ambient information to the user, - * possibly with lower fidelity than normal but greater efficiency. */ - HWC_POWER_MODE_DOZE = 1, - /* The display is turned on normally. */ - HWC_POWER_MODE_NORMAL = 2, - /* The display is configured as in HWC_POWER_MODE_DOZE but may - * stop applying frame buffer updates from the graphics subsystem. - * This power mode is effectively a hint from the doze dream to - * tell the hardware that it is done drawing to the display for the - * time being and that the display should remain on in a low power - * state and continue showing its current contents indefinitely - * until the mode changes. - * - * This mode may also be used as a signal to enable hardware-based doze - * functionality. In this case, the doze dream is effectively - * indicating that the hardware is free to take over the display - * and manage it autonomously to implement low power always-on display - * functionality. */ - HWC_POWER_MODE_DOZE_SUSPEND = 3, -}; - struct FramebufferState; class FrameBuffer { public: diff --git a/selfdrive/hardware/base.h b/selfdrive/hardware/base.h index 8df7d17825..c82610d93a 100644 --- a/selfdrive/hardware/base.h +++ b/selfdrive/hardware/base.h @@ -15,6 +15,7 @@ public: static void reboot() {}; static void poweroff() {}; static void set_brightness(int percent) {}; + static void set_display_power(bool on) {}; static bool get_ssh_enabled() { return false; }; static void set_ssh_enabled(bool enabled) {}; diff --git a/selfdrive/hardware/eon/hardware.h b/selfdrive/hardware/eon/hardware.h index 0a607a90e9..70e9144c33 100644 --- a/selfdrive/hardware/eon/hardware.h +++ b/selfdrive/hardware/eon/hardware.h @@ -3,6 +3,10 @@ #include #include +#include +#include +#include + #include "selfdrive/common/util.h" #include "selfdrive/hardware/base.h" @@ -24,6 +28,10 @@ public: brightness_control.close(); } }; + static void set_display_power(bool on) { + auto dtoken = android::SurfaceComposerClient::getBuiltInDisplay(android::ISurfaceComposer::eDisplayIdMain); + android::SurfaceComposerClient::setDisplayPowerMode(dtoken, on ? HWC_POWER_MODE_NORMAL : HWC_POWER_MODE_OFF); + }; static bool get_ssh_enabled() { return std::system("getprop persist.neos.ssh | grep -qF '1'") == 0; diff --git a/selfdrive/hardware/hw.h b/selfdrive/hardware/hw.h index 542eee6141..0e0980f156 100644 --- a/selfdrive/hardware/hw.h +++ b/selfdrive/hardware/hw.h @@ -1,5 +1,7 @@ #pragma once +#include "selfdrive/hardware/base.h" + #ifdef QCOM #include "selfdrive/hardware/eon/hardware.h" #define Hardware HardwareEon diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 87678f2d4a..2dc7b9fc6b 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -9,6 +9,7 @@ #include #include +#include "common/util.h" #include "common/params.h" #include "common/timing.h" #include "common/swaglog.h" @@ -194,14 +195,32 @@ static void handle_display_state(UIState* s, bool user_input) { static int awake_timeout = 0; awake_timeout = std::max(awake_timeout - 1, 0); - if (user_input || s->scene.ignition || s->scene.started) { - s->awake = true; + constexpr float accel_samples = 5*UI_FREQ; + static float accel_prev = 0., gyro_prev = 0.; + + bool should_wake = s->scene.started || s->scene.ignition || user_input; + if (!should_wake) { + // tap detection while display is off + bool accel_trigger = abs(s->scene.accel_sensor - accel_prev) > 0.2; + bool gyro_trigger = abs(s->scene.gyro_sensor - gyro_prev) > 0.15; + should_wake = accel_trigger && gyro_trigger; + gyro_prev = s->scene.gyro_sensor; + accel_prev = (accel_prev * (accel_samples - 1) + s->scene.accel_sensor) / accel_samples; + } + + if (should_wake) { awake_timeout = 30 * UI_FREQ; - } else if (awake_timeout == 0) { - s->awake = false; + } else if (awake_timeout > 0) { + should_wake = true; } -} + // handle state transition + if (s->awake != should_wake) { + s->awake = should_wake; + Hardware::set_display_power(s->awake); + LOGD("setting display power %d", s->awake); + } +} GLWindow::GLWindow(QWidget* parent) : QOpenGLWidget(parent) { timer = new QTimer(this);