Fan Control Demo

Dependencies:   mbed-rtos mbed

Fork of mbed_fota by KIM HyoengJun

Revision:
12:e3d3676753cc
Parent:
8:9eec2c246a85
diff -r 1ed93accb3fb -r e3d3676753cc main.cpp
--- a/main.cpp	Mon Aug 24 03:24:19 2015 +0000
+++ b/main.cpp	Wed Sep 02 07:44:29 2015 +0000
@@ -10,7 +10,10 @@
 
 
 #include "mbed.h"
+#include "cmsis_os.h"
 #include "BleMsgHandler.h"
+#include "fan_control_task.h"
+#include "dialog_fota_config.h"
 #include "app.h"
 
 Serial hostpc(USBTX,USBRX);
@@ -21,8 +24,68 @@
 DigitalOut myled3(LED3);
 DigitalOut myled4(LED4);
 
+DigitalOut port18(p18);//mid
+DigitalOut port19(p19);//low
+DigitalOut port20(p20);//high
+
+uint8_t Timer_flag;
+uint32_t Residual_Time;
+
 using namespace sevencore_fota;
 
+
+void FanTimer(void const *threadarg)
+{
+    Timer_flag = 0;
+    Residual_Time = 0;
+    BleMsgHandler *BMH;
+    BMH = (struct BleMsgHandler *) threadarg;
+    while(true)
+    {
+        if( Timer_flag == 1 && Residual_Time == 0 )
+        {
+            hostpc.printf("Power off!!\n");
+            if( port18 == 1 || port19 == 1 || port20 == 1 )
+                port18 = port19 = port20 = 0;
+            Timer_flag = 0;
+            /*{
+                uint8_t fota_normal = 0;
+                uint8_t *msg;
+                struct fan_control_set_char_val_req char_set_req;
+                unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
+                // Fill in the parameter structure
+                char_set_req.char_code     = FAN_CONTROL_POWER_STATE_CHAR;
+                char_set_req.val_len       = FAN_CONTROL_MIN_SIZE;
+                memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal));
+                
+                msg = new uint8_t[msg_size];
+                
+                BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ
+                    ,TASK_FAN_CONTROL, TASK_GTL
+                    ,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE)
+                    ,&char_set_req,msg );
+                // Send the message
+                BMH->BleSendMsg(msg,msg_size);                
+                free(msg);
+            }
+            */
+            
+        }
+    
+        if( Timer_flag == 1 )
+        {
+            osDelay(1000);
+            if(Residual_Time > 0){
+                hostpc.printf("Residual Time = %d, minus 1 second!!\n",Residual_Time );
+                Residual_Time--;
+            }
+        }
+    }
+}
+
+void t0(void const *argument) {FanTimer(argument);}
+osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE);
+
 void led_setting_one(void){
     myled = 1;
     myled2 = 1;
@@ -31,7 +94,7 @@
 }
 
 void led_setting_zero(void){
-    myled = 0;
+    myled = 1;
     myled2 = 0;
     myled3 = 0;
     myled4 = 0;
@@ -47,7 +110,7 @@
     wait(0.5);
     myled = 0;
     wait(0.5);
-    led_setting_one(); 
+    led_setting_zero(); 
     wait(0.5);
     hostpc.baud(9600);
     wait(0.5);
@@ -56,6 +119,7 @@
     wait(0.5);
     
     BleMsgHandler myfota(&device,&hostpc);   
+    osThreadCreate( osThread(t0), (void *)&myfota );
     
     myfota.PrintTitle();
     app_rst_gap(&myfota);