From 6d5793d29ed3f6b5bbdeb78a63dba509059f23a6 Mon Sep 17 00:00:00 2001 From: kaizoku-oh Date: Thu, 13 May 2021 18:51:42 +0100 Subject: [PATCH] update example --- .../firestore-crud/src/{main.c => app_main.c} | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) rename examples/firestore-crud/src/{main.c => app_main.c} (74%) diff --git a/examples/firestore-crud/src/main.c b/examples/firestore-crud/src/app_main.c similarity index 74% rename from examples/firestore-crud/src/main.c rename to examples/firestore-crud/src/app_main.c index 78bb504..110e44e 100644 --- a/examples/firestore-crud/src/main.c +++ b/examples/firestore-crud/src/app_main.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -7,9 +7,15 @@ #include "firestore.h" #include "app_wifi.h" -static void _firestore_task(void *); +static void _app_main_firestore_task(void *); +static void _app_main_update_document(void); #define APP_MAIN_TAG "APP_MAIN" + +#define APP_MAIN_FIRESTORE_TASK_STACK_SIZE 10240 +#define APP_MAIN_FIRESTORE_TASK_PRIORITY 4 +#define APP_MAIN_FIRESTORE_PERIOD_MS 1000 + #define APP_MAIN_FIRESTORE_DOC_MAX_SIZE 64 #define APP_MAIN_FIRESTORE_COLLECTION_ID "devices" #define APP_MAIN_FIRESTORE_DOCUMENT_ID "esp32" @@ -24,7 +30,31 @@ static void _firestore_task(void *); static uint32_t u32DocLength; static char tcDoc[APP_MAIN_FIRESTORE_DOC_MAX_SIZE]; -void update_document(void) +void app_main(void) +{ + /* Block until connected to WiFi */ + app_wifi_init(); + app_wifi_wait(); + + xTaskCreate(_app_main_firestore_task, + "firestore", + APP_MAIN_FIRESTORE_TASK_STACK_SIZE, + NULL, + APP_MAIN_FIRESTORE_TASK_PRIORITY, + NULL); +} + +static void _app_main_firestore_task(void *pvParameter) +{ + firestore_init(); + while(1) + { + _app_main_update_document(); + vTaskDelay(APP_MAIN_FIRESTORE_PERIOD_MS / portTICK_PERIOD_MS); + } +} + +static void _app_main_update_document(void) { /* Format json document */ u32DocLength = snprintf(tcDoc, @@ -52,22 +82,3 @@ void update_document(void) ESP_LOGE(APP_MAIN_TAG, "Couldn't format document"); } } - -static void _firestore_task(void *pvParameter) -{ - firestore_init(); - while(1) - { - update_document(); - vTaskDelay(1000 / portTICK_PERIOD_MS); - } -} - -void app_main() -{ - /* Block until connected to WiFi */ - app_wifi_init(); - app_wifi_wait(); - - xTaskCreate(_firestore_task, "firestore", 10240, NULL, 4, NULL); -}