UI: Move the variables need to be updated by socket to UIScene (#19783)

* move variables into UIScene

* rebase master

* rebase master

* rebase master

* rebase master

* rebase master

* rebase master

* fix build error

* cleanup

Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: dd603a89f642ea73d2c9b0def94d228adf9d52df
This commit is contained in:
Dean Lee
2021-03-04 00:40:50 +08:00
committed by GitHub
parent 8ca071310a
commit 0818f7166d
7 changed files with 49 additions and 51 deletions
+9 -9
View File
@@ -30,14 +30,14 @@ static void handle_display_state(UIState *s, bool user_input) {
constexpr float accel_samples = 5*UI_FREQ;
static float accel_prev = 0., gyro_prev = 0.;
bool should_wake = s->started || s->ignition || user_input;
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->accel_sensor - accel_prev) > 0.2;
bool gyro_trigger = abs(s->gyro_sensor - gyro_prev) > 0.15;
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->gyro_sensor;
accel_prev = (accel_prev * (accel_samples - 1) + s->accel_sensor) / accel_samples;
gyro_prev = s->scene.gyro_sensor;
accel_prev = (accel_prev * (accel_samples - 1) + s->scene.accel_sensor) / accel_samples;
}
// determine desired state
@@ -62,7 +62,7 @@ static void handle_display_state(UIState *s, bool user_input) {
}
static void handle_vision_touch(UIState *s, int touch_x, int touch_y) {
if (s->started && (touch_x >= s->viz_rect.x - bdr_s)
if (s->scene.started && (touch_x >= s->viz_rect.x - bdr_s)
&& (s->active_app != cereal::UiLayoutState::App::SETTINGS)) {
if (!s->scene.driver_view) {
s->sidebar_collapsed = !s->sidebar_collapsed;
@@ -77,7 +77,7 @@ static void handle_sidebar_touch(UIState *s, int touch_x, int touch_y) {
if (settings_btn.ptInRect(touch_x, touch_y)) {
s->active_app = cereal::UiLayoutState::App::SETTINGS;
} else if (home_btn.ptInRect(touch_x, touch_y)) {
if (s->started) {
if (s->scene.started) {
s->active_app = cereal::UiLayoutState::App::NONE;
s->sidebar_collapsed = true;
} else {
@@ -139,7 +139,7 @@ int main(int argc, char* argv[]) {
s->sound->setVolume(MIN_VOLUME);
while (!do_exit) {
if (!s->started) {
if (!s->scene.started) {
util::sleep_for(50);
}
double u1 = millis_since_boot();
@@ -164,7 +164,7 @@ int main(int argc, char* argv[]) {
s->sound->setVolume(fmin(MAX_VOLUME, MIN_VOLUME + s->scene.car_state.getVEgo() / 5));
// set brightness
float clipped_brightness = fmin(512, (s->light_sensor*brightness_m) + brightness_b);
float clipped_brightness = fmin(512, (s->scene.light_sensor*brightness_m) + brightness_b);
smooth_brightness = fmin(255, clipped_brightness * 0.01 + smooth_brightness * 0.99);
ui_set_brightness(s, (int)smooth_brightness);