From cab23051d9f0b6daa36e980fb817b98147288aa4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 30 Apr 2014 19:23:21 +0100 Subject: [PATCH] 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 #530. --- stmhal/led.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stmhal/led.c b/stmhal/led.c index 28c918e0e8..9e32c52483 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -143,7 +143,7 @@ int led_get_intensity(pyb_led_t led) { #if defined(PYBV4) || defined(PYBV10) if (led == 4) { - machine_uint_t i = TIM3->CCR1 * 255 / ((USBD_CDC_POLLING_INTERVAL*1000) - 1); + machine_uint_t i = (TIM3->CCR1 * 255 + (USBD_CDC_POLLING_INTERVAL*1000) - 2) / ((USBD_CDC_POLLING_INTERVAL*1000) - 1); if (i > 255) { i = 255; } @@ -209,15 +209,15 @@ STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_arg_check_num(n_args, n_kw, 1, 1, false); // get led number - machine_int_t led_id = mp_obj_get_int(args[0]) - 1; + machine_int_t led_id = mp_obj_get_int(args[0]); // check led number - if (!(0 <= led_id && led_id < NUM_LEDS)) { + if (!(1 <= led_id && led_id <= NUM_LEDS)) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "LED %d does not exist", led_id)); } // return static led object - return (mp_obj_t)&pyb_led_obj[led_id]; + return (mp_obj_t)&pyb_led_obj[led_id - 1]; } /// \method on()