diff --git a/src/covid.c b/src/covid.c index 84abebe..a28e82d 100644 --- a/src/covid.c +++ b/src/covid.c @@ -362,7 +362,7 @@ int init_covid() check_keys(NULL); int err = 0; - #ifndef NATIVE_POSIX + #if CONFIG_BT err = bt_le_scan_start(&scan_param, scan_cb); #endif if (err) @@ -380,7 +380,7 @@ int do_covid() //printk("covid start\n"); int err = 0; - #ifndef NATIVE_POSIX + #if CONFIG_BT err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad), NULL, 0); #endif @@ -392,7 +392,7 @@ int do_covid() k_sleep(K_SECONDS(10)); - #ifndef NATIVE_POSIX + #if CONFIG_BT err = bt_le_adv_stop(); #endif diff --git a/src/display.c b/src/display.c index e3b32b8..a481826 100644 --- a/src/display.c +++ b/src/display.c @@ -9,6 +9,8 @@ #include "display.h" +K_THREAD_STACK_DEFINE(display_stack_area, 5000); + #ifdef DISPLAY const struct device* display_dev; lv_obj_t* display_center_pane; @@ -29,7 +31,8 @@ lv_style_t red_button_style; void display_thread(void* arg1, void* arg2, void* arg3) { #ifdef DISPLAY while (1) { - lv_task_handler(); + lv_task_handler(); + update_display(); k_msleep(10); } #endif @@ -159,10 +162,10 @@ int init_display() { display_msg_label = lv_label_create(display_bot_bar, NULL); lv_label_set_text(display_msg_label, ""); - - update_display(); - lv_task_handler(); + static struct k_thread display_thread_data; + k_thread_create(&display_thread_data, display_stack_area, K_THREAD_STACK_SIZEOF(display_stack_area), display_thread, NULL, NULL, NULL, 0, 0, K_NO_WAIT); + display_blanking_off(display_dev); #endif @@ -191,7 +194,7 @@ int display_set_mem(int mem) { } int display_set_contacts(int contacts) { - lv_label_set_text_fmt(display_contacts_label, "Number of registered contacts %d, from which", contacts); + lv_label_set_text_fmt(display_contacts_label, "Number of contacts: %d,\nfrom which", contacts); return 0; } diff --git a/src/gatt-service.c b/src/gatt-service.c index 94c374b..3215391 100644 --- a/src/gatt-service.c +++ b/src/gatt-service.c @@ -73,6 +73,8 @@ int init_gatt(void) return 0; } +#if CONFIG_BT + int do_gatt(void){ //printk("gatt start\n"); int err; @@ -93,4 +95,12 @@ int do_gatt(void){ //printk("gatt end\n"); return 0; -} \ No newline at end of file +} + +#else + +int do_gatt(void) { + return 0; +} + +#endif \ No newline at end of file diff --git a/src/io.c b/src/io.c index a968c6c..8f4a92b 100644 --- a/src/io.c +++ b/src/io.c @@ -85,24 +85,21 @@ static struct gpio_callback button_0_cb_data; static struct gpio_callback button_1_cb_data; +#ifndef NATIVE_POSIX + void button_0_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins){ - #ifndef NATIVE_POSIX set_infection(true); gpio_pin_set(dev, PIN, (int)1); printk("Button 0 (=infected) pressed at %" PRIu32 "\n", k_cycle_get_32()); - #endif } void button_1_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins){ - #ifndef NATIVE_POSIX set_infection(false); gpio_pin_set(dev, PIN, (int)0); printk("Button 1 (=healthy) pressed at %" PRIu32 "\n", k_cycle_get_32()); - #endif } int init_io(){ - #ifndef NATIVE_POSIX struct device *button0, *button1; int err = 0; //struct device *led; @@ -172,6 +169,21 @@ int init_io(){ } //Turn LED 0 off gpio_pin_set(dev, PIN, (int)0); - #endif return 0; -} \ No newline at end of file +} + +#else + +void button_0_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins) { + // Do nothing +} + +void button_1_pressed(struct device *dev, struct gpio_callback *cb, uint32_t pins) { + // Do nothing +} + +int init_io(){ + return 0; +} + +#endif diff --git a/src/main.c b/src/main.c index fcb8c3b..e0f5ce4 100644 --- a/src/main.c +++ b/src/main.c @@ -19,11 +19,6 @@ #include "io.h" #include "display.h" -#ifndef BLUETOOTH -#define BLUETOOTH 1 -#endif - -K_THREAD_STACK_DEFINE(display_stack_area, 500); void main(void) { int err = 0; @@ -37,13 +32,15 @@ void main(void) { printk("Cyrpto init failed (err %d)\n", err); return; } + #endif + #if CONFIG_FLASH err = init_record_storage(); if (err) { printk("init storage failed (err %d)\n", err); return; } - #endif + #endif err = init_io(); if (err) { @@ -51,7 +48,7 @@ void main(void) { return; } - #if BLUETOOTH + #if CONFIG_BT /* Initialize the Bluetooth Subsystem */ err = bt_enable(NULL); if (err) { @@ -79,9 +76,7 @@ void main(void) { if (err) { printk("init display failed (err %d)\n", err); } - - struct k_thread display_thread_data; - k_tid_t display_tid = k_thread_create(&display_thread_data, display_stack_area, K_THREAD_STACK_SIZEOF(display_stack_area), display_thread, NULL, NULL, NULL, 0, 0, K_NO_WAIT); + do{ do_covid(); diff --git a/zephyr/boards/native_posix_64.conf b/zephyr/boards/native_posix_64.conf index fa733ac..0a31b86 100644 --- a/zephyr/boards/native_posix_64.conf +++ b/zephyr/boards/native_posix_64.conf @@ -16,4 +16,8 @@ CONFIG_LVGL_USE_THEME_MATERIAL=y CONFIG_DISPLAY=y CONFIG_DISPLAY_LOG_LEVEL_ERR=y -CONFIG_HEAP_MEM_POOL_SIZE=16384 +CONFIG_BT=n +CONFIG_FLASH=n +# TODO: Add configuration for flash emulation + +CONFIG_HEAP_MEM_POOL_SIZE=32768 diff --git a/zephyr/build_native.sh b/zephyr/build_native.sh index 48444cc..5b3fd9c 100755 --- a/zephyr/build_native.sh +++ b/zephyr/build_native.sh @@ -1,6 +1,5 @@ #!/bin/bash -BLUETOOTH=${1:-0} rm -rf build -west build -b native_posix_64 . -- -DCMAKE_C_FLAGS="-DNATIVE_POSIX -I../../include/tls_config -DDISPLAY -DBLUETOOTH=$BLUETOOTH" -echo "Run ./build/zephyr/zephyr.elf --bt-dev=hci0" \ No newline at end of file +west build -b native_posix_64 . -- -DCMAKE_C_FLAGS="-DNATIVE_POSIX -I../../include/tls_config -DDISPLAY" +echo "Run ./build/zephyr/zephyr.elf" \ No newline at end of file