From d9012c7af89851b06d3de6d71c7e23f02a2691b4 Mon Sep 17 00:00:00 2001 From: BlynkGO Date: Fri, 23 Sep 2022 10:59:19 +0700 Subject: [PATCH] Version 1.4 add more examples --- .../03.Multitask_Template.ino} | 2 +- .../task1.ino | 0 .../task2.ino | 0 .../task3.ino | 0 .../task4.ino | 0 .../task5.ino | 0 example/04.task_with_del/04.task_with_del.ino | 63 +++++++++++++++++++ src/TridentTD_EasyFreeRTOS32.h | 2 +- 8 files changed, 65 insertions(+), 2 deletions(-) rename example/{Multitask_Template/Multitask_Template.ino => 03.Multitask_Template/03.Multitask_Template.ino} (95%) rename example/{Multitask_Template => 03.Multitask_Template}/task1.ino (100%) rename example/{Multitask_Template => 03.Multitask_Template}/task2.ino (100%) rename example/{Multitask_Template => 03.Multitask_Template}/task3.ino (100%) rename example/{Multitask_Template => 03.Multitask_Template}/task4.ino (100%) rename example/{Multitask_Template => 03.Multitask_Template}/task5.ino (100%) create mode 100644 example/04.task_with_del/04.task_with_del.ino diff --git a/example/Multitask_Template/Multitask_Template.ino b/example/03.Multitask_Template/03.Multitask_Template.ino similarity index 95% rename from example/Multitask_Template/Multitask_Template.ino rename to example/03.Multitask_Template/03.Multitask_Template.ino index 14d18b9..6cb0998 100644 --- a/example/Multitask_Template/Multitask_Template.ino +++ b/example/03.Multitask_Template/03.Multitask_Template.ino @@ -1,6 +1,6 @@ #include -TridentOS task1, task2, task3, task4, task5; // ประกาศตัวแปร task +EasyFreeRTOS32 task1, task2, task3, task4, task5; // ประกาศตัวแปร task void task1_func(void*), task2_func(void*), // ฟังกชั่นที่ task จะเรียกทำงาน task3_func(void*), task4_func(void*), task5_func(void*); diff --git a/example/Multitask_Template/task1.ino b/example/03.Multitask_Template/task1.ino similarity index 100% rename from example/Multitask_Template/task1.ino rename to example/03.Multitask_Template/task1.ino diff --git a/example/Multitask_Template/task2.ino b/example/03.Multitask_Template/task2.ino similarity index 100% rename from example/Multitask_Template/task2.ino rename to example/03.Multitask_Template/task2.ino diff --git a/example/Multitask_Template/task3.ino b/example/03.Multitask_Template/task3.ino similarity index 100% rename from example/Multitask_Template/task3.ino rename to example/03.Multitask_Template/task3.ino diff --git a/example/Multitask_Template/task4.ino b/example/03.Multitask_Template/task4.ino similarity index 100% rename from example/Multitask_Template/task4.ino rename to example/03.Multitask_Template/task4.ino diff --git a/example/Multitask_Template/task5.ino b/example/03.Multitask_Template/task5.ino similarity index 100% rename from example/Multitask_Template/task5.ino rename to example/03.Multitask_Template/task5.ino diff --git a/example/04.task_with_del/04.task_with_del.ino b/example/04.task_with_del/04.task_with_del.ino new file mode 100644 index 0000000..959757f --- /dev/null +++ b/example/04.task_with_del/04.task_with_del.ino @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#define SSID "----------" +#define PASSWORD "----------" +#define SHT20_I2C_SDA 22 +#define SHT20_I2C_SCL 25 + + +// ประกาศ ตัวแปร task และ function สำหรับ task +EasyFreeRTOS32 WiFi_task, SHT20_task; + + +void setup(){ // setup() หลักตัวพิมพ์เล็ก + Serial.begin(115200); Serial.println(); + + WiFi_task.start(CORE0, 4096, [](void *param){ + VOID SETUP(){ + Serial.println("[WiFi] begin ..."); + WiFi.begin(SSID, PASSWORD); + } + VOID LOOP(){ + if( !WiFi.isConnected() ) { + while(!WiFi.isConnected() ) DELAY(400); + Serial.print("[WiFi] WiFi Connected, IP : "); + Serial.println(WiFi.localIP()); + } + DELAY(10000); + } + }); + + SHT20_task.start(CORE1, [](void*param){ + DFRobot_SHT20 sht20(&Wire1, SHT20_I2C_ADDR); + bool sht20_is_inited= false; + VOID SETUP(){ + Serial.println("[SHT20] initing.."); + Wire1.begin(SHT20_I2C_SDA, SHT20_I2C_SCL); + Wire1.beginTransmission(SHT20_I2C_ADDR); + sht20_is_inited = (0== Wire1.endTransmission()); + if(sht20_is_inited ) { + Serial.println("[SHT20] init OK"); //SHT20_I2C_ADDR + }else{ + Serial.println("[SHT20] init failed"); + SHT20_task.del(); // ทำลาย SHT20_task ทิ้งไปไม่ต้องทำงานอีก + } + } + VOID LOOP(){ + DELAY(1000); + if(sht20_is_inited ) { + float sht_temp = sht20.readTemperature(); + float sht_hum = sht20.readHumidity(); + + Serial.printf("[SHT20] Tempperature : %.2f °C\n", sht_temp); + Serial.printf("[SHT20] Humidity : %.2f %%\n", sht_hum); + } + } + }); +} + +void loop(){ DELAY(1); } // loop() หลักตัวพิมพ์เล็ก ไม่จำเป็นต้องใช้แต่ให้มีไว้เสมอ + diff --git a/src/TridentTD_EasyFreeRTOS32.h b/src/TridentTD_EasyFreeRTOS32.h index f09914d..0233430 100644 --- a/src/TridentTD_EasyFreeRTOS32.h +++ b/src/TridentTD_EasyFreeRTOS32.h @@ -46,7 +46,7 @@ class EasyFreeRTOS32 { EasyFreeRTOS32() {}; void start( TaskFunction_t fn, void * const arg=NULL, const uint32_t StackDepth=2048, uint8_t core_no=1); inline void start( TaskFunction_t fn, const uint32_t StackDepth, uint8_t core_no) { start( fn, NULL, StackDepth, core_no); } - inline void start( uint8_t core_no, TaskFunction_t fn) { start(fn, NULL, 2048, core_no) } + inline void start( uint8_t core_no, TaskFunction_t fn) { start( fn, NULL, 2048, core_no); } inline void start( uint8_t core_no, const uint32_t StackDepth, TaskFunction_t fn ) { start( fn, NULL, StackDepth, core_no); } void stop();