Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CtrlStationRX
Diff: main.cpp
- Revision:
- 1:56c272cb4522
- Parent:
- 0:70fee422a0e0
- Child:
- 2:0806f6996e8c
--- a/main.cpp Mon Sep 27 04:26:26 2021 +0000
+++ b/main.cpp Sat Oct 02 05:14:25 2021 +0000
@@ -30,7 +30,7 @@
int main()
{
-
+
POWER[0]=POWER[1]=1;
for(int i=0; i<7; i++) SW[i].mode(PullDown);
@@ -44,11 +44,11 @@
oled.setDispFlag(1,0,0);
// oled.locate(2,0);
// oled.printf("Stop display");
-
+
UART.attach(uartRX, Serial::RxIrq);
while(1) {
-
+
// telemetry.printf("%d\n\r", (SW[6]==0?0:1));
/* SW入力のワンタイム化 */
@@ -81,45 +81,106 @@
static int temp=mainTimer.read_ms();
if(timerMode) msTimer+=mainTimer.read_ms()-temp;
temp=mainTimer.read_ms();
- if(msTimer>120e3){timerMode=0; msTimer=120e3;}
+ if(msTimer>120e3) {
+ timerMode=0;
+ msTimer=120e3;
+ }
/* UART送受信関連 */
- char sentData = (timerMode&1)<<7;
- sentData |= (msTimer/1000)&0x7F;
- UART.putc(sentData);
+ uint8_t sendData[4] = {0};
+ uint8_t checkSum = 0;
+
+ //チェックサム計算
+ for (int i = 0; i < 7; i++)
+ checkSum += msTimer / (int)pow(10.0, (double)i) % 10;
+
+ sendData[3] = 0x80;
+ sendData[3] |= timerMode << 6;
+ sendData[3] |= checkSum & 0x3F;
+
+ //1バイト区切る
+ for(int i = 0; i < 3; i++)
+ sendData[i] = 0x7F & msTimer >> 7 * (2-i);
+
+ for(int i = 0; i < 4; i++){
+ UART.putc(sendData[i]);
+ telemetry.putc(sendData[i]);
+ }
+// telemetry.printf("%d \n\r",msTimer);
+
for(int i=0; i<3; i++)
if(newsTimer[i].read_ms()>500)
newsStatus[i]=0;
- telemetry.printf("%d \n\r",msTimer);
-
+
/* LCD描画 */
- oled.locate(5,0);
- oled.printf("%1d:%02d.%d", msTimer/60000,msTimer/1000%60,msTimer/100%10);
+// oled.locate(5,0);
+// oled.printf("%1d:%02d.%d ", msTimer/60000,msTimer/1000%60,msTimer/100%10);
+//
+// oled.locate(0,0);
+// int statious=!SW[1];
+// if(restFlag&&(SW[2]+SW[3]+SW[4]+SW[5]+SW[6])) restTimer.reset();
+// if(emoTimer.read()<1&&emoTimer.read_ms()%200<100) statious=0;
+// if(statious) oled.printf("EMO ");
+// else oled.printf(" ");
+//
+// oled.locate(12,0);
+// statious=restFlag;
+// if(!SW[1]&&(SW[5]+SW[6])) emoTimer.reset();
+// if(restTimer.read()<1&&restTimer.read_ms()%200<100) statious=0;
+// if(statious) oled.printf("REST");
+// else oled.printf(" ");
- oled.locate(0,0);
+
+// for(int i=0; i<3; i++) {
+// oled.locate(i*6,1);
+// if(newsStatus[i]==0) oled.printf("Lost");
+// if(newsStatus[i]==1) oled.printf("None");
+// if(newsStatus[i]==2) oled.printf("Yoki");
+// }
+// for(int i=0; i<2; i++) {
+// oled.locate(i*6+4,1);
+// oled.printf(" ");
+// }
+
+ char printLCD[32] = {0};
+
int statious=!SW[1];
if(restFlag&&(SW[2]+SW[3]+SW[4]+SW[5]+SW[6])) restTimer.reset();
if(emoTimer.read()<1&&emoTimer.read_ms()%200<100) statious=0;
- if(statious) oled.printf("EMO");
- else oled.printf(" ");
-
- oled.locate(12,0);
+ if(statious) strcat(printLCD,"EMO ");
+ else strcat(printLCD," ");
+
+ char tmp[17] = {0};
+ sprintf(tmp,"%1d:%02d.%d ", msTimer/60000,msTimer/1000%60,msTimer/100%10);
+ strcat(printLCD,tmp);
+
statious=restFlag;
if(!SW[1]&&(SW[5]+SW[6])) emoTimer.reset();
if(restTimer.read()<1&&restTimer.read_ms()%200<100) statious=0;
- if(statious) oled.printf("REST");
- else oled.printf(" ");
-
-
- for(int i=0; i<3; i++) {
- oled.locate(i*6,1);
- if(newsStatus[i]==0) oled.printf("Lost");
- if(newsStatus[i]==1) oled.printf("None");
- if(newsStatus[i]==2) oled.printf("Yoki");
- }
+ if(statious) strcat(printLCD,"REST");
+ else strcat(printLCD," ");
+
+ const char stat[3][5] = {"Lost","None","Yoki"};
+ oled.locate(0,1);
+ sprintf(tmp,"%s %s %s",stat[newsStatus[0]],stat[newsStatus[1]],stat[newsStatus[2]]);
+ strcat(printLCD,tmp);
+
+ oled.locate(0,0);
+ oled.printf(printLCD);
+
+// for(int i=0; i<3; i++) {
+// oled.locate(i*6,1);
+// if(newsStatus[i]==0) oled.printf("Lost");
+// if(newsStatus[i]==1) oled.printf("None");
+// if(newsStatus[i]==2) oled.printf("Yoki");
+// }
+// for(int i=0; i<2; i++) {
+// oled.locate(i*6+4,1);
+// oled.printf(" ");
+// }
//static Timer tim;
//tim.start();
//telemetry.printf("%d \n\r",tim.read_ms());