diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 19759aea78315b3e2f31815916945b32add61b72..470a41853895ef3fbaec66ebea29cb2a8e68490c 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -403,14 +403,15 @@ API(API_DISP_CIRC, /** * Start continuous readout of the light sensor. Will read light level - * at preconfigured interval and make it available via `epic_light_sensor_get()` + * at preconfigured interval and make it available via `epic_light_sensor_get()`. + * + * If the continuous readout was already running, this function will silently pass. + * * * :return: `0` if the start was successful or a negative error value * if an error occured. Possible errors: * * - ``-EBUSY``: The timer could not be scheduled. - * - ``-EALREADY``: The continuous readout is already running. You can ignore - * this error and safely use `epic_light_sensor_get()` anyways. */ API(API_LIGHT_SENSOR_RUN, int epic_light_sensor_run()); @@ -429,12 +430,12 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value)); /** * Stop continuous readout of the light sensor. * + * If the continuous readout wasn't running, this function will silently pass. + * * :return: `0` if the stop was sucessful or a negative error value * if an error occured. Possible errors: * * - ``-EBUSY``: The timer stop could not be scheduled. - * - ``-EINVAL``: The continuous readout was not running. The continuous - * readout can be safely restarted. */ API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop()); diff --git a/epicardium/modules/light_sensor.c b/epicardium/modules/light_sensor.c index 4ba82bb203e505bbd1111dcb5257b0e6e97a71b5..ea5c4ccc3bf012dbc7e730bd2818ffdec57aeb45 100644 --- a/epicardium/modules/light_sensor.c +++ b/epicardium/modules/light_sensor.c @@ -45,20 +45,19 @@ int epic_light_sensor_run() // since &poll_timer_buffer is not NULL, xTimerCreateStatic should allways succeed, so // we don't need to check for poll_timer being NULL. } - if (xTimerIsTimerActive(poll_timer) == pdTRUE) { - return -EALREADY; - } else { + if (xTimerIsTimerActive(poll_timer) == pdFALSE) { if (xTimerStart(poll_timer, 0) != pdPASS) { return -EBUSY; } - return 0; } + return 0; } int epic_light_sensor_stop() { if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { - return -EINVAL; + // timer wasn't running (or never started), just silently pass + return 0; } if (xTimerStop(poll_timer, 0) != pdPASS) {