Skip to content

Commit f0f5808

Browse files
committed
libostentus: update to use as a Zephyr module
* Bump to libostentus v1.0.0 * Include using CONFIG_LIB_OSTENTUS * Guard all calls to this library using the above symbol Signed-off-by: Mike Szczys <[email protected]>
1 parent 3a990d8 commit f0f5808

File tree

7 files changed

+61
-55
lines changed

7 files changed

+61
-55
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,4 @@ UseTab: Always
8787
WhitespaceSensitiveMacros:
8888
- STRINGIFY
8989
- Z_STRINGIFY
90+
- IF_ENABLED

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ build*/
66
.cache
77
credentials.conf
88
__pycache__/
9-
libostentus

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ target_sources(app PRIVATE src/app_settings.c)
1313
target_sources(app PRIVATE src/app_state.c)
1414
target_sources(app PRIVATE src/app_work.c)
1515
target_sources(app PRIVATE src/dfu/app_dfu.c)
16-
target_sources(app PRIVATE src/libostentus/libostentus.c)
1716
target_sources_ifdef(CONFIG_BOOTLOADER_MCUBOOT app PRIVATE src/dfu/flash.c)
1817

1918
add_subdirectory_ifdef(CONFIG_ALUDEL_BATTERY_MONITOR src/battery_monitor)

boards/aludel_mini_v1_sparkfun9160_ns.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ CONFIG_GOLIOTH_RPC_MAX_RESPONSE_LEN=512
4040

4141
# Generate MCUboot compatible images
4242
CONFIG_BOOTLOADER_MCUBOOT=y
43+
44+
# Use Golioth Ostentus Faceplate
45+
CONFIG_LIB_OSTENTUS=y

src/app_work.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ LOG_MODULE_REGISTER(app_work, LOG_LEVEL_DBG);
1111
#include <zephyr/drivers/gpio.h>
1212

1313
#include "app_work.h"
14-
#include "libostentus/libostentus.h"
1514

15+
#ifdef CONFIG_LIB_OSTENTUS
16+
#include <libostentus.h>
17+
#endif
1618
#ifdef CONFIG_ALUDEL_BATTERY_MONITOR
1719
#include "battery_monitor/battery.h"
1820
#endif
@@ -40,10 +42,11 @@ void app_work_sensor_read(void)
4042
int err;
4143
char json_buf[256];
4244

43-
IF_ENABLED(CONFIG_ALUDEL_BATTERY_MONITOR,
44-
(read_and_report_battery();
45-
slide_set(BATTERY_V, get_batt_v_str(), strlen(get_batt_v_str()));
46-
slide_set(BATTERY_LVL, get_batt_lvl_str(), strlen(get_batt_lvl_str()));));
45+
IF_ENABLED(CONFIG_ALUDEL_BATTERY_MONITOR, (
46+
read_and_report_battery();
47+
slide_set(BATTERY_V, get_batt_v_str(), strlen(get_batt_v_str()));
48+
slide_set(BATTERY_LVL, get_batt_lvl_str(), strlen(get_batt_lvl_str()));
49+
));
4750

4851
/* For this demo, we just send Hello to Golioth */
4952
static uint8_t counter;
@@ -66,15 +69,16 @@ void app_work_sensor_read(void)
6669
LOG_ERR("Failed to send sensor data to Golioth: %d", err);
6770
}
6871

69-
/* Update slide values on Ostentus
70-
* -values should be sent as strings
71-
* -use the enum from app_work.h for slide key values
72-
*/
73-
snprintk(json_buf, sizeof(json_buf), "%d", counter);
74-
slide_set(UP_COUNTER, json_buf, strlen(json_buf));
75-
snprintk(json_buf, sizeof(json_buf), "%d", 255 - counter);
76-
slide_set(DN_COUNTER, json_buf, strlen(json_buf));
77-
72+
IF_ENABLED(CONFIG_LIB_OSTENTUS, (
73+
/* Update slide values on Ostentus
74+
* -values should be sent as strings
75+
* -use the enum from app_work.h for slide key values
76+
*/
77+
snprintk(json_buf, sizeof(json_buf), "%d", counter);
78+
slide_set(UP_COUNTER, json_buf, strlen(json_buf));
79+
snprintk(json_buf, sizeof(json_buf), "%d", 255 - counter);
80+
slide_set(DN_COUNTER, json_buf, strlen(json_buf));
81+
));
7882
++counter;
7983
}
8084

src/main.c

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ LOG_MODULE_REGISTER(golioth_rd_template, LOG_LEVEL_DBG);
1616
#include "app_state.h"
1717
#include "app_work.h"
1818
#include "dfu/app_dfu.h"
19-
#include "libostentus/libostentus.h"
19+
20+
#ifdef CONFIG_LIB_OSTENTUS
21+
#include <libostentus.h>
22+
#endif
2023
#ifdef CONFIG_ALUDEL_BATTERY_MONITOR
2124
#include "battery_monitor/battery.h"
2225
#endif
@@ -40,7 +43,6 @@ static struct gpio_callback button_cb_data;
4043

4144
/* forward declarations */
4245
void golioth_connection_led_set(uint8_t state);
43-
void network_led_set(uint8_t state);
4446

