Skip to content

Commit cab2305

Browse files
committed
stmhal: Make LED.intensity return the same value it was set to.
Also give proper error message when trying to construct a non-existent LED. Addresses issue adafruit#530.
1 parent 22d0598 commit cab2305

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

stmhal/led.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int led_get_intensity(pyb_led_t led) {
143143

144144
#if defined(PYBV4) || defined(PYBV10)
145145
if (led == 4) {
146-
machine_uint_t i = TIM3->CCR1 * 255 / ((USBD_CDC_POLLING_INTERVAL*1000) - 1);
146+
machine_uint_t i = (TIM3->CCR1 * 255 + (USBD_CDC_POLLING_INTERVAL*1000) - 2) / ((USBD_CDC_POLLING_INTERVAL*1000) - 1);
147147
if (i > 255) {
148148
i = 255;
149149
}
@@ -209,15 +209,15 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
209209
mp_arg_check_num(n_args, n_kw, 1, 1, false);
210210

211211
// get led number
212-
machine_int_t led_id = mp_obj_get_int(args[0]) - 1;
212+
machine_int_t led_id = mp_obj_get_int(args[0]);
213213

214214
// check led number
215-
if (!(0 <= led_id && led_id < NUM_LEDS)) {
215+
if (!(1 <= led_id && led_id <= NUM_LEDS)) {
216216
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED %d does not exist", led_id));
217217
}
218218

219219
// return static led object
220-
return (mp_obj_t)&pyb_led_obj[led_id];
220+
return (mp_obj_t)&pyb_led_obj[led_id - 1];
221221
}
222222

223223
/// \method on()

0 commit comments

Comments
 (0)