diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-30 19:23:21 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-30 19:23:21 +0100 |
commit | cab23051d9f0b6daa36e980fb817b98147288aa4 (patch) | |
tree | a581c072013a0b82724a77511aad7b48524312b4 | |
parent | 22d05988189f53b8e3a4cf68b3140c2fc53ba7d3 (diff) | |
download | micropython-cab23051d9f0b6daa36e980fb817b98147288aa4.tar.gz micropython-cab23051d9f0b6daa36e980fb817b98147288aa4.zip |
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.
-rw-r--r-- | stmhal/led.c | 8 |
1 files 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() |