Skip to content

Commit 179c954

Browse files
committed
pbio/drv/usb_simulation: Include telemetry in mock data.
Now that USB instead of BLE is used as the main I/O mock, we should include all events to send them to the Virtual Hub animation.
1 parent 4bb9bb9 commit 179c954

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/pbio/drv/usb/usb_simulation.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ pbio_error_t pbdrv_usb_tx_event(pbio_os_state_t *state, const uint8_t *data, uin
3535

3636
PBIO_OS_ASYNC_BEGIN(state);
3737

38-
// Only care about stdout in this simulation.
39-
if (size < 2 || data[0] != PBIO_PYBRICKS_IN_EP_MSG_EVENT || data[1] != PBIO_PYBRICKS_EVENT_WRITE_STDOUT) {
40-
return PBIO_SUCCESS;
38+
39+
// Stdout also goes to native stdout.
40+
if (size > 2 && data[0] == PBIO_PYBRICKS_IN_EP_MSG_EVENT && data[1] == PBIO_PYBRICKS_EVENT_WRITE_STDOUT) {
41+
int ret = write(STDOUT_FILENO, data + 2, size - 2);
42+
(void)ret;
4143
}
4244

43-
int ret = write(STDOUT_FILENO, data + 2, size - 2);
44-
(void)ret;
45+
#ifndef PBDRV_CONFIG_RUN_ON_CI
46+
extern void virtual_hub_socket_send(const uint8_t *data, uint32_t size);
47+
virtual_hub_socket_send(data + 1, size - 1);
48+
#endif
4549

4650
// Simulate some I/O time.
47-
PBIO_OS_AWAIT_MS(state, &timer, 2);
51+
PBIO_OS_AWAIT_MS(state, &timer, 1);
4852

4953
PBIO_OS_ASYNC_END(PBIO_SUCCESS);
5054
}

lib/pbio/platform/virtual_hub/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def process_telemetry(payload):
6262
# Only supports motors for now.
6363
if len(payload) == 6:
6464
type_id, index, angle = struct.unpack("<bbi", payload[0:6])
65-
if type_id == 96:
65+
if type_id == 94: # REVISIT: Align with firmware
6666
angles[index] = angle
6767

6868

0 commit comments

Comments
 (0)