Qt UI: power saving (#20456)

* c2 power saving

* clean that up

* that works

* add to hw

* set power

* release files

* add that

* include hw base

* pc joins the party

* util

Co-authored-by: Comma Device <device@comma.ai>
albatross
Adeeb Shihadeh 2021-03-24 11:09:39 -07:00 committed by GitHub
parent d72855ecb8
commit 49748d5dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 32 deletions

View File

@ -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

View File

@ -1,35 +1,9 @@
#pragma once
#include <cstdlib>
#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:

View File

@ -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) {};

View File

@ -3,6 +3,10 @@
#include <cstdlib>
#include <fstream>
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <hardware/hwcomposer_defs.h>
#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;

View File

@ -1,5 +1,7 @@
#pragma once
#include "selfdrive/hardware/base.h"
#ifdef QCOM
#include "selfdrive/hardware/eon/hardware.h"
#define Hardware HardwareEon

View File

@ -9,6 +9,7 @@
#include <QMouseEvent>
#include <QVBoxLayout>
#include "common/util.h"
#include "common/params.h"
#include "common/timing.h"
#include "common/swaglog.h"
@ -194,15 +195,33 @@ 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);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));