![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
main.cpp@12:e3d3676753cc, 2015-09-02 (annotated)
- Committer:
- dudnwjs
- Date:
- Wed Sep 02 07:44:29 2015 +0000
- Revision:
- 12:e3d3676753cc
- Parent:
- 8:9eec2c246a85
- Child:
- 13:e714e2971c49
Fan Control Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 8:9eec2c246a85 | 1 | /** |
dudnwjs | 8:9eec2c246a85 | 2 | * @file main.cpp |
dudnwjs | 8:9eec2c246a85 | 3 | * @brief interface configuration & main loop start |
dudnwjs | 8:9eec2c246a85 | 4 | * Copyright 2015 SEVENCORE Co., Ltd. |
dudnwjs | 8:9eec2c246a85 | 5 | * |
dudnwjs | 8:9eec2c246a85 | 6 | * @author HyeongJun Kim |
dudnwjs | 8:9eec2c246a85 | 7 | * @version 1.0.0 |
dudnwjs | 8:9eec2c246a85 | 8 | * @since 2015-08-17 |
dudnwjs | 8:9eec2c246a85 | 9 | */ |
dudnwjs | 8:9eec2c246a85 | 10 | |
dudnwjs | 8:9eec2c246a85 | 11 | |
dudnwjs | 0:a1f6b1ba8a1e | 12 | #include "mbed.h" |
dudnwjs | 12:e3d3676753cc | 13 | #include "cmsis_os.h" |
dudnwjs | 1:5cf3a6c969be | 14 | #include "BleMsgHandler.h" |
dudnwjs | 12:e3d3676753cc | 15 | #include "fan_control_task.h" |
dudnwjs | 12:e3d3676753cc | 16 | #include "dialog_fota_config.h" |
dudnwjs | 3:1e70387e1337 | 17 | #include "app.h" |
dudnwjs | 0:a1f6b1ba8a1e | 18 | |
dudnwjs | 0:a1f6b1ba8a1e | 19 | Serial hostpc(USBTX,USBRX); |
dudnwjs | 0:a1f6b1ba8a1e | 20 | Serial device(p13,p14); |
dudnwjs | 6:8dd20294b2aa | 21 | LocalFileSystem local("local"); // Create the local filesystem |
dudnwjs | 0:a1f6b1ba8a1e | 22 | DigitalOut myled(LED1); |
dudnwjs | 6:8dd20294b2aa | 23 | DigitalOut myled2(LED2); |
dudnwjs | 6:8dd20294b2aa | 24 | DigitalOut myled3(LED3); |
dudnwjs | 6:8dd20294b2aa | 25 | DigitalOut myled4(LED4); |
dudnwjs | 0:a1f6b1ba8a1e | 26 | |
dudnwjs | 12:e3d3676753cc | 27 | DigitalOut port18(p18);//mid |
dudnwjs | 12:e3d3676753cc | 28 | DigitalOut port19(p19);//low |
dudnwjs | 12:e3d3676753cc | 29 | DigitalOut port20(p20);//high |
dudnwjs | 12:e3d3676753cc | 30 | |
dudnwjs | 12:e3d3676753cc | 31 | uint8_t Timer_flag; |
dudnwjs | 12:e3d3676753cc | 32 | uint32_t Residual_Time; |
dudnwjs | 12:e3d3676753cc | 33 | |
dudnwjs | 1:5cf3a6c969be | 34 | using namespace sevencore_fota; |
dudnwjs | 1:5cf3a6c969be | 35 | |
dudnwjs | 12:e3d3676753cc | 36 | |
dudnwjs | 12:e3d3676753cc | 37 | void FanTimer(void const *threadarg) |
dudnwjs | 12:e3d3676753cc | 38 | { |
dudnwjs | 12:e3d3676753cc | 39 | Timer_flag = 0; |
dudnwjs | 12:e3d3676753cc | 40 | Residual_Time = 0; |
dudnwjs | 12:e3d3676753cc | 41 | BleMsgHandler *BMH; |
dudnwjs | 12:e3d3676753cc | 42 | BMH = (struct BleMsgHandler *) threadarg; |
dudnwjs | 12:e3d3676753cc | 43 | while(true) |
dudnwjs | 12:e3d3676753cc | 44 | { |
dudnwjs | 12:e3d3676753cc | 45 | if( Timer_flag == 1 && Residual_Time == 0 ) |
dudnwjs | 12:e3d3676753cc | 46 | { |
dudnwjs | 12:e3d3676753cc | 47 | hostpc.printf("Power off!!\n"); |
dudnwjs | 12:e3d3676753cc | 48 | if( port18 == 1 || port19 == 1 || port20 == 1 ) |
dudnwjs | 12:e3d3676753cc | 49 | port18 = port19 = port20 = 0; |
dudnwjs | 12:e3d3676753cc | 50 | Timer_flag = 0; |
dudnwjs | 12:e3d3676753cc | 51 | /*{ |
dudnwjs | 12:e3d3676753cc | 52 | uint8_t fota_normal = 0; |
dudnwjs | 12:e3d3676753cc | 53 | uint8_t *msg; |
dudnwjs | 12:e3d3676753cc | 54 | struct fan_control_set_char_val_req char_set_req; |
dudnwjs | 12:e3d3676753cc | 55 | unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE); |
dudnwjs | 12:e3d3676753cc | 56 | // Fill in the parameter structure |
dudnwjs | 12:e3d3676753cc | 57 | char_set_req.char_code = FAN_CONTROL_POWER_STATE_CHAR; |
dudnwjs | 12:e3d3676753cc | 58 | char_set_req.val_len = FAN_CONTROL_MIN_SIZE; |
dudnwjs | 12:e3d3676753cc | 59 | memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal)); |
dudnwjs | 12:e3d3676753cc | 60 | |
dudnwjs | 12:e3d3676753cc | 61 | msg = new uint8_t[msg_size]; |
dudnwjs | 12:e3d3676753cc | 62 | |
dudnwjs | 12:e3d3676753cc | 63 | BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ |
dudnwjs | 12:e3d3676753cc | 64 | ,TASK_FAN_CONTROL, TASK_GTL |
dudnwjs | 12:e3d3676753cc | 65 | ,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE) |
dudnwjs | 12:e3d3676753cc | 66 | ,&char_set_req,msg ); |
dudnwjs | 12:e3d3676753cc | 67 | // Send the message |
dudnwjs | 12:e3d3676753cc | 68 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 12:e3d3676753cc | 69 | free(msg); |
dudnwjs | 12:e3d3676753cc | 70 | } |
dudnwjs | 12:e3d3676753cc | 71 | */ |
dudnwjs | 12:e3d3676753cc | 72 | |
dudnwjs | 12:e3d3676753cc | 73 | } |
dudnwjs | 12:e3d3676753cc | 74 | |
dudnwjs | 12:e3d3676753cc | 75 | if( Timer_flag == 1 ) |
dudnwjs | 12:e3d3676753cc | 76 | { |
dudnwjs | 12:e3d3676753cc | 77 | osDelay(1000); |
dudnwjs | 12:e3d3676753cc | 78 | if(Residual_Time > 0){ |
dudnwjs | 12:e3d3676753cc | 79 | hostpc.printf("Residual Time = %d, minus 1 second!!\n",Residual_Time ); |
dudnwjs | 12:e3d3676753cc | 80 | Residual_Time--; |
dudnwjs | 12:e3d3676753cc | 81 | } |
dudnwjs | 12:e3d3676753cc | 82 | } |
dudnwjs | 12:e3d3676753cc | 83 | } |
dudnwjs | 12:e3d3676753cc | 84 | } |
dudnwjs | 12:e3d3676753cc | 85 | |
dudnwjs | 12:e3d3676753cc | 86 | void t0(void const *argument) {FanTimer(argument);} |
dudnwjs | 12:e3d3676753cc | 87 | osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE); |
dudnwjs | 12:e3d3676753cc | 88 | |
dudnwjs | 7:3478c46cceef | 89 | void led_setting_one(void){ |
dudnwjs | 6:8dd20294b2aa | 90 | myled = 1; |
dudnwjs | 6:8dd20294b2aa | 91 | myled2 = 1; |
dudnwjs | 6:8dd20294b2aa | 92 | myled3 = 1; |
dudnwjs | 6:8dd20294b2aa | 93 | myled4 = 1; |
dudnwjs | 6:8dd20294b2aa | 94 | } |
dudnwjs | 6:8dd20294b2aa | 95 | |
dudnwjs | 7:3478c46cceef | 96 | void led_setting_zero(void){ |
dudnwjs | 12:e3d3676753cc | 97 | myled = 1; |
dudnwjs | 6:8dd20294b2aa | 98 | myled2 = 0; |
dudnwjs | 6:8dd20294b2aa | 99 | myled3 = 0; |
dudnwjs | 6:8dd20294b2aa | 100 | myled4 = 0; |
dudnwjs | 6:8dd20294b2aa | 101 | } |
dudnwjs | 6:8dd20294b2aa | 102 | |
dudnwjs | 6:8dd20294b2aa | 103 | int main() { |
dudnwjs | 8:9eec2c246a85 | 104 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 105 | myled = 1; |
dudnwjs | 8:9eec2c246a85 | 106 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 107 | myled = 0; |
dudnwjs | 8:9eec2c246a85 | 108 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 109 | myled = 1; |
dudnwjs | 8:9eec2c246a85 | 110 | wait(0.5); |
dudnwjs | 8:9eec2c246a85 | 111 | myled = 0; |
dudnwjs | 8:9eec2c246a85 | 112 | wait(0.5); |
dudnwjs | 12:e3d3676753cc | 113 | led_setting_zero(); |
dudnwjs | 8:9eec2c246a85 | 114 | wait(0.5); |
dudnwjs | 5:e11b23f9aacc | 115 | hostpc.baud(9600); |
dudnwjs | 8:9eec2c246a85 | 116 | wait(0.5); |
dudnwjs | 3:1e70387e1337 | 117 | device.baud(115200); |
dudnwjs | 6:8dd20294b2aa | 118 | device.set_flow_control(device.RTSCTS,P2_7,p12); |
dudnwjs | 8:9eec2c246a85 | 119 | wait(0.5); |
dudnwjs | 3:1e70387e1337 | 120 | |
dudnwjs | 5:e11b23f9aacc | 121 | BleMsgHandler myfota(&device,&hostpc); |
dudnwjs | 12:e3d3676753cc | 122 | osThreadCreate( osThread(t0), (void *)&myfota ); |
dudnwjs | 6:8dd20294b2aa | 123 | |
dudnwjs | 1:5cf3a6c969be | 124 | myfota.PrintTitle(); |
dudnwjs | 3:1e70387e1337 | 125 | app_rst_gap(&myfota); |
dudnwjs | 3:1e70387e1337 | 126 | |
dudnwjs | 8:9eec2c246a85 | 127 | for(int i = 0; i < 200; i++) { |
dudnwjs | 4:60be78a172c2 | 128 | myfota.BleReceiveMsg(); |
dudnwjs | 4:60be78a172c2 | 129 | myfota.BleMsgHandle(); |
dudnwjs | 4:60be78a172c2 | 130 | } |
dudnwjs | 3:1e70387e1337 | 131 | |
dudnwjs | 0:a1f6b1ba8a1e | 132 | while(1) { |
dudnwjs | 0:a1f6b1ba8a1e | 133 | myled = 1; |
dudnwjs | 0:a1f6b1ba8a1e | 134 | wait(0.5); |
dudnwjs | 0:a1f6b1ba8a1e | 135 | myled = 0; |
dudnwjs | 0:a1f6b1ba8a1e | 136 | wait(0.5); |
dudnwjs | 0:a1f6b1ba8a1e | 137 | } |
dudnwjs | 5:e11b23f9aacc | 138 | |
dudnwjs | 0:a1f6b1ba8a1e | 139 | } |