Skip to content

Commit

Permalink
pbio/sys/status: Restore event status function.
Browse files Browse the repository at this point in the history
This keeps the protocol complete.

Also fix outdated changelog update.
  • Loading branch information
laurensvalk committed Sep 2, 2024
1 parent b959321 commit 67a1bfd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
backwards compatibility. For now, this is added to start various builtin
programs, but it prepares for the ability to start different downloaded
programs too ([pybricks-micropython#254]).
- Added program identifier to the hub status report to the host.
- Added one byte program identifier to the hub status report to the host.

### Changed

Expand All @@ -32,8 +32,6 @@
the hub ([pybricks-micropython#250]).
- Improved font for the digits ``0--9`` when displaying them
with `hub.display.char(str(x))` ([pybricks-micropython#253]).
- Added an optional 32-bit program identifier payload to the protocol commands
for starting a builtin or user program.

### Fixed
- Fixed not able to connect to new Technic Move hub with `LWP3Device()`.
Expand Down
2 changes: 2 additions & 0 deletions lib/pbio/include/pbio/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ typedef enum {
*/
#define PBIO_PYBRICKS_STATUS_FLAG(status) (1 << status)

uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id);

/**
* Application-specific feature flag supported by a hub.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/include/pbsys/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void pbsys_status_clear(pbio_pybricks_status_t status);
bool pbsys_status_test(pbio_pybricks_status_t status);
bool pbsys_status_test_debounce(pbio_pybricks_status_t status, bool state, uint32_t ms);
uint32_t pbsys_status_get_flags(void);
uint32_t pbsys_status_write_status_report(uint8_t *buf);
uint32_t pbsys_status_get_status_report(uint8_t *buf);

#endif // _PBSYS_STATUS_H_

Expand Down
15 changes: 15 additions & 0 deletions lib/pbio/src/protocol/pybricks.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
_Static_assert(NUM_PBIO_PYBRICKS_STATUS <= sizeof(uint32_t) * 8,
"oh no, we added too many status flags");

/**
* Writes Pybricks status report command to @p buf
*
* @param [in] buf The buffer to hold the binary data.
* @param [in] flags The status flags.
* @param [in] program_id Program identifier.
* @return The number of bytes written to @p buf.
*/
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id) {
buf[0] = PBIO_PYBRICKS_EVENT_STATUS_REPORT;
pbio_set_uint32_le(&buf[1], flags);
buf[5] = program_id;
return 6;
}

/**
* Encodes the value of the Pybricks hub capabilities characteristic.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/sys/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static PT_THREAD(pbsys_bluetooth_monitor_status(struct pt *pt)) {
etimer_restart(&timer);

// send the message
msg.context.size = pbsys_status_write_status_report(&msg.payload[0]);
msg.context.size = pbsys_status_get_status_report(&msg.payload[0]);
msg.context.connection = PBDRV_BLUETOOTH_CONNECTION_PYBRICKS;
list_add(send_queue, &msg);
msg.is_queued = true;
Expand Down
9 changes: 3 additions & 6 deletions lib/pbio/sys/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ static void pbsys_status_update_flag(pbio_pybricks_status_t status, bool set) {
}

/**
* Writes Pybricks status report command to @p buf
* Gets the Pybricks status report and writes it to @p buf
*
* @param [in] buf The buffer to hold the binary data.
* @return The number of bytes written to @p buf.
*/
uint32_t pbsys_status_write_status_report(uint8_t *buf) {
buf[0] = PBIO_PYBRICKS_EVENT_STATUS_REPORT;
pbio_set_uint32_le(&buf[1], pbsys_status.flags);
buf[5] = pbsys_status.program_id;
return 6;
uint32_t pbsys_status_get_status_report(uint8_t *buf) {
return pbio_pybricks_event_status_report(buf, pbsys_status.flags, pbsys_status.program_id);
}

/**
Expand Down

0 comments on commit 67a1bfd

Please sign in to comment.