Aliexpressなどで販売されている64x32のフルカラードットマトリクスLED2枚とNucleo F401REを利用して、 E233系の駅停車時、路線名表示ありのLED側面行先表示を再現するプログラムです。 3秒間隔、3段階切替で、路線名、種別、行先、次停車駅を個別に指定することが可能です。

Dependencies:   SDFileSystem mbed

Revision:
32:3bf210e07de7
Parent:
31:d186b04b983e
Child:
33:c934bc793c5a
--- a/main.cpp	Sun Feb 22 10:25:54 2015 +0000
+++ b/main.cpp	Sat Feb 28 05:37:16 2015 +0000
@@ -161,10 +161,15 @@
 bool ScrollEnable = 1;
 
 int ChangeCount = 0;
-int LineNumber = 12;
+int LineNumber = 1;
 int KindNumber = 22;
 int ForNumber = 114;
 int NextStaNumber = 1;
+
+int RoutePatternNumber = 1;
+int DeptStaNumber = 3;
+int TermStaNumber = 32;
+
 char SerialBuffer[30];
 //シリアル処理用バッファ
 char ABuffer[30];
@@ -684,6 +689,183 @@
     }
 }
 
+void ScrollRead2(){
+    //スクロールカウンタを0に戻す
+    ScrollCount = 0;
+    //スクロールバッファ初期化
+    for(int i = 0; i < 2048; i++){
+        for(int j = 0; j < 16; j++){
+            ScrollBuffer[j][i] = 0;
+        }
+    }
+
+    
+    //test
+    //Initialize StopStationCode
+    for (int x = 0; x < MaxStopStation; x++){
+        StopStationCode[x]= 0;
+    }
+    
+    int DeptStaIndex = 0;
+    int TermStaIndex = 0;
+    //sprintf(SDFilePath,"/sd/E233/RoutePattern/RoutePattern%d.bin",1);
+    sprintf(SDFilePath,"/sd/E233/RoutePattern/RoutePattern001001.bin");
+     
+    //始発駅インデックス取得
+    for(int i = 0; i < MaxStopStation; i++){
+        FILE *fp = fopen(SDFilePath, "r");
+        if(fp == NULL) {
+            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+            break;   
+        }else{
+            //停車駅コード取得
+            int test = 0;
+            int test2 = 0;
+            fseek(fp, i*2 + 4, SEEK_SET);
+            test = getc(fp);
+            test = test << 8;
+
+            fseek(fp, i*2 + 4 + 1, SEEK_SET);
+            test2 = getc(fp); 
+            test = test ^ test2;    
+            fclose(fp); 
+            if(test == DeptStaNumber){
+                DeptStaIndex = i + 1;
+                pc.printf("DeptStaIndex:%d\r\n",DeptStaIndex);
+                pc.printf("break\r\n");
+                break;
+                
+            }
+        }
+        pc.printf("DeptSta-loopcount:%d\r\n",i);
+    }
+    
+    //終着駅インデックス取得
+    for(int i = 0; i < MaxStopStation; i++){
+        FILE *fp = fopen(SDFilePath, "r");
+        if(fp == NULL) {
+            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+            break;   
+        }else{
+            //停車駅コード取得
+            int test = 0;
+            int test2 = 0;
+            fseek(fp, i*2 + 4, SEEK_SET);
+            test = getc(fp);
+            test = test << 8;
+
+            fseek(fp, i*2 + 4 + 1, SEEK_SET);
+            test2 = getc(fp); 
+            test = test ^ test2;    
+            fclose(fp); 
+            if(test == TermStaNumber){
+                TermStaIndex = i + 1;
+                pc.printf("TermStaIndex:%d\r\n",TermStaIndex);
+                pc.printf("break\r\n");
+                break;
+                
+            }
+        }
+        pc.printf("TermSta-loopcount:%d\r\n",i);
+    }
+        
+    
+    
+    
+    if(DeptStaIndex != 0 && TermStaIndex != 0){
+        
+        
+        //SDRead StopStationCode
+        //始発駅インデックス < 終着駅インデックスなら
+        if(DeptStaIndex < TermStaIndex){
+            for(int i = 0; i < MaxStopStation; i++){
+                //停車駅コード取得
+                int test = 0;
+                int test2 = 0;
+        
+                FILE *fp = fopen(SDFilePath, "r");
+                if(fp == NULL) {
+                    pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+                    break;    
+                }else{
+                    //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
+                    fseek(fp, DeptStaIndex*2 + i*2 + 4, SEEK_SET);
+                    test = getc(fp);
+                    test = test << 8;
+
+                    fseek(fp, DeptStaIndex*2 + i*2 + 4 + 1, SEEK_SET);
+                    test2 = getc(fp); 
+                    test = test ^ test2;
+            
+                    StopStationCode[i] = test;
+                    pc.printf("StopStationCode[%d]:%d\r\n",i,StopStationCode[i]);
+              
+                    //読み込んだ駅名コードが終着駅コードと同じならばループを抜ける  
+                    if(StopStationCode[i] == TermStaNumber){
+                        break;
+                    }           
+                    fclose(fp); 
+                }
+            }
+        }
+        
+        
+              
+    }else{
+    //始発駅インデックス、終着駅インデックスのどちらか、または両方が0の場合運用パターンデータに駅名コードが存在しない
+        pc.printf("Error DeptStaIndex or TermStaIndex = 0\r\n");
+        pc.printf("Error DeptStaIndex:%d,TermStaIndex:%d",DeptStaIndex,TermStaIndex);
+    }  
+        
+    //test end    
+             
+    //ScrollDebug
+     ScrollWriteCount = 80;
+    
+    //この電車の停車駅は、
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",1);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);
+    ScrollWriteCount = ScrollWriteCount + 80;   
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",2);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;  
+
+    for(int i = 0; i < MaxStopStation; i++){        
+        if(StopStationCode[i] == 0){
+            break;
+        }
+        //駅名
+        sprintf(SDFilePath,"/sd/E233/StationName/%d.bin",StopStationCode[i]);
+        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,128,16);
+        
+        //駅名文字数取得
+        int test = 0;
+        sprintf(SDFilePath,"/sd/E233/StationNameLength.bin");
+        FILE *fp = fopen(SDFilePath, "r");
+        if(fp == NULL) {
+            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+        }else{
+            //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
+            fseek(fp, StopStationCode[i], SEEK_SET);
+            test = getc(fp);
+            //pc.printf("StationNameLength:%d\r\n",test);
+            fclose(fp); 
+        }
+               
+        ScrollWriteCount = ScrollWriteCount + (test * 16);  
+        sprintf(SDFilePath,"/sd/E233/StopStation/0x8132.bin");
+        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,16,16);       
+        ScrollWriteCount = ScrollWriteCount + 16;      
+    }
+    ScrollWriteCount = ScrollWriteCount - 16;
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",3);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;     
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",4);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;   
+    
+    }
 
 
 void SDFileRead(){
@@ -951,6 +1133,43 @@
                 TimerTick();                                
             }
             
