diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a2c540c9..71fc35e31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/pbio/include/pbdrv/usb.h b/lib/pbio/include/pbdrv/usb.h index 1a4a40515..08c8a4f4e 100644 --- a/lib/pbio/include/pbdrv/usb.h +++ b/lib/pbio/include/pbdrv/usb.h @@ -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 diff --git a/pybricks/common/pb_type_charger.c b/pybricks/common/pb_type_charger.c index 39d8a035c..7efd25ef5 100644 --- a/pybricks/common/pb_type_charger.c +++ b/pybricks/common/pb_type_charger.c @@ -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);