File tree Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -534,6 +534,10 @@ void pbdrv_usb_tx_flush(void) {
534534 USBBufferFlush ((tUSBBuffer * )& g_sTxBuffer );
535535}
536536
537+ bool pbdrv_usb_connection_is_active (void ) {
538+ return false;
539+ }
540+
537541PROCESS_THREAD (pbdrv_usb_process , ev , data ) {
538542
539543 PROCESS_BEGIN ();
Original file line number Diff line number Diff line change @@ -214,6 +214,10 @@ static void pbdrv_usb_stm32_reset_tx_state(void) {
214214 pbdrv_usb_stm32_is_events_subscribed = false;
215215}
216216
217+ bool pbdrv_usb_connection_is_active (void ) {
218+ return pbdrv_usb_stm32_is_events_subscribed ;
219+ }
220+
217221/**
218222 * @brief Pybricks_Itf_Init
219223 * Initializes the Pybricks media low layer
Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ uint32_t pbdrv_usb_stdout_tx_available(void);
6262*/
6363bool pbdrv_usb_stdout_tx_is_idle (void );
6464
65+ /**
66+ * Indicates if a Pybricks app is connected and configured.
67+ *
68+ * @retval true if active, so the host has subscribed to events.
69+ */
70+ bool pbdrv_usb_connection_is_active (void );
71+
6572#else // PBDRV_CONFIG_USB
6673
6774static inline pbdrv_usb_bcd_t pbdrv_usb_get_bcd (void ) {
@@ -80,6 +87,10 @@ static inline bool pbdrv_usb_stdout_tx_is_idle(void) {
8087 return true;
8188}
8289
90+ static inline bool pbdrv_usb_connection_is_active (void ) {
91+ return false;
92+ }
93+
8394#endif // PBDRV_CONFIG_USB
8495
8596#endif // _PBDRV_USB_H_
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ typedef bool (*pbsys_host_stdin_event_callback_t)(uint8_t c);
2626#if PBSYS_CONFIG_HOST
2727
2828void pbsys_host_init (void );
29+ bool pbsys_host_is_connected (void );
2930uint32_t pbsys_host_stdin_get_free (void );
3031void pbsys_host_stdin_write (const uint8_t * data , uint32_t size );
3132void pbsys_host_stdin_set_callback (pbsys_host_stdin_event_callback_t callback );
@@ -38,6 +39,7 @@ bool pbsys_host_tx_is_idle(void);
3839#else // PBSYS_CONFIG_HOST
3940
4041#define pbsys_host_init ()
42+ #define pbsys_host_is_connected () false
4143#define pbsys_host_stdin_get_free () 0
4244#define pbsys_host_stdin_write (data , size ) { (void)(data); (void)(size); }
4345#define pbsys_host_stdin_set_callback (callback ) { (void)(callback); }
Original file line number Diff line number Diff line change 1010#include <stddef.h>
1111#include <stdint.h>
1212
13- #include <contiki.h>
14-
1513#include <pbdrv/bluetooth.h>
1614#include <pbdrv/clock.h>
1715#include <pbdrv/core.h>
2220#include <pbio/light.h>
2321#include <pbio/os.h>
2422#include <pbsys/config.h>
23+ #include <pbsys/host.h>
2524#include <pbsys/main.h>
2625#include <pbsys/status.h>
2726#include <pbsys/storage_settings.h>
@@ -265,8 +264,7 @@ pbio_error_t pbsys_hmi_await_program_selection(void) {
265264 }
266265
267266 // Don't time out while connected to host.
268- if (pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_LE )) {
269- // REVISIT: This should ask sys/host for "is connected" so it covers all connection types.
267+ if (pbsys_host_is_connected ()) {
270268 time_start = pbdrv_clock_get_ms ();
271269 }
272270
Original file line number Diff line number Diff line change @@ -22,6 +22,19 @@ void pbsys_host_init(void) {
2222 pbsys_bluetooth_init ();
2323}
2424
25+ /**
26+ * Tests if the hub is connected to the host with BLE or USB.
27+ *
28+ * Connected implies an active connection to a Pybricks app, not just
29+ * physically plugged in.
30+ *
31+ * @return @c true if connection is active, else @c false.
32+ */
33+ bool pbsys_host_is_connected (void ) {
34+ return pbdrv_bluetooth_is_connected (PBDRV_BLUETOOTH_CONNECTION_PYBRICKS ) ||
35+ pbdrv_usb_connection_is_active ();
36+ }
37+
2538// Publisher APIs. Pybricks Profile connections call these to push data to
2639// a common stdin buffer.
2740
You can’t perform that action at this time.
0 commit comments