4547
void wake_system_thread(void)
4648
{
@@ -67,7 +69,9 @@ static void golioth_on_connect(struct golioth_client *client)
6769
#ifdef CONFIG_SOC_NRF9160
6870
static void process_lte_connected(void)
6971
{
70-
network_led_set(1);
72+
/* Change the state of the Internet LED on Ostentus */
73+
IF_ENABLED(CONFIG_LIB_OSTENTUS, (led_internet_set(1);));
74+
7175
golioth_system_client_start();
7276
}
7377

@@ -164,15 +168,7 @@ void golioth_connection_led_set(uint8_t state)
164168
/* Turn on Golioth logo LED once connected */
165169
gpio_pin_set_dt(&golioth_led, pin_state);
166170
/* Change the state of the Golioth LED on Ostentus */
167-
led_golioth_set(pin_state);
168-
}
169-
170-
/* Set (unset) LED indicators for active internet connection */
171-
void network_led_set(uint8_t state)
172-
{
173-
uint8_t pin_state = state ? 1 : 0;
174-
/* Change the state of the Internet LED on Ostentus */
175-
led_internet_set(pin_state);
171+
IF_ENABLED(CONFIG_LIB_OSTENTUS, (led_golioth_set(pin_state);));
176172
}
177173

178174
int main(void)
@@ -184,11 +180,12 @@ int main(void)
184180
LOG_INF("Firmware version: %s", CONFIG_MCUBOOT_IMAGE_VERSION);
185181
IF_ENABLED(CONFIG_MODEM_INFO, (log_modem_firmware_version();));
186182

187-
/* Update Ostentus LEDS using bitmask (Power On and Battery)*/
188-
led_bitmask(LED_POW | LED_BAT);
189-
190-
/* Show Golioth Logo on Ostentus ePaper screen */
191-
show_splash();
183+
IF_ENABLED(CONFIG_LIB_OSTENTUS, (
184+
/* Update Ostentus LEDS using bitmask (Power On and Battery) */
185+
led_bitmask(LED_POW | LED_BAT);
186+
/* Show Golioth Logo on Ostentus ePaper screen */
187+
show_splash();
188+
));
192189

193190
/* Get system thread id so loop delay change event can wake main */
194191
_system_thread = k_current_get();
@@ -258,26 +255,29 @@ int main(void)
258255
gpio_init_callback(&button_cb_data, button_pressed, BIT(user_btn.pin));
259256
gpio_add_callback(user_btn.port, &button_cb_data);
260257

261-
/* Set up a slideshow on Ostentus
262-
* - add up to 256 slides
263-
* - use the enum in app_work.h to add new keys
264-
* - values are updated using these keys (see app_work.c)
265-
*/
266-
slide_add(UP_COUNTER, LABEL_UP_COUNTER, strlen(LABEL_UP_COUNTER));
267-
slide_add(DN_COUNTER, LABEL_DN_COUNTER, strlen(LABEL_DN_COUNTER));
268-
IF_ENABLED(CONFIG_ALUDEL_BATTERY_MONITOR,
269-
(slide_add(BATTERY_V, LABEL_BATTERY, strlen(LABEL_BATTERY));
270-
slide_add(BATTERY_LVL, LABEL_BATTERY, strlen(LABEL_BATTERY));));
271-
slide_add(FIRMWARE, LABEL_FIRMWARE, strlen(LABEL_FIRMWARE));
272-
273-
/* Set the title ofthe Ostentus summary slide (optional) */
274-
summary_title(SUMMARY_TITLE, strlen(SUMMARY_TITLE));
275-
276-
/* Update the Firmware slide with the firmware version */
277-
slide_set(FIRMWARE, CONFIG_MCUBOOT_IMAGE_VERSION, strlen(CONFIG_MCUBOOT_IMAGE_VERSION));
278-
279-
/* Start Ostentus slideshow with 30 second delay between slides */
280-
slideshow(30000);
258+
IF_ENABLED(CONFIG_LIB_OSTENTUS,(
259+
/* Set up a slideshow on Ostentus
260+
* - add up to 256 slides
261+
* - use the enum in app_work.h to add new keys
262+
* - values are updated using these keys (see app_work.c)
263+
*/
264+
slide_add(UP_COUNTER, LABEL_UP_COUNTER, strlen(LABEL_UP_COUNTER));
265+
slide_add(DN_COUNTER, LABEL_DN_COUNTER, strlen(LABEL_DN_COUNTER));
266+
IF_ENABLED(CONFIG_ALUDEL_BATTERY_MONITOR, (
267+
slide_add(BATTERY_V, LABEL_BATTERY, strlen(LABEL_BATTERY));
268+
slide_add(BATTERY_LVL, LABEL_BATTERY, strlen(LABEL_BATTERY));
269+
));
270+
slide_add(FIRMWARE, LABEL_FIRMWARE, strlen(LABEL_FIRMWARE));
271+
272+
/* Set the title ofthe Ostentus summary slide (optional) */
273+
summary_title(SUMMARY_TITLE, strlen(SUMMARY_TITLE));
274+
275+
/* Update the Firmware slide with the firmware version */
276+
slide_set(FIRMWARE, CONFIG_MCUBOOT_IMAGE_VERSION, strlen(CONFIG_MCUBOOT_IMAGE_VERSION));
277+
278+
/* Start Ostentus slideshow with 30 second delay between slides */
279+
slideshow(30000);
280+
));
281281

282282
while (true) {
283283
app_work_sensor_read();

west.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ manifest:
3636
url: [email protected]:golioth/golioth-zephyr-boards.git
3737

3838
- name: libostentus
39-
path: app/src/libostentus
40-
revision: 5d37e4160959881932d1dd869e1d238096878cf2
39+
path: deps/modules/lib/libostentus
40+
revision: v1.0.0
4141
url: [email protected]:golioth/libostentus.git
4242

4343
- name: zephyr-network-info

0 commit comments

Comments
 (0)