+            //データ一括設定2
+            //先頭文字:'B'
+            if(ABuffer[0] == 'B'){
+                //路線名 L
+                //ABuffer[1]は'L'
+                LineNumber = CharToInt(ABuffer[2],ABuffer[3],ABuffer[4]);
+                pc.printf("Line:%d\r\n",LineNumber);
+                
+                //次停車駅 N
+                //ABuffer[5]は'N'                  
+                NextStaNumber = CharToInt(ABuffer[6],ABuffer[7],ABuffer[8]);
+                pc.printf("NextStation:%d\r\n",NextStaNumber);
+                
+                //運用パターン P
+                //Pxxxyyyzzz
+                //x:運用パターン番号(3桁)
+                //y:始発駅(3桁)
+                //z:終着駅(3桁)
+                //ABuffer[9]は'P'                  
+                RoutePatternNumber = CharToInt(ABuffer[10],ABuffer[11],ABuffer[12]);
+                pc.printf("RoutePattern:%d\r\n",RoutePatternNumber);                
+                
+                DeptStaNumber = CharToInt(ABuffer[13],ABuffer[14],ABuffer[15]);
+                pc.printf("DeptStaNumber:%d\r\n",DeptStaNumber); 
+                TermStaNumber = CharToInt(ABuffer[16],ABuffer[17],ABuffer[18]);
+                pc.printf("TermStaNumber:%d\r\n",TermStaNumber); 
+                
+                
+                //一括設定時は続けてSDからの読み込み
+                pc.printf("Set\r\n"); 
+                SDFileRead(); 
+                ScrollRead2();
+                Scroll = 1;
+                //即時反映
+                TimerTick();                                
+            }
+            
         busyflag = false;
     }else{
       count++;
@@ -960,6 +1179,102 @@
     OE = LOW;
 }
 
