From 120fdbd8bb88ddaaabc44b5be5d760eef7347e1e Mon Sep 17 00:00:00 2001
From: Adrian Schneider <adrian.schneider@abusix.com>
Date: Sun, 21 Jul 2019 16:58:36 +0200
Subject: [PATCH] chore(light_sensor) handle scheduling errors in pycardium

---
 pycardium/modules/light_sensor.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pycardium/modules/light_sensor.c b/pycardium/modules/light_sensor.c
index f055ef28..9b0d1a08 100644
--- a/pycardium/modules/light_sensor.c
+++ b/pycardium/modules/light_sensor.c
@@ -5,7 +5,11 @@
 
 STATIC mp_obj_t mp_light_sensor_start()
 {
-    epic_light_sensor_run();
+    int status = epic_light_sensor_run();
+    if (status == -EBUSY)
+    {
+        mp_raise_msg(&mp_type_RuntimeError, "timer could not be scheduled");
+    }
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_start_obj, mp_light_sensor_start);
@@ -25,7 +29,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_get_obj, mp_light_sensor_get_readi
 
 STATIC mp_obj_t mp_light_sensor_stop()
 {
-    epic_light_sensor_stop();
+    int status = epic_light_sensor_stop();
+    if (status == -EBUSY)
+    {
+        mp_raise_msg(&mp_type_RuntimeError, "timer could not be scheduled");
+    }
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_stop_obj, mp_light_sensor_stop);
-- 
GitLab