From 339e74f9a32b2617ed0902c09cd42eb76532334d Mon Sep 17 00:00:00 2001 From: Adrian Schneider <adrian.schneider@abusix.com> Date: Mon, 22 Jul 2019 23:26:24 +0200 Subject: [PATCH] chore(light_sensor) make start and stop functions silently pass if nothing to do --- epicardium/epicardium.h | 11 ++++++----- epicardium/modules/light_sensor.c | 9 ++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 19759aea..470a4185 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 4ba82bb2..ea5c4ccc 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) { -- GitLab