+void ScrollRead(){
+    //test
+    //Initialize StopStationCode
+    for (int x = 0; x < MaxStopStation; x++){
+        StopStationCode[x]= 0;
+    }
+    
+    //SDRead StopStationCode
+    for(int i = 0; i < MaxStopStation; i++){
+
+        //停車駅コード取得
+        int test = 0;
+        int test2 = 0;
+        sprintf(SDFilePath,"/sd/E233/StopStationList/%d.bin",1);
+        FILE *fp = fopen(SDFilePath, "r");
+        if(fp == NULL) {
+            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+            break;
+            
+        }else{
+            //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
+            fseek(fp, i*2, SEEK_SET);
+            test = getc(fp);
+            test = test << 8;
+
+            fseek(fp, i*2 + 1, SEEK_SET);
+            test2 = getc(fp); 
+            test = test ^ test2;
+            
+            StopStationCode[i] = test;
+            pc.printf("StopStationCode[%d]:%d\r\n",i,StopStationCode[i]);
+              
+        if(StopStationCode[i] == 0){
+            break;
+        }           
+            fclose(fp); 
+        }
+    }        
+        
+    //test end    
+             
+    //ScrollDebug
+     ScrollWriteCount = 80;
+    
+    //この電車の停車駅は、
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",1);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);
+    ScrollWriteCount = ScrollWriteCount + 80;   
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",2);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;  
+
+    for(int i = 0; i < MaxStopStation; i++){        
+        if(StopStationCode[i] == 0){
+            break;
+        }
+        //駅名
+        sprintf(SDFilePath,"/sd/E233/StationName/%d.bin",StopStationCode[i]);
+        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,128,16);
+        
+        //駅名文字数取得
+        int test = 0;
+        sprintf(SDFilePath,"/sd/E233/StationNameLength.bin");
+        FILE *fp = fopen(SDFilePath, "r");
+        if(fp == NULL) {
+            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
+        }else{
+            //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
+            fseek(fp, StopStationCode[i], SEEK_SET);
+            test = getc(fp);
+            //pc.printf("StationNameLength:%d\r\n",test);
+            fclose(fp); 
+        }
+               
+        ScrollWriteCount = ScrollWriteCount + (test * 16);  
+        sprintf(SDFilePath,"/sd/E233/StopStation/0x8132.bin");
+        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,16,16);       
+        ScrollWriteCount = ScrollWriteCount + 16;      
+    }
+    ScrollWriteCount = ScrollWriteCount - 16;
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",3);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;     
+    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",4);
+    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
+    ScrollWriteCount = ScrollWriteCount + 80;   
+    
+    }
+
+
+
+
+
+
+
+
 int main(){
     Init(); // Set things up
     //Serial
@@ -1010,104 +1325,7 @@
     
     //起動時にスクロールデータを読み込み
     if(ScrollEnable == 1){
-
-    //test
-    //Initialize StopStationCode
-    for (int x = 0; x < MaxStopStation; x++){
-        StopStationCode[x]= 0;
-    }
-    
-    //SDRead StopStationCode
-    for(int i = 0; i < MaxStopStation; i++){
-
-        //停車駅コード取得
-        int test = 0;
-        int test2 = 0;
-        sprintf(SDFilePath,"/sd/E233/StopStationList/%d.bin",1);
-        FILE *fp = fopen(SDFilePath, "r");
-        if(fp == NULL) {
-            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
-            break;
-            
-        }else{
-            //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
-            fseek(fp, i*2, SEEK_SET);
-            test = getc(fp);
-            test = test << 8;
-
-            fseek(fp, i*2 + 1, SEEK_SET);
-            test2 = getc(fp); 
-            test = test ^ test2;
-            
-            StopStationCode[i] = test;
-            pc.printf("StopStationCode[%d]:%d\r\n",i,StopStationCode[i]);
-              
-        if(StopStationCode[i] == 0){
-            break;
-        }           
-            fclose(fp); 
-        }
-    }        
-        
-    //test end    
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-        
-    //ScrollDebug
-     ScrollWriteCount = 80;
-    
-    //この電車の停車駅は、
-    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",1);
-    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);
-    ScrollWriteCount = ScrollWriteCount + 80;   
-    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",2);
-    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
-    ScrollWriteCount = ScrollWriteCount + 80;  
-
-    for(int i = 0; i < MaxStopStation; i++){        
-        if(StopStationCode[i] == 0){
-            break;
-        }
-        //駅名
-        sprintf(SDFilePath,"/sd/E233/StationName/%d.bin",StopStationCode[i]);
-        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,128,16);
-        
-        //駅名文字数取得
-        int test = 0;
-        sprintf(SDFilePath,"/sd/E233/StationNameLength.bin");
-        FILE *fp = fopen(SDFilePath, "r");
-        if(fp == NULL) {
-            pc.printf("SDFileOpen Error %s\r\n",SDFilePath);
-        }else{
-            //pc.printf("SDFileOpen Success %s\r\n",SDFilePath);
-            fseek(fp, StopStationCode[i], SEEK_SET);
-            test = getc(fp);
-            //pc.printf("StationNameLength:%d\r\n",test);
-            fclose(fp); 
-        }
-               
-        ScrollWriteCount = ScrollWriteCount + (test * 16);  
-        sprintf(SDFilePath,"/sd/E233/StopStation/0x8132.bin");
-        SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,16,16);       
-        ScrollWriteCount = ScrollWriteCount + 16;      
-    }
-    ScrollWriteCount = ScrollWriteCount - 16;
-    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",3);
-    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
-    ScrollWriteCount = ScrollWriteCount + 80;     
-    sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",4);
-    SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16);       
-    ScrollWriteCount = ScrollWriteCount + 80;      
+        ScrollRead2();
     }