MonitoringSys_toukarui

Dependencies:   mbed SB1602E MSCFILESytem FatFileSystemCpp TextLCD

Committer:
MPPT51
Date:
Wed Apr 08 01:18:43 2020 +0000
Revision:
0:a6417f504b9d
MonitoringSys_includingToukarui

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MPPT51 0:a6417f504b9d 1 /* Monitoring System Program
MPPT51 0:a6417f504b9d 2 * @Kikkawa
MPPT51 0:a6417f504b9d 3 * @ver.1 2020/04/05, ver.2 2020/04/05
MPPT51 0:a6417f504b9d 4 *
MPPT51 0:a6417f504b9d 5 * LCD(20*4), LCD(デカ文字,SB1602E), CAN, USBmemory, indicator, hazard, horn
MPPT51 0:a6417f504b9d 6 */
MPPT51 0:a6417f504b9d 7 #include "mbed.h"
MPPT51 0:a6417f504b9d 8 #include "TextLCD.h" //LCD(4*20)ライブラリ
MPPT51 0:a6417f504b9d 9 #include "SB1602E.h" //LCD(デカ文字)ライブラリ
MPPT51 0:a6417f504b9d 10 #include "MSCFileSystem.h" //USBメモリのライブラリ
MPPT51 0:a6417f504b9d 11
MPPT51 0:a6417f504b9d 12 DigitalOut myled(LED1);
MPPT51 0:a6417f504b9d 13 DigitalOut myled1(LED2);
MPPT51 0:a6417f504b9d 14 DigitalOut myled2(LED3);
MPPT51 0:a6417f504b9d 15 DigitalOut myled3(LED4);
MPPT51 0:a6417f504b9d 16
MPPT51 0:a6417f504b9d 17 /*インパネ周りの設定*/
MPPT51 0:a6417f504b9d 18 Ticker flipper0;
MPPT51 0:a6417f504b9d 19 DigitalOut overCharge(p22); //過充電LED点灯用
MPPT51 0:a6417f504b9d 20 DigitalOut overDisCharge(p23); //過放電LED点灯用
MPPT51 0:a6417f504b9d 21 DigitalOut winkR_Out(p5); //ウィンカー右_出力
MPPT51 0:a6417f504b9d 22 DigitalOut winkL_Out(p6); //ウィンカー左_出力
MPPT51 0:a6417f504b9d 23 DigitalOut horn_Out(p8); //ホーン_出力
MPPT51 0:a6417f504b9d 24 DigitalOut brake_Out(p7); //ブレーキ_出力
MPPT51 0:a6417f504b9d 25 InterruptIn P_SW(p24); //Pボタン_入力(テレメトリ送信とかUSBメモリ保存ファイル切り替えとかに使用予定)
MPPT51 0:a6417f504b9d 26 InterruptIn winkR_SW(p21); //ウィンカー右スイッチ入力 kiban5
MPPT51 0:a6417f504b9d 27 InterruptIn winkL_SW(p10); //ウィンカー左スイッチ入力
MPPT51 0:a6417f504b9d 28 InterruptIn horn_SW(p12); //ホーンスイッチ入力
MPPT51 0:a6417f504b9d 29 InterruptIn hazard_SW(p11); //ハザードスイッチ入力
MPPT51 0:a6417f504b9d 30 InterruptIn brake_SW(p9); //ブレーキ入力
MPPT51 0:a6417f504b9d 31 bool P_SW_pre = 0;
MPPT51 0:a6417f504b9d 32 bool winkR_SW_pre = 0;
MPPT51 0:a6417f504b9d 33 bool winkL_SW_pre = 0;
MPPT51 0:a6417f504b9d 34 bool hazard_SW_pre = 0;
MPPT51 0:a6417f504b9d 35 void toukarui_init(void);
MPPT51 0:a6417f504b9d 36
MPPT51 0:a6417f504b9d 37 /*LCD(20*4)の設定 (lcd1)*/
MPPT51 0:a6417f504b9d 38 TextLCD lcd1(p15, p16, p17, p18, p19, p20); // RS, E, DB4, DB5, DB6, DB7
MPPT51 0:a6417f504b9d 39 void lcd1_printf(void); //LCDに文字表示する関数
MPPT51 0:a6417f504b9d 40 int lcd1_cnt = 0;
MPPT51 0:a6417f504b9d 41
MPPT51 0:a6417f504b9d 42 /*LCD(デカ文字)の設定 (lcd2)*/
MPPT51 0:a6417f504b9d 43 I2C i2c( p28, p27 );
MPPT51 0:a6417f504b9d 44 SB1602E lcd2( i2c ); // SDA, SCL
MPPT51 0:a6417f504b9d 45 int lcd2_cnt = 0;
MPPT51 0:a6417f504b9d 46
MPPT51 0:a6417f504b9d 47 /*USBメモリの設定*/
MPPT51 0:a6417f504b9d 48 MSCFileSystem msc("usb"); // Mount flash drive under the name "msc"
MPPT51 0:a6417f504b9d 49 void MSC_init(void); //USBの初期設定関数
MPPT51 0:a6417f504b9d 50 void write_MSC(void); //USBへデータを書き込む関数
MPPT51 0:a6417f504b9d 51 FILE *fp;
MPPT51 0:a6417f504b9d 52
MPPT51 0:a6417f504b9d 53
MPPT51 0:a6417f504b9d 54 void winker_flip() {
MPPT51 0:a6417f504b9d 55 if( hazard_SW_pre ) {
MPPT51 0:a6417f504b9d 56 myled1 = !myled1;
MPPT51 0:a6417f504b9d 57 myled2 = !myled2;
MPPT51 0:a6417f504b9d 58 }
MPPT51 0:a6417f504b9d 59 else if( winkL_SW_pre ) {
MPPT51 0:a6417f504b9d 60 myled1 = !myled1;
MPPT51 0:a6417f504b9d 61 }
MPPT51 0:a6417f504b9d 62 else if( winkR_SW_pre ){
MPPT51 0:a6417f504b9d 63 myled2 = !myled2;
MPPT51 0:a6417f504b9d 64 }
MPPT51 0:a6417f504b9d 65 else {
MPPT51 0:a6417f504b9d 66 myled1 = 0;
MPPT51 0:a6417f504b9d 67 myled2 = 0;
MPPT51 0:a6417f504b9d 68 }
MPPT51 0:a6417f504b9d 69 }
MPPT51 0:a6417f504b9d 70
MPPT51 0:a6417f504b9d 71 void P_SW_handler() {
MPPT51 0:a6417f504b9d 72 P_SW_pre = !P_SW_pre;
MPPT51 0:a6417f504b9d 73 }
MPPT51 0:a6417f504b9d 74
MPPT51 0:a6417f504b9d 75 void winkR_SW_handler() {
MPPT51 0:a6417f504b9d 76 winkR_SW_pre = !winkR_SW_pre;
MPPT51 0:a6417f504b9d 77 }
MPPT51 0:a6417f504b9d 78
MPPT51 0:a6417f504b9d 79 void winkL_SW_handler() {
MPPT51 0:a6417f504b9d 80 winkL_SW_pre = !winkL_SW_pre;
MPPT51 0:a6417f504b9d 81 }
MPPT51 0:a6417f504b9d 82
MPPT51 0:a6417f504b9d 83 void hazard_SW_handler() {
MPPT51 0:a6417f504b9d 84 hazard_SW_pre = !hazard_SW_pre;
MPPT51 0:a6417f504b9d 85 winkR_SW_pre = 0;
MPPT51 0:a6417f504b9d 86 winkL_SW_pre = 0;
MPPT51 0:a6417f504b9d 87 myled1 = 0;
MPPT51 0:a6417f504b9d 88 myled2 = 0;
MPPT51 0:a6417f504b9d 89 }
MPPT51 0:a6417f504b9d 90
MPPT51 0:a6417f504b9d 91 void horn_SW_handler() {
MPPT51 0:a6417f504b9d 92 if( !horn_SW.read() ){ //ホーンSWを押しているとき
MPPT51 0:a6417f504b9d 93 myled3 = 1;
MPPT51 0:a6417f504b9d 94 horn_Out = 1;
MPPT51 0:a6417f504b9d 95 }
MPPT51 0:a6417f504b9d 96 else { //ホーンSWを離しているとき
MPPT51 0:a6417f504b9d 97 myled3 = 0;
MPPT51 0:a6417f504b9d 98 horn_Out = 0;
MPPT51 0:a6417f504b9d 99 }
MPPT51 0:a6417f504b9d 100 }
MPPT51 0:a6417f504b9d 101
MPPT51 0:a6417f504b9d 102 void lcd1_printf(){
MPPT51 0:a6417f504b9d 103 lcd1.locate(0, 1);
MPPT51 0:a6417f504b9d 104 lcd1.printf( "%d", lcd1_cnt );
MPPT51 0:a6417f504b9d 105 }
MPPT51 0:a6417f504b9d 106
MPPT51 0:a6417f504b9d 107 void lcd2_printf(){
MPPT51 0:a6417f504b9d 108 lcd2.printf( 0, "Hello world!\r" ); // line# (0 or 1), string
MPPT51 0:a6417f504b9d 109 // lcd2.printf( 1, " %d\r", lcd1_cnt, lcd1_cnt, lcd1_cnt ); // \rがないと座標が右にシフトしていく
MPPT51 0:a6417f504b9d 110 // lcd2.printf( 1, "%d %d %d\r", lcd1_cnt, lcd1_cnt, lcd1_cnt ); // \rがないと座標が右にシフトしていく
MPPT51 0:a6417f504b9d 111 // lcd2.printf( 1, "%d %d %d\r", lcd1_cnt, lcd1_cnt, lcd1_cnt ); // \rがないと座標が右にシフトしていく
MPPT51 0:a6417f504b9d 112
MPPT51 0:a6417f504b9d 113 }
MPPT51 0:a6417f504b9d 114
MPPT51 0:a6417f504b9d 115 void MSC_init(){ //USBメモリの初期設定関数
MPPT51 0:a6417f504b9d 116 fp = fopen( "/usb/test.csv", "a"); //ファイルを開く "W"は新規作成して書き込み,"a"は上書き(Fileなければ新規作成書き込み)
MPPT51 0:a6417f504b9d 117 printf("USB fileopen0!\r\n");
MPPT51 0:a6417f504b9d 118 if ( fp == NULL ) {
MPPT51 0:a6417f504b9d 119 printf("USBmemory ERROR!\r\n");
MPPT51 0:a6417f504b9d 120 exit(1);
MPPT51 0:a6417f504b9d 121 }
MPPT51 0:a6417f504b9d 122 fprintf(fp,"a,b,c,d,e,f,g\n"); //ファイル書き込み
MPPT51 0:a6417f504b9d 123 fclose(fp); //ファイルを閉じる
MPPT51 0:a6417f504b9d 124 printf("USB file close!\n");
MPPT51 0:a6417f504b9d 125 }
MPPT51 0:a6417f504b9d 126
MPPT51 0:a6417f504b9d 127 void write_MSC(){ //USBメモリにデータ書き込む関数
MPPT51 0:a6417f504b9d 128 if ( (fp= fopen( "/usb/MPPT.csv", "a")) == NULL ){ //ファイルを開く, aは上書きの命令(ファイルが存在しなければ新規作成する)
MPPT51 0:a6417f504b9d 129 printf("USB error\r\n");
MPPT51 0:a6417f504b9d 130 exit(1);
MPPT51 0:a6417f504b9d 131 }
MPPT51 0:a6417f504b9d 132 // fprintf(fp,"%f,%f,%f,%f,%f,%f\n", Vin1, Cin1, Vout1, Vout1, temp1, temp2); //ファイル書き込み
MPPT51 0:a6417f504b9d 133 fclose(fp); //ファイルを閉じる
MPPT51 0:a6417f504b9d 134 }
MPPT51 0:a6417f504b9d 135
MPPT51 0:a6417f504b9d 136 void toukarui_init(){
MPPT51 0:a6417f504b9d 137 P_SW.mode( PullUp ); // 内蔵プルアップを使う
MPPT51 0:a6417f504b9d 138 winkR_SW.mode( PullUp ); // 内蔵プルアップを使う
MPPT51 0:a6417f504b9d 139 winkL_SW.mode( PullUp ); // 内蔵プルアップを使う
MPPT51 0:a6417f504b9d 140 horn_SW.mode( PullUp ); // 内蔵プルアップを使う
MPPT51 0:a6417f504b9d 141 hazard_SW.mode( PullUp ); // 内蔵プルアップを使う
MPPT51 0:a6417f504b9d 142
MPPT51 0:a6417f504b9d 143 P_SW.rise(&P_SW_handler); //立ち下がり割り込みを設定
MPPT51 0:a6417f504b9d 144 winkR_SW.rise(&winkR_SW_handler); //立ち上がり割り込みを設定
MPPT51 0:a6417f504b9d 145 winkL_SW.rise(&winkL_SW_handler); //立ち上がり割り込みを設定
MPPT51 0:a6417f504b9d 146 horn_SW.fall(&horn_SW_handler); //立ち上がり割り込みを設定
MPPT51 0:a6417f504b9d 147 horn_SW.rise(&horn_SW_handler); //立ち上がり割り込みを設定
MPPT51 0:a6417f504b9d 148 hazard_SW.rise(&hazard_SW_handler); //立ち上がり割り込みを設定
MPPT51 0:a6417f504b9d 149
MPPT51 0:a6417f504b9d 150 flipper0.attach(&winker_flip, 0.67); // the address of the function to be attached (flip) and the interval (2 seconds)
MPPT51 0:a6417f504b9d 151 }
MPPT51 0:a6417f504b9d 152
MPPT51 0:a6417f504b9d 153 int main() {
MPPT51 0:a6417f504b9d 154 wait(0.001);
MPPT51 0:a6417f504b9d 155 lcd1.cls();
MPPT51 0:a6417f504b9d 156 wait(0.001);
MPPT51 0:a6417f504b9d 157 lcd1.locate(0, 0);
MPPT51 0:a6417f504b9d 158 lcd1.printf( "Hello world!");
MPPT51 0:a6417f504b9d 159
MPPT51 0:a6417f504b9d 160 MSC_init(); //USBメモリ初期化
MPPT51 0:a6417f504b9d 161 toukarui_init();
MPPT51 0:a6417f504b9d 162 while(1) {
MPPT51 0:a6417f504b9d 163 lcd1_printf(); //LCD(20*4)への文字表示をする関数
MPPT51 0:a6417f504b9d 164 lcd2_printf(); //LCD(デカ文字)への文字表示をする関数
MPPT51 0:a6417f504b9d 165 lcd1_cnt++;
MPPT51 0:a6417f504b9d 166
MPPT51 0:a6417f504b9d 167 write_MSC(); //USBメモリへ書き込む関数
MPPT51 0:a6417f504b9d 168 wait(1.0);
MPPT51 0:a6417f504b9d 169 }
MPPT51 0:a6417f504b9d 170 }