TBT電装 メインプログラム 2017/12/8

Dependencies:   HMC5883L SDFileSystem TextOLED mbed

Committer:
Joeatsumi
Date:
Fri Dec 08 10:27:22 2017 +0000
Revision:
0:a9bde4f79982
2017/12/8; TBT???????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joeatsumi 0:a9bde4f79982 1 //H29/1208
Joeatsumi 0:a9bde4f79982 2
Joeatsumi 0:a9bde4f79982 3 #include "mbed.h"
Joeatsumi 0:a9bde4f79982 4 #include "TextOLED.h"
Joeatsumi 0:a9bde4f79982 5 #include "SDFileSystem.h"
Joeatsumi 0:a9bde4f79982 6 #include "stdio.h"
Joeatsumi 0:a9bde4f79982 7
Joeatsumi 0:a9bde4f79982 8
Joeatsumi 0:a9bde4f79982 9 #define ON 1
Joeatsumi 0:a9bde4f79982 10 #define OFF 0
Joeatsumi 0:a9bde4f79982 11
Joeatsumi 0:a9bde4f79982 12 AnalogIn alt(p20); //高度計読み取り
Joeatsumi 0:a9bde4f79982 13 InterruptIn speedcount(p17); //機速用のフォトインタラプタ読み取り
Joeatsumi 0:a9bde4f79982 14 InterruptIn rpmcount(p18); //回転数用のフォトインタラプタ読み取り
Joeatsumi 0:a9bde4f79982 15 InterruptIn Log_Switch(p26);//ログスイッチ読み取り
Joeatsumi 0:a9bde4f79982 16
Joeatsumi 0:a9bde4f79982 17
Joeatsumi 0:a9bde4f79982 18 Serial pc(USBTX, USBRX);
Joeatsumi 0:a9bde4f79982 19 Serial control_com(p28, p27);//制御基板との通信用
Joeatsumi 0:a9bde4f79982 20 Serial android_com(p13, p14); //Androidとの通信用txrx
Joeatsumi 0:a9bde4f79982 21
Joeatsumi 0:a9bde4f79982 22 TextOLED pilot_oled(p29, p30,p22, p23, p24,p25); // RS, E, DB4, DB5, DB6, DB7 有機EL
Joeatsumi 0:a9bde4f79982 23 SDFileSystem sd(p5, p6, p7, p8, "sd");//SDpinの番号 3,7,5,2 //1pin--Vout,4pin--Vout,6pin--GND,8pin--Vout
Joeatsumi 0:a9bde4f79982 24
Joeatsumi 0:a9bde4f79982 25
Joeatsumi 0:a9bde4f79982 26 DigitalOut led1(LED1);
Joeatsumi 0:a9bde4f79982 27 DigitalOut led2(LED2);
Joeatsumi 0:a9bde4f79982 28 DigitalOut led3(LED3);
Joeatsumi 0:a9bde4f79982 29 DigitalOut led4(LED4);
Joeatsumi 0:a9bde4f79982 30 //DigitalOut soundsystem(p21);//音システム用
Joeatsumi 0:a9bde4f79982 31
Joeatsumi 0:a9bde4f79982 32 //タイマー割り込み宣言
Joeatsumi 0:a9bde4f79982 33 Ticker ticker;//updateのタイマー割り込み
Joeatsumi 0:a9bde4f79982 34 Timer t,t1;
Joeatsumi 0:a9bde4f79982 35
Joeatsumi 0:a9bde4f79982 36 int speedcounter = 0, rpmcounter = 0, min = 0, sec = 0, i;
Joeatsumi 0:a9bde4f79982 37 int oldspeed = 0, oldrpm = 0;
Joeatsumi 0:a9bde4f79982 38 int log_count = 0;
Joeatsumi 0:a9bde4f79982 39 int SD_count = 0;
Joeatsumi 0:a9bde4f79982 40 int up2=0,up1=0,down1=0,down2=0,E_neut=0;
Joeatsumi 0:a9bde4f79982 41 int left1=0,left2=0,right1=0,right2=0,R_neut=0;
Joeatsumi 0:a9bde4f79982 42 int send_compass=0;
Joeatsumi 0:a9bde4f79982 43
Joeatsumi 0:a9bde4f79982 44
Joeatsumi 0:a9bde4f79982 45 double time_s = 0,time_ms=0,time1=0,time2=0, speed = 0, rpm = 0, height = 0,compass = 0;
Joeatsumi 0:a9bde4f79982 46
Joeatsumi 0:a9bde4f79982 47 char ele;
Joeatsumi 0:a9bde4f79982 48 char rud;
Joeatsumi 0:a9bde4f79982 49 char e_trim='e',r_trim='r';
Joeatsumi 0:a9bde4f79982 50 char compass_array[4] = "000";
Joeatsumi 0:a9bde4f79982 51 char data;
Joeatsumi 0:a9bde4f79982 52 char send_buff1[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Joeatsumi 0:a9bde4f79982 53
Joeatsumi 0:a9bde4f79982 54
Joeatsumi 0:a9bde4f79982 55 unsigned char Log_flag = OFF;
Joeatsumi 0:a9bde4f79982 56 unsigned char SD_flag = OFF;
Joeatsumi 0:a9bde4f79982 57
Joeatsumi 0:a9bde4f79982 58 //プロトタイプ宣言
Joeatsumi 0:a9bde4f79982 59
Joeatsumi 0:a9bde4f79982 60 void SD_log();
Joeatsumi 0:a9bde4f79982 61 void OLEDdisplay_print();
Joeatsumi 0:a9bde4f79982 62 void spd_f();
Joeatsumi 0:a9bde4f79982 63 void rpm_f();
Joeatsumi 0:a9bde4f79982 64 void spd_c();
Joeatsumi 0:a9bde4f79982 65 void rpm_c();
Joeatsumi 0:a9bde4f79982 66 void control_communication();
Joeatsumi 0:a9bde4f79982 67 void android_communication();
Joeatsumi 0:a9bde4f79982 68 void update();
Joeatsumi 0:a9bde4f79982 69 //================//
Joeatsumi 0:a9bde4f79982 70 void xbee();
Joeatsumi 0:a9bde4f79982 71 //================//
Joeatsumi 0:a9bde4f79982 72 void altitude_f();
Joeatsumi 0:a9bde4f79982 73 void compass_f();
Joeatsumi 0:a9bde4f79982 74 void Log_Switch_f();
Joeatsumi 0:a9bde4f79982 75 void CGRAM_1();
Joeatsumi 0:a9bde4f79982 76 void CGRAM_2();
Joeatsumi 0:a9bde4f79982 77 void CGRAM_3();
Joeatsumi 0:a9bde4f79982 78 void CGRAM_4();
Joeatsumi 0:a9bde4f79982 79 void CGRAM_5();
Joeatsumi 0:a9bde4f79982 80
Joeatsumi 0:a9bde4f79982 81 FILE* fp;
Joeatsumi 0:a9bde4f79982 82
Joeatsumi 0:a9bde4f79982 83
Joeatsumi 0:a9bde4f79982 84 int main() {
Joeatsumi 0:a9bde4f79982 85
Joeatsumi 0:a9bde4f79982 86 pilot_oled.cls();
Joeatsumi 0:a9bde4f79982 87
Joeatsumi 0:a9bde4f79982 88 // init();
Joeatsumi 0:a9bde4f79982 89
Joeatsumi 0:a9bde4f79982 90 pc.printf("furst TBT!!\n");
Joeatsumi 0:a9bde4f79982 91
Joeatsumi 0:a9bde4f79982 92 led1=1;
Joeatsumi 0:a9bde4f79982 93 led2=1;
Joeatsumi 0:a9bde4f79982 94 led3=1;
Joeatsumi 0:a9bde4f79982 95 led4=1;
Joeatsumi 0:a9bde4f79982 96
Joeatsumi 0:a9bde4f79982 97 // myled(1,1,0,0);
Joeatsumi 0:a9bde4f79982 98 wait(2);
Joeatsumi 0:a9bde4f79982 99
Joeatsumi 0:a9bde4f79982 100
Joeatsumi 0:a9bde4f79982 101 fp = fopen("/sd/log_data.txt", "w");
Joeatsumi 0:a9bde4f79982 102 if(fp == NULL) {
Joeatsumi 0:a9bde4f79982 103 pilot_oled.locate(0, 0);
Joeatsumi 0:a9bde4f79982 104 pilot_oled.printf("There is no sd.");
Joeatsumi 0:a9bde4f79982 105 error("Could not open file for write\n");
Joeatsumi 0:a9bde4f79982 106 }
Joeatsumi 0:a9bde4f79982 107
Joeatsumi 0:a9bde4f79982 108 pc.printf("Start writing!\n");
Joeatsumi 0:a9bde4f79982 109
Joeatsumi 0:a9bde4f79982 110 fclose(fp);
Joeatsumi 0:a9bde4f79982 111 fp = fopen("/sd/log_data.txt", "w");
Joeatsumi 0:a9bde4f79982 112 fprintf(fp, "SD_count, min, sec, rpm, speed, height,compass,up2,up1,E_neut,down1,down2,left2,left1,R_neut,right1,right2\r\n");
Joeatsumi 0:a9bde4f79982 113 fclose(fp);
Joeatsumi 0:a9bde4f79982 114 fp = fopen("/sd/log_data.txt", "w");
Joeatsumi 0:a9bde4f79982 115
Joeatsumi 0:a9bde4f79982 116 android_com.baud(115200);
Joeatsumi 0:a9bde4f79982 117 android_com.format(8,Serial::None,1);
Joeatsumi 0:a9bde4f79982 118
Joeatsumi 0:a9bde4f79982 119 control_com.attach(control_communication, Serial::RxIrq);
Joeatsumi 0:a9bde4f79982 120 control_com.baud(115200);
Joeatsumi 0:a9bde4f79982 121
Joeatsumi 0:a9bde4f79982 122 t.start();
Joeatsumi 0:a9bde4f79982 123 t1.start();
Joeatsumi 0:a9bde4f79982 124
Joeatsumi 0:a9bde4f79982 125 Log_Switch.rise(&Log_Switch_f);
Joeatsumi 0:a9bde4f79982 126 speedcount.rise(&spd_c);
Joeatsumi 0:a9bde4f79982 127 rpmcount.rise(&rpm_c);
Joeatsumi 0:a9bde4f79982 128 ticker.attach(update,1);//1s更新
Joeatsumi 0:a9bde4f79982 129
Joeatsumi 0:a9bde4f79982 130 while (1) {
Joeatsumi 0:a9bde4f79982 131
Joeatsumi 0:a9bde4f79982 132
Joeatsumi 0:a9bde4f79982 133 led3=!led3;
Joeatsumi 0:a9bde4f79982 134 if(min >=30) { //30分経過時、タイマーリセット
Joeatsumi 0:a9bde4f79982 135 t.reset();
Joeatsumi 0:a9bde4f79982 136 }
Joeatsumi 0:a9bde4f79982 137 if(Log_flag == OFF) { //log取るごとにリセット
Joeatsumi 0:a9bde4f79982 138 t.stop();
Joeatsumi 0:a9bde4f79982 139 t.reset();
Joeatsumi 0:a9bde4f79982 140 } else {
Joeatsumi 0:a9bde4f79982 141 t.start();
Joeatsumi 0:a9bde4f79982 142 }
Joeatsumi 0:a9bde4f79982 143 time_s = t.read();//時間取得
Joeatsumi 0:a9bde4f79982 144 min = (int)(time_s) / 60;
Joeatsumi 0:a9bde4f79982 145 sec = (int)time_s % 60;
Joeatsumi 0:a9bde4f79982 146 wait(0.2);
Joeatsumi 0:a9bde4f79982 147 }
Joeatsumi 0:a9bde4f79982 148 }
Joeatsumi 0:a9bde4f79982 149
Joeatsumi 0:a9bde4f79982 150
Joeatsumi 0:a9bde4f79982 151 void xbee(){
Joeatsumi 0:a9bde4f79982 152 //================================//
Joeatsumi 0:a9bde4f79982 153 struct{
Joeatsumi 0:a9bde4f79982 154 char highbyte;
Joeatsumi 0:a9bde4f79982 155 char lowbyte;
Joeatsumi 0:a9bde4f79982 156 short intdat;
Joeatsumi 0:a9bde4f79982 157 }datax;
Joeatsumi 0:a9bde4f79982 158 struct{
Joeatsumi 0:a9bde4f79982 159 char highbyte;
Joeatsumi 0:a9bde4f79982 160 char lowbyte;
Joeatsumi 0:a9bde4f79982 161 short intdat;
Joeatsumi 0:a9bde4f79982 162 }datax2;
Joeatsumi 0:a9bde4f79982 163 struct{
Joeatsumi 0:a9bde4f79982 164 char highbyte;
Joeatsumi 0:a9bde4f79982 165 char lowbyte;
Joeatsumi 0:a9bde4f79982 166 short intdat;
Joeatsumi 0:a9bde4f79982 167 }datax3;
Joeatsumi 0:a9bde4f79982 168
Joeatsumi 0:a9bde4f79982 169 //===========================//
Joeatsumi 0:a9bde4f79982 170
Joeatsumi 0:a9bde4f79982 171
Joeatsumi 0:a9bde4f79982 172 datax.intdat = rpm;
Joeatsumi 0:a9bde4f79982 173 datax2.intdat = height*10.0;
Joeatsumi 0:a9bde4f79982 174 datax3.intdat = speed*10.0;
Joeatsumi 0:a9bde4f79982 175
Joeatsumi 0:a9bde4f79982 176 datax.highbyte=datax.intdat/256;
Joeatsumi 0:a9bde4f79982 177 datax.lowbyte=datax.intdat%256;
Joeatsumi 0:a9bde4f79982 178
Joeatsumi 0:a9bde4f79982 179 datax2.highbyte=datax2.intdat/256;
Joeatsumi 0:a9bde4f79982 180 datax2.lowbyte=datax2.intdat%256;
Joeatsumi 0:a9bde4f79982 181
Joeatsumi 0:a9bde4f79982 182 datax3.highbyte=datax3.intdat/256;
Joeatsumi 0:a9bde4f79982 183 datax3.lowbyte=datax3.intdat%256;
Joeatsumi 0:a9bde4f79982 184
Joeatsumi 0:a9bde4f79982 185 control_com.putc('H');//ヘッダーを送信
Joeatsumi 0:a9bde4f79982 186 control_com.putc(datax.highbyte);
Joeatsumi 0:a9bde4f79982 187 control_com.putc(datax.lowbyte);
Joeatsumi 0:a9bde4f79982 188
Joeatsumi 0:a9bde4f79982 189 control_com.putc(datax2.highbyte);
Joeatsumi 0:a9bde4f79982 190 control_com.putc(datax2.lowbyte);
Joeatsumi 0:a9bde4f79982 191
Joeatsumi 0:a9bde4f79982 192
Joeatsumi 0:a9bde4f79982 193 control_com.putc(datax3.highbyte);
Joeatsumi 0:a9bde4f79982 194 control_com.putc(datax3.lowbyte);
Joeatsumi 0:a9bde4f79982 195
Joeatsumi 0:a9bde4f79982 196 }
Joeatsumi 0:a9bde4f79982 197
Joeatsumi 0:a9bde4f79982 198
Joeatsumi 0:a9bde4f79982 199 void SD_log() //SDログ関数
Joeatsumi 0:a9bde4f79982 200 {
Joeatsumi 0:a9bde4f79982 201 // __disable_irq();
Joeatsumi 0:a9bde4f79982 202 led2 = 1;
Joeatsumi 0:a9bde4f79982 203 if (Log_flag == ON) {
Joeatsumi 0:a9bde4f79982 204 FILE *fp;
Joeatsumi 0:a9bde4f79982 205 fp = fopen("/sd/log_data.txt", "a");
Joeatsumi 0:a9bde4f79982 206 if (NULL == fp) {
Joeatsumi 0:a9bde4f79982 207 pilot_oled.locate(0, 0);
Joeatsumi 0:a9bde4f79982 208 pilot_oled.printf("There is no SD!!");
Joeatsumi 0:a9bde4f79982 209 pc.printf("There is no SD!!\n");
Joeatsumi 0:a9bde4f79982 210
Joeatsumi 0:a9bde4f79982 211 pilot_oled.locate(0, 0);
Joeatsumi 0:a9bde4f79982 212 pilot_oled.printf("There is no sd.");
Joeatsumi 0:a9bde4f79982 213
Joeatsumi 0:a9bde4f79982 214 error("Could not open file for write \n");
Joeatsumi 0:a9bde4f79982 215 } else {
Joeatsumi 0:a9bde4f79982 216
Joeatsumi 0:a9bde4f79982 217 pc.printf("Now logging!!\r\n");
Joeatsumi 0:a9bde4f79982 218 fprintf(fp, "NO:%d,%02d:%02d,%1.0f,%0.3f,%0.3f,%0.3f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", SD_count, min, sec, rpm, speed, height,compass,up2,up1,E_neut,down1,down2,left2,left1,R_neut,right1,right2);
Joeatsumi 0:a9bde4f79982 219 fclose(fp); //操舵データ
Joeatsumi 0:a9bde4f79982 220 }
Joeatsumi 0:a9bde4f79982 221 }
Joeatsumi 0:a9bde4f79982 222 led2 = 0;
Joeatsumi 0:a9bde4f79982 223 // __enable_irq();
Joeatsumi 0:a9bde4f79982 224 }
Joeatsumi 0:a9bde4f79982 225
Joeatsumi 0:a9bde4f79982 226 void Log_Switch_f()//ログスイッチ
Joeatsumi 0:a9bde4f79982 227 {
Joeatsumi 0:a9bde4f79982 228 log_count++;
Joeatsumi 0:a9bde4f79982 229 if (log_count == 1) {
Joeatsumi 0:a9bde4f79982 230 Log_flag = ON;
Joeatsumi 0:a9bde4f79982 231 SD_count++;
Joeatsumi 0:a9bde4f79982 232 } else if (log_count == 2) {
Joeatsumi 0:a9bde4f79982 233 Log_flag = OFF;
Joeatsumi 0:a9bde4f79982 234 log_count = 0;
Joeatsumi 0:a9bde4f79982 235 }
Joeatsumi 0:a9bde4f79982 236 }
Joeatsumi 0:a9bde4f79982 237
Joeatsumi 0:a9bde4f79982 238 void OLEDdisplay_print() //有機EL表示用関数
Joeatsumi 0:a9bde4f79982 239 {
Joeatsumi 0:a9bde4f79982 240 led3!=led3;
Joeatsumi 0:a9bde4f79982 241
Joeatsumi 0:a9bde4f79982 242 pilot_oled.locate(0, 1);
Joeatsumi 0:a9bde4f79982 243 pilot_oled.printf("r%3.0f s%4.1f h%4.1f", rpm,speed,height);//センサーの値
Joeatsumi 0:a9bde4f79982 244 wait_ms(0.7);
Joeatsumi 0:a9bde4f79982 245
Joeatsumi 0:a9bde4f79982 246 pilot_oled.locate(4, 0);
Joeatsumi 0:a9bde4f79982 247 pilot_oled.printf("%1d", send_compass);
Joeatsumi 0:a9bde4f79982 248 pilot_oled.locate(11, 0);
Joeatsumi 0:a9bde4f79982 249 if (Log_flag == ON) pilot_oled.printf("ON ");
Joeatsumi 0:a9bde4f79982 250 else pilot_oled.printf("OFF");
Joeatsumi 0:a9bde4f79982 251
Joeatsumi 0:a9bde4f79982 252 // pilot_oled.locate(0, 0);
Joeatsumi 0:a9bde4f79982 253 // pilot_oled.printf("count:%d",rpmcounter);//時間表示
Joeatsumi 0:a9bde4f79982 254 wait_ms(0.7);
Joeatsumi 0:a9bde4f79982 255 // __enable_irq();
Joeatsumi 0:a9bde4f79982 256 }
Joeatsumi 0:a9bde4f79982 257
Joeatsumi 0:a9bde4f79982 258 void compass_f()//高度の変換
Joeatsumi 0:a9bde4f79982 259 {
Joeatsumi 0:a9bde4f79982 260 compass=atoi(compass_array);
Joeatsumi 0:a9bde4f79982 261
Joeatsumi 0:a9bde4f79982 262 if(compass<22.5&&compass>=0||compass<360&&compass>=337.5)send_compass=1;//北
Joeatsumi 0:a9bde4f79982 263 else if(compass<67.5&&compass>=22.5)send_compass=2;//
Joeatsumi 0:a9bde4f79982 264 else if(compass<112.5&&compass>=67.5)send_compass=3;//東
Joeatsumi 0:a9bde4f79982 265 else if(compass<157.5&&compass>=112.5)send_compass=4;//
Joeatsumi 0:a9bde4f79982 266 else if(compass<202.5&&compass>=157.5)send_compass=5;//南
Joeatsumi 0:a9bde4f79982 267 else if(compass<247.5&&compass>=202.5)send_compass=6;//
Joeatsumi 0:a9bde4f79982 268 else if(compass<292.5&&compass>=247.5)send_compass=7;//西
Joeatsumi 0:a9bde4f79982 269 else if(compass<337.5&&compass>=292.5)send_compass=8;//
Joeatsumi 0:a9bde4f79982 270
Joeatsumi 0:a9bde4f79982 271
Joeatsumi 0:a9bde4f79982 272
Joeatsumi 0:a9bde4f79982 273 }
Joeatsumi 0:a9bde4f79982 274
Joeatsumi 0:a9bde4f79982 275 void altitude_f()//高度の変換
Joeatsumi 0:a9bde4f79982 276 {
Joeatsumi 0:a9bde4f79982 277 height=alt.read()*3.3*1000/1.6/100;
Joeatsumi 0:a9bde4f79982 278 }
Joeatsumi 0:a9bde4f79982 279
Joeatsumi 0:a9bde4f79982 280 void rpm_c() //回転数のフォトインタラプタ
Joeatsumi 0:a9bde4f79982 281 {
Joeatsumi 0:a9bde4f79982 282 rpmcounter++;
Joeatsumi 0:a9bde4f79982 283 }
Joeatsumi 0:a9bde4f79982 284
Joeatsumi 0:a9bde4f79982 285 void rpm_f() //回転数計測
Joeatsumi 0:a9bde4f79982 286 {
Joeatsumi 0:a9bde4f79982 287 rpm = (double)(rpmcounter * 60000/time_ms/48);
Joeatsumi 0:a9bde4f79982 288 rpmcounter = 0;
Joeatsumi 0:a9bde4f79982 289 }
Joeatsumi 0:a9bde4f79982 290
Joeatsumi 0:a9bde4f79982 291 void spd_c() //機速のフォトインタラプタ
Joeatsumi 0:a9bde4f79982 292 {
Joeatsumi 0:a9bde4f79982 293 speedcounter++;
Joeatsumi 0:a9bde4f79982 294 }
Joeatsumi 0:a9bde4f79982 295
Joeatsumi 0:a9bde4f79982 296 void spd_f()
Joeatsumi 0:a9bde4f79982 297 {
Joeatsumi 0:a9bde4f79982 298 int x = 0;
Joeatsumi 0:a9bde4f79982 299 x = (double)(speedcounter * 60000/time_ms/8);
Joeatsumi 0:a9bde4f79982 300 speed = (double)(0.0014*x + 0.9815);
Joeatsumi 0:a9bde4f79982 301 //最初の機速校正時の式は、0.0015*x + 0.6063
Joeatsumi 0:a9bde4f79982 302 if(speed<=0.9815) {
Joeatsumi 0:a9bde4f79982 303 speed = 0;
Joeatsumi 0:a9bde4f79982 304 }
Joeatsumi 0:a9bde4f79982 305 speedcounter = 0;
Joeatsumi 0:a9bde4f79982 306 }
Joeatsumi 0:a9bde4f79982 307
Joeatsumi 0:a9bde4f79982 308
Joeatsumi 0:a9bde4f79982 309 void control_communication() //操舵基板との通信用
Joeatsumi 0:a9bde4f79982 310 {
Joeatsumi 0:a9bde4f79982 311 // myled(9,9,1,9);
Joeatsumi 0:a9bde4f79982 312
Joeatsumi 0:a9bde4f79982 313 // __disable_irq();
Joeatsumi 0:a9bde4f79982 314 // t1.stop();
Joeatsumi 0:a9bde4f79982 315 for (int i = 0; i <3; i++) {
Joeatsumi 0:a9bde4f79982 316 compass_array[i] = control_com.getc();//高度の受信
Joeatsumi 0:a9bde4f79982 317 }
Joeatsumi 0:a9bde4f79982 318 ele = control_com.getc();//舵角の受信
Joeatsumi 0:a9bde4f79982 319 rud = control_com.getc();//舵角の受信
Joeatsumi 0:a9bde4f79982 320 e_trim = control_com.getc();//trimの受信
Joeatsumi 0:a9bde4f79982 321 r_trim = control_com.getc();//trimの受信
Joeatsumi 0:a9bde4f79982 322
Joeatsumi 0:a9bde4f79982 323 pilot_oled.locate(0, 0);
Joeatsumi 0:a9bde4f79982 324 pilot_oled.printf("%1c%1c", e_trim,r_trim);
Joeatsumi 0:a9bde4f79982 325 pilot_oled.locate(14, 0);
Joeatsumi 0:a9bde4f79982 326 pilot_oled.printf("%2d", SD_count);
Joeatsumi 0:a9bde4f79982 327 wait_ms(0.7);
Joeatsumi 0:a9bde4f79982 328 ///////////エレベータログデータ条件分岐////////////////////////////
Joeatsumi 0:a9bde4f79982 329 switch(ele) {
Joeatsumi 0:a9bde4f79982 330 case 'U':
Joeatsumi 0:a9bde4f79982 331 pilot_oled.locate(6, 0);
Joeatsumi 0:a9bde4f79982 332 // pilot_oled.putc(0x02);//
Joeatsumi 0:a9bde4f79982 333 pilot_oled.printf("U");//
Joeatsumi 0:a9bde4f79982 334 up2 = 5 ;
Joeatsumi 0:a9bde4f79982 335 break;
Joeatsumi 0:a9bde4f79982 336 case 'u':
Joeatsumi 0:a9bde4f79982 337 pilot_oled.locate(6, 0);
Joeatsumi 0:a9bde4f79982 338 // pilot_oled.putc(0x5E);//^
Joeatsumi 0:a9bde4f79982 339 pilot_oled.printf("u");//
Joeatsumi 0:a9bde4f79982 340 up1 = 4 ;
Joeatsumi 0:a9bde4f79982 341 break;
Joeatsumi 0:a9bde4f79982 342 case 'n':
Joeatsumi 0:a9bde4f79982 343 pilot_oled.locate(6, 0);
Joeatsumi 0:a9bde4f79982 344 pilot_oled.putc(0x2D);//-
Joeatsumi 0:a9bde4f79982 345 E_neut = 3 ;
Joeatsumi 0:a9bde4f79982 346 break;
Joeatsumi 0:a9bde4f79982 347 case 'd':
Joeatsumi 0:a9bde4f79982 348 pilot_oled.locate(6, 0);
Joeatsumi 0:a9bde4f79982 349 // pilot_oled.putc(0x00);//vみたいな文字
Joeatsumi 0:a9bde4f79982 350 pilot_oled.printf("d");//
Joeatsumi 0:a9bde4f79982 351 down1 = 2 ;
Joeatsumi 0:a9bde4f79982 352 break;
Joeatsumi 0:a9bde4f79982 353 case 'D':
Joeatsumi 0:a9bde4f79982 354 pilot_oled.locate(6, 0);
Joeatsumi 0:a9bde4f79982 355 // pilot_oled.putc(0x01);
Joeatsumi 0:a9bde4f79982 356 pilot_oled.printf("D");//
Joeatsumi 0:a9bde4f79982 357 down2 = 1;
Joeatsumi 0:a9bde4f79982 358 break;
Joeatsumi 0:a9bde4f79982 359 default:
Joeatsumi 0:a9bde4f79982 360 break;
Joeatsumi 0:a9bde4f79982 361 }
Joeatsumi 0:a9bde4f79982 362 /////////ラダーログデータ条件分岐/////////////////////////////////////
Joeatsumi 0:a9bde4f79982 363 switch(rud) {
Joeatsumi 0:a9bde4f79982 364 case 'L':
Joeatsumi 0:a9bde4f79982 365 pilot_oled.locate(8, 0);
Joeatsumi 0:a9bde4f79982 366 // pilot_oled.putc(0x03);
Joeatsumi 0:a9bde4f79982 367 pilot_oled.printf("L");//
Joeatsumi 0:a9bde4f79982 368 left2 =1;
Joeatsumi 0:a9bde4f79982 369 break;
Joeatsumi 0:a9bde4f79982 370 case 'l':
Joeatsumi 0:a9bde4f79982 371 pilot_oled.locate(8, 0);
Joeatsumi 0:a9bde4f79982 372 pilot_oled.putc(0x3C);//<
Joeatsumi 0:a9bde4f79982 373 left1 =2;
Joeatsumi 0:a9bde4f79982 374 break;
Joeatsumi 0:a9bde4f79982 375 case 'N':
Joeatsumi 0:a9bde4f79982 376 pilot_oled.locate(8, 0);
Joeatsumi 0:a9bde4f79982 377 pilot_oled.putc(0x7C);//|
Joeatsumi 0:a9bde4f79982 378 R_neut=3;
Joeatsumi 0:a9bde4f79982 379 break;
Joeatsumi 0:a9bde4f79982 380 case 'r':
Joeatsumi 0:a9bde4f79982 381 pilot_oled.locate(8, 0);
Joeatsumi 0:a9bde4f79982 382 pilot_oled.putc(0x3E);//>
Joeatsumi 0:a9bde4f79982 383 right1=4;
Joeatsumi 0:a9bde4f79982 384 break;
Joeatsumi 0:a9bde4f79982 385 case 'R':
Joeatsumi 0:a9bde4f79982 386 pilot_oled.locate(8, 0);
Joeatsumi 0:a9bde4f79982 387 // pilot_oled.putc(0x04);
Joeatsumi 0:a9bde4f79982 388 pilot_oled.printf("R");//
Joeatsumi 0:a9bde4f79982 389 right2=5;
Joeatsumi 0:a9bde4f79982 390 break;
Joeatsumi 0:a9bde4f79982 391 default:
Joeatsumi 0:a9bde4f79982 392 break;
Joeatsumi 0:a9bde4f79982 393 }
Joeatsumi 0:a9bde4f79982 394 // t1.start();
Joeatsumi 0:a9bde4f79982 395 //__enable_irq();
Joeatsumi 0:a9bde4f79982 396 }
Joeatsumi 0:a9bde4f79982 397
Joeatsumi 0:a9bde4f79982 398 void android_communication()
Joeatsumi 0:a9bde4f79982 399 {
Joeatsumi 0:a9bde4f79982 400 // myled(9,9,9,1);
Joeatsumi 0:a9bde4f79982 401
Joeatsumi 0:a9bde4f79982 402 int srpm,sspeed,sheight;
Joeatsumi 0:a9bde4f79982 403 srpm=(int)rpm;
Joeatsumi 0:a9bde4f79982 404 sspeed=(int)speed*10;
Joeatsumi 0:a9bde4f79982 405 sheight=(int)height*10;
Joeatsumi 0:a9bde4f79982 406 if(srpm<100)srpm+=900;
Joeatsumi 0:a9bde4f79982 407 if(sspeed<100)sspeed+=900;
Joeatsumi 0:a9bde4f79982 408 if(sheight<100)sheight+=900;
Joeatsumi 0:a9bde4f79982 409
Joeatsumi 0:a9bde4f79982 410 snprintf(send_buff1,12,"s%3d%3d%3d%d",srpm,sheight,sspeed,send_compass);
Joeatsumi 0:a9bde4f79982 411 for(i=0;i<12;i++){
Joeatsumi 0:a9bde4f79982 412 // pc.putc(send_buff1[i]);
Joeatsumi 0:a9bde4f79982 413 android_com.putc(send_buff1[i]);
Joeatsumi 0:a9bde4f79982 414 }
Joeatsumi 0:a9bde4f79982 415 }
Joeatsumi 0:a9bde4f79982 416
Joeatsumi 0:a9bde4f79982 417 void update() //データ更新。最優先関数、割り込み禁止絶対入れろ。
Joeatsumi 0:a9bde4f79982 418 {
Joeatsumi 0:a9bde4f79982 419 // myled(1,0,0,0);
Joeatsumi 0:a9bde4f79982 420 __disable_irq();
Joeatsumi 0:a9bde4f79982 421 //time2 = t1.read_ms();
Joeatsumi 0:a9bde4f79982 422 time_ms = t1.read_ms();//周期時間読み取り
Joeatsumi 0:a9bde4f79982 423 t1.stop();
Joeatsumi 0:a9bde4f79982 424 t1.reset();
Joeatsumi 0:a9bde4f79982 425 led4 =! led4;
Joeatsumi 0:a9bde4f79982 426 //time_ms =time2-time1;
Joeatsumi 0:a9bde4f79982 427 rpm_f();
Joeatsumi 0:a9bde4f79982 428 spd_f();
Joeatsumi 0:a9bde4f79982 429 altitude_f();
Joeatsumi 0:a9bde4f79982 430 compass_f();
Joeatsumi 0:a9bde4f79982 431 SD_log();
Joeatsumi 0:a9bde4f79982 432 OLEDdisplay_print();
Joeatsumi 0:a9bde4f79982 433 android_communication();
Joeatsumi 0:a9bde4f79982 434 //=============================//
Joeatsumi 0:a9bde4f79982 435 xbee();
Joeatsumi 0:a9bde4f79982 436 //==============================//
Joeatsumi 0:a9bde4f79982 437 pc.printf("NO:%d,%02d:%02d,R:%1.0f,S:%0.3f,H:%0.3f,compass:%3.0f,%c%c,e:%c,r:%c,et:%c,rt:%c,%.3f\r\n", SD_count, min, sec, rpm, speed, height,compass,compass_array[0],compass_array[1], ele, rud,e_trim,r_trim,time_ms);
Joeatsumi 0:a9bde4f79982 438 // pc.printf("TBT\n");
Joeatsumi 0:a9bde4f79982 439 up2 = 0;
Joeatsumi 0:a9bde4f79982 440 up1 = 0;
Joeatsumi 0:a9bde4f79982 441 E_neut = 0;
Joeatsumi 0:a9bde4f79982 442 down1=0;
Joeatsumi 0:a9bde4f79982 443 down2=0;
Joeatsumi 0:a9bde4f79982 444 left1= 0;
Joeatsumi 0:a9bde4f79982 445 left2 =0;
Joeatsumi 0:a9bde4f79982 446 R_neut = 0;
Joeatsumi 0:a9bde4f79982 447 right1=0;
Joeatsumi 0:a9bde4f79982 448 right2=0;
Joeatsumi 0:a9bde4f79982 449 t1.start();
Joeatsumi 0:a9bde4f79982 450 // time1 = t1.read_ms();
Joeatsumi 0:a9bde4f79982 451 __enable_irq();
Joeatsumi 0:a9bde4f79982 452 }