diff --git a/bricks/_common/sources.mk b/bricks/_common/sources.mk index 1f1215901..7ed2f6b3e 100644 --- a/bricks/_common/sources.mk +++ b/bricks/_common/sources.mk @@ -242,6 +242,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\ sys/battery.c \ sys/command.c \ sys/core.c \ + sys/hmi_buildhat.c \ sys/hmi_ev3.c \ sys/hmi_ev3_ui.c \ sys/hmi_none.c \ diff --git a/lib/pbio/platform/build_hat/pbsysconfig.h b/lib/pbio/platform/build_hat/pbsysconfig.h index 5ccffd986..95e9a239c 100644 --- a/lib/pbio/platform/build_hat/pbsysconfig.h +++ b/lib/pbio/platform/build_hat/pbsysconfig.h @@ -10,7 +10,7 @@ #define PBSYS_CONFIG_BATTERY_CHARGER (0) #define PBSYS_CONFIG_HMI (1) #define PBSYS_CONFIG_HMI_STOP_BUTTON (0) // does not exist but pbsys_main() requires this to be defined -#define PBSYS_CONFIG_HMI_NONE (1) +#define PBSYS_CONFIG_HMI_BUILDHAT (1) #define PBSYS_CONFIG_HMI_NUM_SLOTS (0) #define PBSYS_CONFIG_HOST (1) #define PBSYS_CONFIG_HOST_EVENT_OUT_SIZE (512) diff --git a/lib/pbio/sys/hmi_buildhat.c b/lib/pbio/sys/hmi_buildhat.c new file mode 100644 index 000000000..c51779f45 --- /dev/null +++ b/lib/pbio/sys/hmi_buildhat.c @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2018-2026 The Pybricks Authors + +// Provides the Human Machine Interface (HMI) for the Build HAT. +// There is nothing to select, so the REPL starts right after boot. + +#include + +#if PBSYS_CONFIG_HMI_BUILDHAT + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +void pbsys_hmi_init(void) { +} + +void pbsys_hmi_deinit(void) { +} + +void pbsys_hmi_stop_animation(void) { +} + +void pbsys_hmi_connection_changed_handler(void) { +} + +pbio_error_t pbsys_hmi_await_program_selection(void) { + + do { + if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST)) { + return PBIO_ERROR_CANCELED; + } + pbio_os_run_processes_and_wait_for_event(); + } while (pbdrv_button_get_pressed()); + + // Start the "ready" animation, same as hmi_pup.c does after program + // selection. + #if PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS + pbio_color_light_start_breathe_animation(pbsys_status_light_main, PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS_HUE); + #elif PBSYS_CONFIG_STATUS_LIGHT + pbio_color_light_off(pbsys_status_light_main); + #endif + + return pbsys_main_program_request_start(PBIO_PYBRICKS_USER_PROGRAM_ID_REPL, PBSYS_MAIN_PROGRAM_START_REQUEST_TYPE_BOOT); +} + +#endif // PBSYS_CONFIG_HMI_BUILDHAT