Skip to content

Commit e837f44

Browse files
committed
pbio/sys/core: Consolidate power button logic.
This keeps the power button logic in one place. This used to be separate because the hmi logic was implicit in pbio/sys/bluetooth, but we don't have that anymore. By splitting this out of the sys/hmi module, we can make a platform specific HMI.
1 parent a9e5bf4 commit e837f44

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

lib/pbio/sys/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ PROCESS_THREAD(pbsys_system_process, ev, data) {
3535
if (ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
3636
etimer_reset(&timer);
3737
pbsys_battery_poll();
38-
pbsys_hmi_poll();
3938
pbsys_program_stop_poll();
39+
pbsys_status_light_poll();
4040

4141
// keep the hub from resetting itself
4242
pbdrv_watchdog_update();
@@ -53,7 +53,8 @@ void pbsys_init(void) {
5353

5454
pbsys_battery_init();
5555
pbsys_host_init();
56-
pbsys_hmi_init();
56+
pbsys_status_light_init();
57+
pbsys_hub_light_matrix_init();
5758

5859
process_start(&pbsys_system_process);
5960

lib/pbio/sys/hmi.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,6 @@
3737
#define DEBUG_PRINT(...)
3838
#endif
3939

40-
void pbsys_hmi_init(void) {
41-
pbsys_status_light_init();
42-
pbsys_hub_light_matrix_init();
43-
}
44-
45-
/**
46-
* Polls the HMI.
47-
*
48-
* This is called periodically to update the current HMI state.
49-
*/
50-
void pbsys_hmi_poll(void) {
51-
pbio_button_flags_t btn = pbdrv_button_get_pressed();
52-
53-
if (btn & PBIO_BUTTON_CENTER) {
54-
pbsys_status_set(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED);
55-
56-
// power off when button is held down for 2 seconds
57-
if (pbsys_status_test_debounce(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED, true, 2000)) {
58-
pbsys_status_set(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST);
59-
}
60-
} else {
61-
pbsys_status_clear(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED);
62-
}
63-
64-
pbsys_status_light_poll();
65-
}
66-
6740
/**
6841
* Registers button presses to update the visual UI state and request the
6942
* launch of a program.

lib/pbio/sys/hmi.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <pbsys/config.h>
88
#include <pbsys/status.h>
99

10-
void pbsys_hmi_init(void);
11-
void pbsys_hmi_poll(void);
1210
pbio_error_t pbsys_hmi_await_program_selection(void);
1311

1412
#endif // _PBSYS_SYS_HMI_H_

lib/pbio/sys/program_stop.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,29 @@ void pbsys_program_stop_set_buttons(pbio_button_flags_t buttons) {
5353
}
5454

5555
/**
56-
* This is called periodically to monitor the user program.
56+
* This is called periodically to monitor the power button and shutdown requests.
5757
*/
5858
void pbsys_program_stop_poll(void) {
5959

60+
pbio_button_flags_t btn = pbdrv_button_get_pressed();
61+
62+
if (btn & PBIO_BUTTON_CENTER) {
63+
pbsys_status_set(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED);
64+
65+
// power off when button is held down for 2 seconds
66+
if (pbsys_status_test_debounce(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED, true, 2000)) {
67+
pbsys_status_set(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST);
68+
}
69+
} else {
70+
pbsys_status_clear(PBIO_PYBRICKS_STATUS_POWER_BUTTON_PRESSED);
71+
}
72+
6073
// Cancel user application program if shutdown was requested.
6174
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) {
6275
pbsys_program_stop(true);
6376
return;
6477
}
6578

66-
pbio_button_flags_t btn = pbdrv_button_get_pressed();
67-
6879
if (!stop_buttons) {
6980
return;
7081
}

0 commit comments

Comments
 (0)