Skip to content
Snippets Groups Projects
Commit 339e74f9 authored by Adrian Schneider's avatar Adrian Schneider
Browse files

chore(light_sensor) make start and stop functions silently pass if nothing to do

parent 5796f861
No related tags found
No related merge requests found
Pipeline #1404 passed
...@@ -403,14 +403,15 @@ API(API_DISP_CIRC, ...@@ -403,14 +403,15 @@ API(API_DISP_CIRC,
/** /**
* Start continuous readout of the light sensor. Will read light level * 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 * :return: `0` if the start was successful or a negative error value
* if an error occured. Possible errors: * if an error occured. Possible errors:
* *
* - ``-EBUSY``: The timer could not be scheduled. * - ``-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()); 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)); ...@@ -429,12 +430,12 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value));
/** /**
* Stop continuous readout of the light sensor. * 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 * :return: `0` if the stop was sucessful or a negative error value
* if an error occured. Possible errors: * if an error occured. Possible errors:
* *
* - ``-EBUSY``: The timer stop could not be scheduled. * - ``-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()); API(API_LIGHT_SENSOR_STOP, int epic_light_sensor_stop());
......
...@@ -45,20 +45,19 @@ int epic_light_sensor_run() ...@@ -45,20 +45,19 @@ int epic_light_sensor_run()
// since &poll_timer_buffer is not NULL, xTimerCreateStatic should allways succeed, so // since &poll_timer_buffer is not NULL, xTimerCreateStatic should allways succeed, so
// we don't need to check for poll_timer being NULL. // we don't need to check for poll_timer being NULL.
} }
if (xTimerIsTimerActive(poll_timer) == pdTRUE) { if (xTimerIsTimerActive(poll_timer) == pdFALSE) {
return -EALREADY;
} else {
if (xTimerStart(poll_timer, 0) != pdPASS) { if (xTimerStart(poll_timer, 0) != pdPASS) {
return -EBUSY; return -EBUSY;
} }
return 0;
} }
return 0;
} }
int epic_light_sensor_stop() int epic_light_sensor_stop()
{ {
if (!poll_timer || xTimerIsTimerActive(poll_timer) == pdFALSE) { 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) { if (xTimerStop(poll_timer, 0) != pdPASS) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment