test
Dependencies: mbed-STM32F103C8T6 SHT21_ncleee
main.cpp@1:0fe432e5dfc4, 2020-04-15 (annotated)
- Committer:
- bbw
- Date:
- Wed Apr 15 11:36:03 2020 +0000
- Revision:
- 1:0fe432e5dfc4
- Parent:
- 0:217105958c2d
Test_bob_0415
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
techneo | 0:217105958c2d | 1 | #include "mbed.h" |
bbw | 1:0fe432e5dfc4 | 2 | //#include "rtos.h" |
bbw | 1:0fe432e5dfc4 | 3 | #include "stm32f103c8t6.h" |
bbw | 1:0fe432e5dfc4 | 4 | #include "ATCmdParser.h" |
bbw | 1:0fe432e5dfc4 | 5 | #include "UARTSerial.h" |
bbw | 1:0fe432e5dfc4 | 6 | //#include "Thread.h" |
bbw | 1:0fe432e5dfc4 | 7 | |
bbw | 1:0fe432e5dfc4 | 8 | DigitalOut MOTOA1(PB_4); |
bbw | 1:0fe432e5dfc4 | 9 | DigitalOut MOTOB1(PB_5); |
bbw | 1:0fe432e5dfc4 | 10 | |
bbw | 1:0fe432e5dfc4 | 11 | DigitalOut MOTOA2(PB_8); |
bbw | 1:0fe432e5dfc4 | 12 | DigitalOut MOTOB2(PB_9); |
bbw | 1:0fe432e5dfc4 | 13 | |
bbw | 1:0fe432e5dfc4 | 14 | Serial debug_uart(PB_10, PB_11); |
bbw | 1:0fe432e5dfc4 | 15 | |
bbw | 1:0fe432e5dfc4 | 16 | AnalogIn SensorCurrent(PA_0); |
bbw | 1:0fe432e5dfc4 | 17 | |
bbw | 1:0fe432e5dfc4 | 18 | AnalogIn BatteryVoltage(PA_1); |
bbw | 1:0fe432e5dfc4 | 19 | |
bbw | 1:0fe432e5dfc4 | 20 | void motor1_move(uint8_t dir); |
bbw | 1:0fe432e5dfc4 | 21 | void motor2_move(uint8_t dir); |
bbw | 1:0fe432e5dfc4 | 22 | |
bbw | 1:0fe432e5dfc4 | 23 | void system_init(); |
bbw | 1:0fe432e5dfc4 | 24 | |
bbw | 1:0fe432e5dfc4 | 25 | UARTSerial *_serial; |
bbw | 1:0fe432e5dfc4 | 26 | |
bbw | 1:0fe432e5dfc4 | 27 | //Thread thread1,thread2,thread3; |
bbw | 1:0fe432e5dfc4 | 28 | |
bbw | 1:0fe432e5dfc4 | 29 | #if 1 |
bbw | 1:0fe432e5dfc4 | 30 | |
bbw | 1:0fe432e5dfc4 | 31 | uint8_t sensor_cnt,cal_cnt; |
bbw | 1:0fe432e5dfc4 | 32 | uint8_t dir; |
bbw | 1:0fe432e5dfc4 | 33 | float sense_value; |
bbw | 1:0fe432e5dfc4 | 34 | uint8_t ov_flag, init_flag, motor1_ready_flag, motor2_ready_flag, sensor_flag; |
bbw | 1:0fe432e5dfc4 | 35 | |
bbw | 1:0fe432e5dfc4 | 36 | #endif |
bbw | 1:0fe432e5dfc4 | 37 | |
bbw | 1:0fe432e5dfc4 | 38 | void sensor_capture_cb(void){ |
bbw | 1:0fe432e5dfc4 | 39 | sensor_cnt++; |
bbw | 1:0fe432e5dfc4 | 40 | } |
bbw | 1:0fe432e5dfc4 | 41 | |
bbw | 1:0fe432e5dfc4 | 42 | #define MAX_LENGTH_STEPS 55 |
bbw | 1:0fe432e5dfc4 | 43 | #define MIN_LENGTH_STEPS 10 |
bbw | 1:0fe432e5dfc4 | 44 | #define MOVING_UP 1 |
bbw | 1:0fe432e5dfc4 | 45 | #define MOVING_DOWN 2 |
bbw | 1:0fe432e5dfc4 | 46 | #define MOVING_FORWARD 1 |
bbw | 1:0fe432e5dfc4 | 47 | #define MOVING_BACKWARD 2 |
bbw | 1:0fe432e5dfc4 | 48 | #define STOP 0 |
bbw | 1:0fe432e5dfc4 | 49 | |
bbw | 1:0fe432e5dfc4 | 50 | #if 1 |
bbw | 1:0fe432e5dfc4 | 51 | |
bbw | 1:0fe432e5dfc4 | 52 | void Power_thread(void const *argument){/*detect current*/ |
bbw | 1:0fe432e5dfc4 | 53 | uint8_t i = 0; |
bbw | 1:0fe432e5dfc4 | 54 | while(true){ |
bbw | 1:0fe432e5dfc4 | 55 | Thread::wait(500); /*unit millisec*/ |
bbw | 1:0fe432e5dfc4 | 56 | //debug_uart.printf("Power_thread 11111111111111\r\n"); |
bbw | 1:0fe432e5dfc4 | 57 | //debug_uart.printf("sensor_cnt = %d\r\n", sensor_cnt); |
bbw | 1:0fe432e5dfc4 | 58 | sense_value = SensorCurrent.read(); |
bbw | 1:0fe432e5dfc4 | 59 | //debug_uart.printf("current sense_value2 =%0.4f \r\n", sense_value); |
bbw | 1:0fe432e5dfc4 | 60 | if((sense_value>0.8)&&sensor_flag){ |
bbw | 1:0fe432e5dfc4 | 61 | debug_uart.printf("sense_value = %0.4f > 0.4 \r\n", sense_value); |
bbw | 1:0fe432e5dfc4 | 62 | ov_flag = 1; |
bbw | 1:0fe432e5dfc4 | 63 | //if(motor2_ready_flag){ |
bbw | 1:0fe432e5dfc4 | 64 | //motor2_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 65 | //while(1){motor1_move(STOP);} |
bbw | 1:0fe432e5dfc4 | 66 | //} |
bbw | 1:0fe432e5dfc4 | 67 | } |
bbw | 1:0fe432e5dfc4 | 68 | } |
bbw | 1:0fe432e5dfc4 | 69 | } |
techneo | 0:217105958c2d | 70 | |
bbw | 1:0fe432e5dfc4 | 71 | void Motor1_thread(void const *argument){/*detect current*/ |
bbw | 1:0fe432e5dfc4 | 72 | uint8_t i; |
bbw | 1:0fe432e5dfc4 | 73 | while(true){ |
bbw | 1:0fe432e5dfc4 | 74 | Thread::wait(300); /*unit millisec*/ |
bbw | 1:0fe432e5dfc4 | 75 | if(motor2_ready_flag){ |
bbw | 1:0fe432e5dfc4 | 76 | sensor_cnt = 0; |
bbw | 1:0fe432e5dfc4 | 77 | motor1_move(MOVING_FORWARD); |
bbw | 1:0fe432e5dfc4 | 78 | wait(1); |
bbw | 1:0fe432e5dfc4 | 79 | sensor_flag = 1; |
bbw | 1:0fe432e5dfc4 | 80 | while(!ov_flag){debug_uart.printf("xxxxxxxxxxxxxxxxx \r\n"); wait(1);} |
bbw | 1:0fe432e5dfc4 | 81 | motor1_move(STOP); |
bbw | 1:0fe432e5dfc4 | 82 | debug_uart.printf("overcurrent detected \r\n"); |
bbw | 1:0fe432e5dfc4 | 83 | ov_flag = 0; |
bbw | 1:0fe432e5dfc4 | 84 | motor2_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 85 | cal_cnt = sensor_cnt; |
bbw | 1:0fe432e5dfc4 | 86 | debug_uart.printf("calibration done \r\n"); |
bbw | 1:0fe432e5dfc4 | 87 | debug_uart.printf("calibrated cnt is %d \r\n", cal_cnt); |
bbw | 1:0fe432e5dfc4 | 88 | wait(2); |
bbw | 1:0fe432e5dfc4 | 89 | debug_uart.printf("back to origianl position, motor1_ready_flag = 1\r\n"); |
bbw | 1:0fe432e5dfc4 | 90 | motor1_ready_flag = 1; |
bbw | 1:0fe432e5dfc4 | 91 | while(1){ |
bbw | 1:0fe432e5dfc4 | 92 | if(motor2_ready_flag){break;}else{ |
bbw | 1:0fe432e5dfc4 | 93 | wait(1); |
bbw | 1:0fe432e5dfc4 | 94 | debug_uart.printf("thread2----wait for motor2 ready\r\n"); //wait(1); |
bbw | 1:0fe432e5dfc4 | 95 | } |
bbw | 1:0fe432e5dfc4 | 96 | } |
bbw | 1:0fe432e5dfc4 | 97 | motor2_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 98 | sensor_cnt = 0; |
bbw | 1:0fe432e5dfc4 | 99 | sensor_flag = 0; |
bbw | 1:0fe432e5dfc4 | 100 | motor1_move(MOVING_BACKWARD); |
bbw | 1:0fe432e5dfc4 | 101 | debug_uart.printf("current cal_cnt is %d\r\n", cal_cnt); |
bbw | 1:0fe432e5dfc4 | 102 | //while(sensor_cnt<(cal_cnt-10)){debug_uart.printf("sensor cnt is %d\r\n", sensor_cnt);} |
bbw | 1:0fe432e5dfc4 | 103 | while(1){ |
bbw | 1:0fe432e5dfc4 | 104 | if(sensor_cnt>(cal_cnt-10)){break;}else{ |
bbw | 1:0fe432e5dfc4 | 105 | wait_ms(10); |
bbw | 1:0fe432e5dfc4 | 106 | //debug_uart.printf("sensor cnt is %d \r\n", sensor_cnt); |
bbw | 1:0fe432e5dfc4 | 107 | } |
bbw | 1:0fe432e5dfc4 | 108 | } |
bbw | 1:0fe432e5dfc4 | 109 | debug_uart.printf("xxxxxxxxxx----------sensor cnt is %d \r\n", sensor_cnt); |
bbw | 1:0fe432e5dfc4 | 110 | //debug_uart.printf("sensor cnt is higher than equal cal_cnt - 10 \r\n"); |
bbw | 1:0fe432e5dfc4 | 111 | motor1_move(STOP); |
bbw | 1:0fe432e5dfc4 | 112 | wait(2); |
bbw | 1:0fe432e5dfc4 | 113 | motor1_ready_flag = 1; |
bbw | 1:0fe432e5dfc4 | 114 | //if(ov_flag){ov_flag = 0;} |
bbw | 1:0fe432e5dfc4 | 115 | } |
bbw | 1:0fe432e5dfc4 | 116 | } |
bbw | 1:0fe432e5dfc4 | 117 | } |
bbw | 1:0fe432e5dfc4 | 118 | |
bbw | 1:0fe432e5dfc4 | 119 | void Motor2_thread(void const *argument){/*detect current*/ |
bbw | 1:0fe432e5dfc4 | 120 | uint8_t sta1,sta2; |
bbw | 1:0fe432e5dfc4 | 121 | DigitalIn Stopper1(PA_13); |
bbw | 1:0fe432e5dfc4 | 122 | DigitalIn Stopper2(PA_15); |
bbw | 1:0fe432e5dfc4 | 123 | |
bbw | 1:0fe432e5dfc4 | 124 | while(true){ |
bbw | 1:0fe432e5dfc4 | 125 | Thread::wait(300); /*unit millisec*/ |
bbw | 1:0fe432e5dfc4 | 126 | if(!init_flag){ |
bbw | 1:0fe432e5dfc4 | 127 | #if 1 |
bbw | 1:0fe432e5dfc4 | 128 | wait(1); |
bbw | 1:0fe432e5dfc4 | 129 | debug_uart.printf("thread 2 start \r\n"); |
bbw | 1:0fe432e5dfc4 | 130 | motor2_move(MOVING_UP); |
bbw | 1:0fe432e5dfc4 | 131 | while(Stopper1){;} |
bbw | 1:0fe432e5dfc4 | 132 | motor2_move(STOP); |
bbw | 1:0fe432e5dfc4 | 133 | debug_uart.printf("up stopper1 triggered \r\n"); |
bbw | 1:0fe432e5dfc4 | 134 | //init_flag = 1; |
bbw | 1:0fe432e5dfc4 | 135 | motor2_ready_flag = 1; |
bbw | 1:0fe432e5dfc4 | 136 | wait(1); |
bbw | 1:0fe432e5dfc4 | 137 | //while(!motor1_ready_flag){debug_uart.printf("wait for motor1 ready\r\n");wait(1);} |
bbw | 1:0fe432e5dfc4 | 138 | while(1){ |
bbw | 1:0fe432e5dfc4 | 139 | if(motor1_ready_flag){break;}else{ |
bbw | 1:0fe432e5dfc4 | 140 | wait(1); |
bbw | 1:0fe432e5dfc4 | 141 | debug_uart.printf("thread2----wait for motor1 ready \r\n"); |
bbw | 1:0fe432e5dfc4 | 142 | } |
bbw | 1:0fe432e5dfc4 | 143 | } |
bbw | 1:0fe432e5dfc4 | 144 | debug_uart.printf("motor1 is ready\r\n"); |
bbw | 1:0fe432e5dfc4 | 145 | motor1_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 146 | motor2_move(MOVING_DOWN); |
bbw | 1:0fe432e5dfc4 | 147 | while(Stopper2){;} |
bbw | 1:0fe432e5dfc4 | 148 | motor2_move(STOP); |
bbw | 1:0fe432e5dfc4 | 149 | debug_uart.printf("down stopper1 triggered \r\n"); |
bbw | 1:0fe432e5dfc4 | 150 | motor2_ready_flag = 1; |
bbw | 1:0fe432e5dfc4 | 151 | init_flag = 1; |
bbw | 1:0fe432e5dfc4 | 152 | //while(!motor1_ready_flag){debug_uart.printf("wait for finish\r\n");wait(1);} |
bbw | 1:0fe432e5dfc4 | 153 | while(1){ |
bbw | 1:0fe432e5dfc4 | 154 | if(motor1_ready_flag){break;}else{ |
bbw | 1:0fe432e5dfc4 | 155 | wait(1); |
bbw | 1:0fe432e5dfc4 | 156 | debug_uart.printf("thread2----wait for motor1 ready \r\n"); |
bbw | 1:0fe432e5dfc4 | 157 | } |
bbw | 1:0fe432e5dfc4 | 158 | } |
bbw | 1:0fe432e5dfc4 | 159 | debug_uart.printf("move motor2 to center\r\n"); |
bbw | 1:0fe432e5dfc4 | 160 | motor2_move(MOVING_UP); |
bbw | 1:0fe432e5dfc4 | 161 | wait(1.5); |
bbw | 1:0fe432e5dfc4 | 162 | motor2_move(STOP); |
bbw | 1:0fe432e5dfc4 | 163 | debug_uart.printf("motor2 thread done\r\n"); |
bbw | 1:0fe432e5dfc4 | 164 | #endif |
bbw | 1:0fe432e5dfc4 | 165 | } |
bbw | 1:0fe432e5dfc4 | 166 | } |
bbw | 1:0fe432e5dfc4 | 167 | } |
techneo | 0:217105958c2d | 168 | |
techneo | 0:217105958c2d | 169 | |
bbw | 1:0fe432e5dfc4 | 170 | #endif |
bbw | 1:0fe432e5dfc4 | 171 | |
bbw | 1:0fe432e5dfc4 | 172 | int main(){ |
bbw | 1:0fe432e5dfc4 | 173 | wait(2); |
techneo | 0:217105958c2d | 174 | |
bbw | 1:0fe432e5dfc4 | 175 | system_init(); |
bbw | 1:0fe432e5dfc4 | 176 | |
bbw | 1:0fe432e5dfc4 | 177 | InterruptIn Hall1(PA_14); |
bbw | 1:0fe432e5dfc4 | 178 | //InterruptIn Hall2(PB_3); |
bbw | 1:0fe432e5dfc4 | 179 | Hall1.fall(callback(sensor_capture_cb)); // Attach ISR to handle button press event |
bbw | 1:0fe432e5dfc4 | 180 | //Hall2.fall(callback(sensor_capture_cb)); // Attach ISR to handle button press event |
bbw | 1:0fe432e5dfc4 | 181 | debug_uart.printf("Hall1 init done\r\n"); |
techneo | 0:217105958c2d | 182 | |
bbw | 1:0fe432e5dfc4 | 183 | //Thread thread1(osPriorityNormal,2048,Power_thread, NULL); /*check the real-time current*/ |
bbw | 1:0fe432e5dfc4 | 184 | |
bbw | 1:0fe432e5dfc4 | 185 | #if 0 |
bbw | 1:0fe432e5dfc4 | 186 | thread1.start(Power_thread); |
bbw | 1:0fe432e5dfc4 | 187 | debug_uart.printf("thread1~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 188 | thread2.start(Motor1_thread); |
bbw | 1:0fe432e5dfc4 | 189 | debug_uart.printf("thread2~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 190 | thread3.start(Motor2_thread); |
bbw | 1:0fe432e5dfc4 | 191 | debug_uart.printf("thread3~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 192 | #endif |
bbw | 1:0fe432e5dfc4 | 193 | |
bbw | 1:0fe432e5dfc4 | 194 | #if 1 |
bbw | 1:0fe432e5dfc4 | 195 | |
bbw | 1:0fe432e5dfc4 | 196 | Thread thread1(Power_thread, NULL, osPriorityNormal, 2048); |
bbw | 1:0fe432e5dfc4 | 197 | Thread thread2(Motor1_thread, NULL, osPriorityNormal, 2048); |
bbw | 1:0fe432e5dfc4 | 198 | Thread thread3(Motor1_thread, NULL, osPriorityNormal, 2048); |
bbw | 1:0fe432e5dfc4 | 199 | #endif |
bbw | 1:0fe432e5dfc4 | 200 | |
bbw | 1:0fe432e5dfc4 | 201 | #if 0 |
bbw | 1:0fe432e5dfc4 | 202 | debug_uart.printf("thread1~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 203 | Thread thread2(osPriorityNormal,2048,Motor1_thread, NULL); /*check the real-time current*/ |
bbw | 1:0fe432e5dfc4 | 204 | //Thread thread2(Motor1_thread, NULL, osPriorityNormal, 512); /*check the real-time current*/ |
bbw | 1:0fe432e5dfc4 | 205 | debug_uart.printf("thread2~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 206 | Thread thread3(osPriorityNormal,2048,Motor2_thread,NULL); /*check the real-time current*/ |
bbw | 1:0fe432e5dfc4 | 207 | //Thread thread3(Motor2_thread, NULL, osPriorityNormal, 512); /*check the real-time current*/ |
bbw | 1:0fe432e5dfc4 | 208 | debug_uart.printf("thread3~~~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 209 | #endif |
bbw | 1:0fe432e5dfc4 | 210 | |
bbw | 1:0fe432e5dfc4 | 211 | |
bbw | 1:0fe432e5dfc4 | 212 | |
bbw | 1:0fe432e5dfc4 | 213 | init_flag = 0; |
bbw | 1:0fe432e5dfc4 | 214 | //motor2_ready_flag = 1; |
bbw | 1:0fe432e5dfc4 | 215 | //motor2_move(MOVING_DOWN); |
bbw | 1:0fe432e5dfc4 | 216 | while(1){ |
bbw | 1:0fe432e5dfc4 | 217 | //debug_uart.printf("~~~~~~~~~~~~~~\r\n"); |
bbw | 1:0fe432e5dfc4 | 218 | wait(1); |
bbw | 1:0fe432e5dfc4 | 219 | //sense_value = SensorCurrent.read(); |
bbw | 1:0fe432e5dfc4 | 220 | debug_uart.printf("current sense_value2 =%0.4f \r\n", sense_value); |
techneo | 0:217105958c2d | 221 | } |
techneo | 0:217105958c2d | 222 | } |
techneo | 0:217105958c2d | 223 | |
techneo | 0:217105958c2d | 224 | |
techneo | 0:217105958c2d | 225 | |
bbw | 1:0fe432e5dfc4 | 226 | |
bbw | 1:0fe432e5dfc4 | 227 | void motor1_move(uint8_t dir){/*main motor*/ |
bbw | 1:0fe432e5dfc4 | 228 | if(dir==1){/*forward*/ |
bbw | 1:0fe432e5dfc4 | 229 | MOTOA1 = 0; |
bbw | 1:0fe432e5dfc4 | 230 | MOTOB1 = 1; |
bbw | 1:0fe432e5dfc4 | 231 | }else if(dir==2){/*backward*/ |
bbw | 1:0fe432e5dfc4 | 232 | MOTOA1 = 1; |
bbw | 1:0fe432e5dfc4 | 233 | MOTOB1 = 0; |
bbw | 1:0fe432e5dfc4 | 234 | }else{ /*stop*/ |
bbw | 1:0fe432e5dfc4 | 235 | MOTOA1 = 0; |
bbw | 1:0fe432e5dfc4 | 236 | MOTOB1 = 0; |
bbw | 1:0fe432e5dfc4 | 237 | } |
bbw | 1:0fe432e5dfc4 | 238 | } |
bbw | 1:0fe432e5dfc4 | 239 | |
bbw | 1:0fe432e5dfc4 | 240 | void motor2_move(uint8_t dir){/*assistant motor*/ |
bbw | 1:0fe432e5dfc4 | 241 | if(dir==1){/*up*/ |
bbw | 1:0fe432e5dfc4 | 242 | MOTOA2 = 0; |
bbw | 1:0fe432e5dfc4 | 243 | MOTOB2 = 1; |
bbw | 1:0fe432e5dfc4 | 244 | }else if(dir==2){/*down*/ |
bbw | 1:0fe432e5dfc4 | 245 | MOTOA2 = 1; |
bbw | 1:0fe432e5dfc4 | 246 | MOTOB2 = 0; |
bbw | 1:0fe432e5dfc4 | 247 | }else{ /*stop*/ |
bbw | 1:0fe432e5dfc4 | 248 | MOTOA2 = 0; |
bbw | 1:0fe432e5dfc4 | 249 | MOTOB2 = 0; |
bbw | 1:0fe432e5dfc4 | 250 | } |
bbw | 1:0fe432e5dfc4 | 251 | } |
bbw | 1:0fe432e5dfc4 | 252 | |
bbw | 1:0fe432e5dfc4 | 253 | void system_init(){ |
bbw | 1:0fe432e5dfc4 | 254 | |
bbw | 1:0fe432e5dfc4 | 255 | debug_uart.baud(115200); |
bbw | 1:0fe432e5dfc4 | 256 | /* |
bbw | 1:0fe432e5dfc4 | 257 | lcdBus.write(0x00); |
bbw | 1:0fe432e5dfc4 | 258 | TFTRD = 0; |
bbw | 1:0fe432e5dfc4 | 259 | TFTWR = 0; |
bbw | 1:0fe432e5dfc4 | 260 | TFTDC = 0; |
bbw | 1:0fe432e5dfc4 | 261 | TFTCS = 0; |
bbw | 1:0fe432e5dfc4 | 262 | */ |
bbw | 1:0fe432e5dfc4 | 263 | MOTOA1 = 0; |
bbw | 1:0fe432e5dfc4 | 264 | MOTOB1 = 0; |
bbw | 1:0fe432e5dfc4 | 265 | MOTOA2 = 0; |
bbw | 1:0fe432e5dfc4 | 266 | MOTOB2 = 0; |
bbw | 1:0fe432e5dfc4 | 267 | init_flag = 0; |
bbw | 1:0fe432e5dfc4 | 268 | motor1_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 269 | motor2_ready_flag = 0; |
bbw | 1:0fe432e5dfc4 | 270 | sense_value = 0; |
bbw | 1:0fe432e5dfc4 | 271 | sensor_flag = 0; |
bbw | 1:0fe432e5dfc4 | 272 | |
bbw | 1:0fe432e5dfc4 | 273 | debug_uart.printf("system init done\r\n"); |
bbw | 1:0fe432e5dfc4 | 274 | |
bbw | 1:0fe432e5dfc4 | 275 | } |
bbw | 1:0fe432e5dfc4 | 276 | #if 0 |
bbw | 1:0fe432e5dfc4 | 277 | void wifi_debug(){ |
bbw | 1:0fe432e5dfc4 | 278 | wifi_uart.baud(115200); |
bbw | 1:0fe432e5dfc4 | 279 | debug_uart.baud(115200); |
bbw | 1:0fe432e5dfc4 | 280 | WIFI_PWREN = 1; |
bbw | 1:0fe432e5dfc4 | 281 | while(1){ |
bbw | 1:0fe432e5dfc4 | 282 | if(wifi_uart.readable()){ |
bbw | 1:0fe432e5dfc4 | 283 | debug_uart.putc(wifi_uart.getc()); |
bbw | 1:0fe432e5dfc4 | 284 | } |
bbw | 1:0fe432e5dfc4 | 285 | if(debug_uart.readable()){ |
bbw | 1:0fe432e5dfc4 | 286 | wifi_uart.putc(debug_uart.getc()); |
bbw | 1:0fe432e5dfc4 | 287 | } |
bbw | 1:0fe432e5dfc4 | 288 | } |
bbw | 1:0fe432e5dfc4 | 289 | } |
bbw | 1:0fe432e5dfc4 | 290 | void bt_debug(){ |
bbw | 1:0fe432e5dfc4 | 291 | bt_uart.baud(9600); |
bbw | 1:0fe432e5dfc4 | 292 | debug_uart.baud(9600); |
bbw | 1:0fe432e5dfc4 | 293 | while(1){ |
bbw | 1:0fe432e5dfc4 | 294 | if(bt_uart.readable()){ |
bbw | 1:0fe432e5dfc4 | 295 | debug_uart.putc(bt_uart.getc()); |
bbw | 1:0fe432e5dfc4 | 296 | } |
bbw | 1:0fe432e5dfc4 | 297 | if(debug_uart.readable()){ |
bbw | 1:0fe432e5dfc4 | 298 | bt_uart.putc(debug_uart.getc()); |
bbw | 1:0fe432e5dfc4 | 299 | } |
bbw | 1:0fe432e5dfc4 | 300 | } |
bbw | 1:0fe432e5dfc4 | 301 | } |
bbw | 1:0fe432e5dfc4 | 302 | void lcd_debug(){ |
bbw | 1:0fe432e5dfc4 | 303 | char i = 0; |
bbw | 1:0fe432e5dfc4 | 304 | unsigned char str[] = "bob's test"; |
bbw | 1:0fe432e5dfc4 | 305 | unsigned char str2[] = "hello world"; |
bbw | 1:0fe432e5dfc4 | 306 | ST7789V_Init(); |
bbw | 1:0fe432e5dfc4 | 307 | BlockWrite(0,COL-1,0,ROW-1); |
bbw | 1:0fe432e5dfc4 | 308 | LCD_block_test(); |
bbw | 1:0fe432e5dfc4 | 309 | //DispColor(GREEN); |
bbw | 1:0fe432e5dfc4 | 310 | DispStr(str, 40, 80, BLUE, GREEN); |
bbw | 1:0fe432e5dfc4 | 311 | DispStr(str2, 40, 120, BLUE, GREEN); |
bbw | 1:0fe432e5dfc4 | 312 | //DispOneChar(0x32,60,60,BLUE,GREEN); |
bbw | 1:0fe432e5dfc4 | 313 | while(1){ |
bbw | 1:0fe432e5dfc4 | 314 | ; |
bbw | 1:0fe432e5dfc4 | 315 | } |
bbw | 1:0fe432e5dfc4 | 316 | } |
bbw | 1:0fe432e5dfc4 | 317 | |
bbw | 1:0fe432e5dfc4 | 318 | void sht20_debug(){ |
bbw | 1:0fe432e5dfc4 | 319 | while(1) { |
bbw | 1:0fe432e5dfc4 | 320 | int temperature = sht.readTemp(); |
bbw | 1:0fe432e5dfc4 | 321 | debug_uart.printf("Temperature is: %d \t", temperature); |
bbw | 1:0fe432e5dfc4 | 322 | int humidity= sht.readHumidity(); |
bbw | 1:0fe432e5dfc4 | 323 | debug_uart.printf("Humidity: %d \r\n",humidity); |
bbw | 1:0fe432e5dfc4 | 324 | wait(2); |
bbw | 1:0fe432e5dfc4 | 325 | } |
bbw | 1:0fe432e5dfc4 | 326 | } |
bbw | 1:0fe432e5dfc4 | 327 | |
bbw | 1:0fe432e5dfc4 | 328 | void eeprom_debug(){ |
bbw | 1:0fe432e5dfc4 | 329 | char ucdata_write[1]; |
bbw | 1:0fe432e5dfc4 | 330 | if (!i2c.write((MCP24AA02_ADDR|WRITE), ucdata_write, 1, 0)){ |
bbw | 1:0fe432e5dfc4 | 331 | //readID(MCP24AA02_MID); |
bbw | 1:0fe432e5dfc4 | 332 | //readID(MCP24AA02_DID); |
bbw | 1:0fe432e5dfc4 | 333 | //Uncomment the following 6 lines of code to write Data into the EEPROM |
bbw | 1:0fe432e5dfc4 | 334 | /* |
bbw | 1:0fe432e5dfc4 | 335 | writeEE(0x00,0x4D); // ASCII M |
bbw | 1:0fe432e5dfc4 | 336 | writeEE(0x01,0x61); // ASCII a |
bbw | 1:0fe432e5dfc4 | 337 | writeEE(0x02,0x72); // ASCII r |
bbw | 1:0fe432e5dfc4 | 338 | writeEE(0x03,0x74); // ASCII t |
bbw | 1:0fe432e5dfc4 | 339 | writeEE(0x04,0x69); // ASCII i |
bbw | 1:0fe432e5dfc4 | 340 | writeEE(0x05,0x6E); // ASCII n |
bbw | 1:0fe432e5dfc4 | 341 | debug_uart.printf("\n\r"); |
bbw | 1:0fe432e5dfc4 | 342 | */ |
bbw | 1:0fe432e5dfc4 | 343 | //Uncomment the following line to Erase the EEPROM |
bbw | 1:0fe432e5dfc4 | 344 | // eraseEE(); |
bbw | 1:0fe432e5dfc4 | 345 | #if 1 |
bbw | 1:0fe432e5dfc4 | 346 | for (int i=2;i<=0x7;i++){readEE(i);} |
bbw | 1:0fe432e5dfc4 | 347 | debug_uart.printf("\r\n"); |
bbw | 1:0fe432e5dfc4 | 348 | #endif |
bbw | 1:0fe432e5dfc4 | 349 | }else{ |
bbw | 1:0fe432e5dfc4 | 350 | debug_uart.printf("\n\rCannot get an ACK from the Device check connections!\n\r"); |
bbw | 1:0fe432e5dfc4 | 351 | } |
bbw | 1:0fe432e5dfc4 | 352 | } |
bbw | 1:0fe432e5dfc4 | 353 | |
bbw | 1:0fe432e5dfc4 | 354 | #endif |
bbw | 1:0fe432e5dfc4 | 355 | |
bbw | 1:0fe432e5dfc4 | 356 | |
bbw | 1:0fe432e5dfc4 | 357 |