Skip to content

Commit 74bebe8

Browse files
committed
Add screen orientation based on accelerometer to homescreen
1 parent 377ee32 commit 74bebe8

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

main/menu/home.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "apps.h"
66
#include "bsp/display.h"
77
#include "bsp/input.h"
8+
#include "bsp/orientation.h"
89
#include "bsp/power.h"
910
#include "charging_mode.h"
1011
#include "common/display.h"
@@ -144,6 +145,8 @@ void menu_home(void) {
144145

145146
render(buffer, theme, &menu, position, false, true);
146147

148+
bsp_orientation_enable_accelerometer();
149+
147150
while (1) {
148151
bsp_input_event_t event;
149152
if (xQueueReceive(input_event_queue, &event, pdMS_TO_TICKS(1000)) == pdTRUE) {
@@ -244,7 +247,24 @@ void menu_home(void) {
244247
break;
245248
}
246249
} else {
247-
render(buffer, theme, &menu, position, true, true);
250+
bool gyro_enabled = false;
251+
bool accel_enabled = false;
252+
float gyro_x, gyro_y, gyro_z;
253+
float accel_x, accel_y, accel_z;
254+
bsp_orientation_get(&gyro_enabled, &accel_enabled, &gyro_x, &gyro_y, &gyro_z, &accel_x, &accel_y, &accel_z);
255+
bool changed = false;
256+
if (accel_x > 2.0f || !accel_enabled) {
257+
if (pax_buf_get_orientation(buffer) != PAX_O_ROT_CCW) {
258+
pax_buf_set_orientation(buffer, PAX_O_ROT_CCW);
259+
changed = true;
260+
}
261+
} else if (accel_x < -2.0f) {
262+
if (pax_buf_get_orientation(buffer) != PAX_O_ROT_CW) {
263+
pax_buf_set_orientation(buffer, PAX_O_ROT_CW);
264+
changed = true;
265+
}
266+
}
267+
render(buffer, theme, &menu, position, !changed, true);
248268
}
249269
}
250270
}

0 commit comments

Comments
 (0)