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

chore(light_sensor) make code style compliant

parent 15ceddd3
No related branches found
No related tags found
No related merge requests found
Pipeline #1402 passed
......@@ -14,7 +14,8 @@ static StaticTimer_t poll_timer_buffer;
int epic_light_sensor_init()
{
const sys_cfg_adc_t sys_adc_cfg = NULL; /* No system specific configuration needed. */
const sys_cfg_adc_t sys_adc_cfg =
NULL; /* No system specific configuration needed. */
if (ADC_Init(0x9, &sys_adc_cfg) != E_NO_ERROR) {
return -EINVAL;
}
......@@ -32,8 +33,7 @@ int epic_light_sensor_run()
{
epic_light_sensor_init();
if (!poll_timer)
{
if (!poll_timer) {
poll_timer = xTimerCreateStatic(
"light_sensor_adc",
READ_FREQ,
......@@ -44,14 +44,11 @@ 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)
{
if (xTimerIsTimerActive(poll_timer) == pdTRUE) {
return -EALREADY;
} else {
if (xTimerStart(poll_timer, 0) != pdPASS)
{
if (xTimerStart(poll_timer, 0) != pdPASS) {
return -EBUSY;
}
return 0;
......@@ -64,8 +61,7 @@ int epic_light_sensor_stop()
return -EINVAL;
}
if (xTimerStop(poll_timer, 0) != pdPASS)
{
if (xTimerStop(poll_timer, 0) != pdPASS) {
return -EBUSY;
}
return 0;
......@@ -73,8 +69,7 @@ int epic_light_sensor_stop()
int epic_light_sensor_get(uint16_t *value)
{
if (!poll_timer || !xTimerIsTimerActive(poll_timer))
{
if (!poll_timer || !xTimerIsTimerActive(poll_timer)) {
return -ENODATA;
}
*value = last_value;
......
......@@ -6,9 +6,10 @@
STATIC mp_obj_t mp_light_sensor_start()
{
int status = epic_light_sensor_run();
if (status == -EBUSY)
{
mp_raise_msg(&mp_type_RuntimeError, "timer could not be scheduled");
if (status == -EBUSY) {
mp_raise_msg(
&mp_type_RuntimeError, "timer could not be scheduled"
);
}
return mp_const_none;
}
......@@ -18,21 +19,23 @@ STATIC mp_obj_t mp_light_sensor_get_reading()
{
uint16_t last;
int status = epic_light_sensor_get(&last);
if (status == -ENODATA)
{
if (status == -ENODATA) {
mp_raise_ValueError("sensor not running");
return mp_const_none;
}
return mp_obj_new_int_from_uint(last);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_get_obj, mp_light_sensor_get_reading);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(
light_sensor_get_obj, mp_light_sensor_get_reading
);
STATIC mp_obj_t mp_light_sensor_stop()
{
int status = epic_light_sensor_stop();
if (status == -EBUSY)
{
mp_raise_msg(&mp_type_RuntimeError, "timer could not be stopped");
if (status == -EBUSY) {
mp_raise_msg(
&mp_type_RuntimeError, "timer could not be stopped"
);
}
return mp_const_none;
}
......@@ -44,7 +47,9 @@ STATIC const mp_rom_map_elem_t light_sensor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&light_sensor_stop_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_reading), MP_ROM_PTR(&light_sensor_get_obj) }
};
STATIC MP_DEFINE_CONST_DICT(light_sensor_module_globals, light_sensor_module_globals_table);
STATIC MP_DEFINE_CONST_DICT(
light_sensor_module_globals, light_sensor_module_globals_table
);
const mp_obj_module_t light_sensor_module = {
.base = { &mp_type_module },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment