Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybricks.common.charger: change return value of connected() #274

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
- Re-implemented `hub.imu.heading()` to use optionally use the projection of 3D
orientation to improve performance when the hub is lifted off the ground.
The 1D-based heading remains the default for now.
- Change return value of connected() property from bool to int using the value
of pbdrv_usb_get_bcd(). This will allow pro users to be able to tell if they
have a "nonstandard" charger that could prevent proper
charging ([pybricks-micropython#274]).

### Fixed
- Fixed `DriveBase.angle()` getting an incorrectly rounded gyro value, which
could cause `turn(360)` to be off by a degree ([support#1844]).
- Fixed `hub` silently ignoring non-orthogonal base axis when it should raise.

[pybricks-micropython#274]: https://github.com/pybricks/pybricks-micropython/pull/274
[support#943]: https://github.com/pybricks/support/issues/943
[support#1886]: https://github.com/pybricks/support/issues/1886
[support#1844]: https://github.com/pybricks/support/issues/1844
Expand Down
12 changes: 7 additions & 5 deletions lib/pbio/include/pbdrv/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
* Indicates battery charging capabilites that were detected on a USB port.
*/
typedef enum {
// NOTE: These values are part of the MicroPython API, don't change the numbers.

/** The USB cable is not connected (no VBUS). */
PBDRV_USB_BCD_NONE,
PBDRV_USB_BCD_NONE = 0,
/** The USB cable is connected to a non-standard charger or PS/2 port. */
PBDRV_USB_BCD_NONSTANDARD,
PBDRV_USB_BCD_NONSTANDARD = 1,
/** The USB cable is connected to standard downstream port. */
PBDRV_USB_BCD_STANDARD_DOWNSTREAM,
PBDRV_USB_BCD_STANDARD_DOWNSTREAM = 2,
/** The USB cable is connected to charging downstream port. */
PBDRV_USB_BCD_CHARGING_DOWNSTREAM,
PBDRV_USB_BCD_CHARGING_DOWNSTREAM = 3,
/** The USB cable is connected to dedicated charging port. */
PBDRV_USB_BCD_DEDICATED_CHARGING,
PBDRV_USB_BCD_DEDICATED_CHARGING = 4,
} pbdrv_usb_bcd_t;

#if PBDRV_CONFIG_USB
Expand Down
2 changes: 1 addition & 1 deletion pybricks/common/pb_type_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static mp_obj_t Charger_status(mp_obj_t self_in) {
static MP_DEFINE_CONST_FUN_OBJ_1(Charger_status_obj, Charger_status);

static mp_obj_t Charger_connected(mp_obj_t self_in) {
return mp_obj_new_bool(pbdrv_usb_get_bcd() != PBDRV_USB_BCD_NONE);
return mp_obj_new_int(pbdrv_usb_get_bcd());
}
static MP_DEFINE_CONST_FUN_OBJ_1(Charger_connected_obj, Charger_connected);

Expand Down
Loading