Skip to content

Commit

Permalink
Organize source files in sub-dirs
Browse files Browse the repository at this point in the history
- Rename 'err' with 'ret' where applicable
  • Loading branch information
bandogora committed Oct 28, 2024
1 parent b60eb96 commit 982b01d
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 50 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/src/led_display.c → app/src/display/led_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/sys/util.h>

#include "display_switches.h"
#include "display/display_switches.h"

#if !DT_NODE_EXISTS(DT_ALIAS(mux))
#error "Multiplexer device node with alias 'mux' not defined."
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 33 additions & 33 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
#include <zephyr/sys/reboot.h>
#include <zephyr/types.h>

#include "display_switches.h"
#include "display/display_switches.h"
#include "display/pwm_leds.h"
#include "external_rtc.h"
#include "light_sensor.h"
#include "lte_manager.h"
#include "pwm_leds.h"
#include "net/lte_manager.h"
#include "update_stop.h"
#include "watchdog_app.h"

#ifdef CONFIG_BOOTLOADER_MCUBOOT
#include "fota.h"
#include "net/fota.h"
#endif

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
Expand Down Expand Up @@ -114,20 +114,20 @@ int main(void) {

#else
int main(void) {
int err;
int ret;
int lux;
int wdt_channel_id = -1;

err = init_display_switches();
if (err < 0) {
LOG_ERR("Failed to initialize display switches. Err: %d", err);
ret = init_display_switches();
if (ret < 0) {
LOG_ERR("Failed to initialize display switches. Err: %d", ret);
goto reset;
}

// Set all displays off because the LEDs have memory
for (size_t box = 0; box < NUMBER_OF_DISPLAY_BOXES; box++) {
err = display_off(box);
if (err < 0) {
ret = display_off(box);
if (ret < 0) {
LOG_ERR("Failed to set display switch %d off.", box);
}
}
Expand All @@ -137,8 +137,8 @@ int main(void) {
goto reset;
}

err = pwm_leds_set((uint32_t)lux);
if (err) {
ret = pwm_leds_set((uint32_t)lux);
if (ret) {
goto reset;
}

Expand All @@ -154,20 +154,20 @@ int main(void) {
goto reset;
}

err = wdt_feed(wdt, wdt_channel_id);
if (err) {
LOG_ERR("Failed to feed watchdog. Err: %d", err);
ret = wdt_feed(wdt, wdt_channel_id);
if (ret) {
LOG_ERR("Failed to feed watchdog. Err: %d", ret);
goto reset;
}

err = lte_connect();
if (err) {
ret = lte_connect();
if (ret) {
goto reset;
}

if (k_sem_take(&lte_connected_sem, K_FOREVER) == 0) {
err = set_external_rtc_time();
if (err) {
ret = set_external_rtc_time();
if (ret) {
LOG_ERR("Failed to set rtc.");
goto reset;
}
Expand All @@ -177,9 +177,9 @@ int main(void) {
}
k_sem_give(&lte_connected_sem);

err = wdt_feed(wdt, wdt_channel_id);
if (err) {
LOG_ERR("Failed to feed watchdog. Err: %d", err);
ret = wdt_feed(wdt, wdt_channel_id);
if (ret) {
LOG_ERR("Failed to feed watchdog. Err: %d", ret);
goto reset;
}

Expand All @@ -191,26 +191,26 @@ int main(void) {

while (1) {
if (k_sem_take(&stop_sem, K_NO_WAIT) == 0) {
err = update_stop();
if (err == 0) {
ret = update_stop();
if (ret == 0) {
lux = get_lux();
if (lux < 0) {
goto reset;
}
} else if (err == 2) {
} else if (ret == 2) {
lux = 0xFF;
} else {
goto reset;
}

err = pwm_leds_set((uint32_t)lux);
if (err) {
ret = pwm_leds_set((uint32_t)lux);
if (ret) {
goto reset;
}

err = wdt_feed(wdt, wdt_channel_id);
if (err) {
LOG_ERR("Failed to feed watchdog. Err: %d", err);
ret = wdt_feed(wdt, wdt_channel_id);
if (ret) {
LOG_ERR("Failed to feed watchdog. Err: %d", ret);
goto reset;
}
}
Expand All @@ -223,9 +223,9 @@ int main(void) {
#ifdef CONFIG_DEBUG
LOG_WRN("Reached end of main; waiting for manual reset.");
while (1) {
err = wdt_feed(wdt, wdt_channel_id);
if (err) {
LOG_ERR("Failed to feed watchdog. Err: %d", err);
ret = wdt_feed(wdt, wdt_channel_id);
if (ret) {
LOG_ERR("Failed to feed watchdog. Err: %d", ret);
}
k_msleep(29000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <zephyr/net/tls_credentials.h>
#include <zephyr/storage/stream_flash.h>

#include "fota.h"
#include "lte_manager.h"
#include "net/fota.h"
#include "net/lte_manager.h"
#include "watchdog_app.h"

LOG_MODULE_REGISTER(custom_http_client, LOG_LEVEL_INF);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/src/fota.c → app/src/net/fota.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <zephyr/storage/flash_map.h>
#include <zephyr/sys/util.h>

#include "custom_http_client.h"
#include "net/custom_http_client.h"
#include "pm_config.h"
#include "watchdog_app.h"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions app/src/update_stop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

#include "custom_http_client.h"
#include "display_switches.h"
#include "display/display_switches.h"
#include "display/led_display.h"
#include "external_rtc.h"
#include "json/jsmn_parse.h"
#include "led_display.h"
#include "net/custom_http_client.h"
#include "stop.h"

LOG_MODULE_REGISTER(update_stop, LOG_LEVEL_INF);
Expand Down Expand Up @@ -92,7 +92,7 @@ static int parse_returned_routes(Stop stop, DisplayBox display_boxes[]) {
}

int update_stop(void) {
int err;
int ret;
static Stop stop = {.last_updated = 0, .id = CONFIG_STOP_ID};
static const DisplayBox display_boxes[] = DISPLAY_BOXES;

Expand All @@ -107,16 +107,16 @@ int update_stop(void) {
static char json_buf[CONFIG_STOP_JSON_BUF_SIZE];

retry:
err = http_request_stop_json(
ret = http_request_stop_json(
&json_buf[0], CONFIG_STOP_JSON_BUF_SIZE, headers_buf, sizeof(headers_buf)
);
if (err) {
LOG_ERR("HTTP GET request for JSON failed; cleaning up. ERR: %d", err);
if (ret) {
LOG_ERR("HTTP GET request for JSON failed; cleaning up. ERR: %d", ret);
return 1;
}

err = parse_stop_json(&json_buf[0], &stop);
if (err) {
ret = parse_stop_json(&json_buf[0], &stop);
if (ret) {
LOG_DBG(
"recv_body_buf size: %d, recv_body strlen: %d",
CONFIG_STOP_JSON_BUF_SIZE, strlen(&json_buf[0])
Expand All @@ -127,11 +127,11 @@ int update_stop(void) {
* means the HTTP transfer was incomplete. This may be a server-side issue,
* so we can retry the download once before resetting the device.
*/
if (err == 3 && retry_error == 0) {
if (ret == 3 && retry_error == 0) {
LOG_WRN("JSON download was incomplete, retrying...");
retry_error = 1;
goto retry;
} else if (err == 5) {
} else if (ret == 5) {
/* A returned 5 corresponds to a successful response with no scheduled
* departures.
*/
Expand All @@ -146,8 +146,8 @@ int update_stop(void) {
stop.routes_size, stop.last_updated
);

err = parse_returned_routes(stop, display_boxes);
if (err) {
ret = parse_returned_routes(stop, display_boxes);
if (ret) {
return 1;
}

Expand Down

0 comments on commit 982b01d

Please sign in to comment.