ジョイスティック切換えで色々な処理をやります。 C言語学習用です。

Dependencies:   C12832 MMA7660 mbed

Revision:
13:2c1fe87a06cd
Child:
14:15447d4751c3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main.cpp	Wed Apr 04 20:58:28 2018 +0900
@@ -0,0 +1,79 @@
+#include "mbed.h"
+#include "C12832.h"
+
+#include "commands.h"
+#include "ringBuffer.h"
+
+extern COMMAND_TRRIGER   commandList[];
+extern COMMAND_TRRIGER   triggerNull;
+
+BusIn joyStick(p15,p12,p13,p16,p14);
+C12832 lcd(p5, p7, p6, p8, p11);
+
+int main()
+{
+    lcd.cls();
+    lcd.locate(0,3);
+    lcd.printf("mbed Switches application");
+    
+    // デバイスの初期化
+    for(int index = 0; commandList[index].trigger != nothing; index++) {
+        commandList[index].command->initialize();
+    }
+    
+    COMMAND_TRRIGER *current = &triggerNull;
+    while(true) {
+        
+        // 要求の取得
+        COMMAND_TRRIGER *request = NULL;
+        for(int index = 0; commandList[index].trigger != nothing; index++) {
+            if (joyStick == commandList[index].trigger) {
+                request = &commandList[index];
+            }
+        }
+
+        // 要求があったら
+        if (request != NULL) {
+            bool full = ringbufferPut(request);
+            if (full) {
+                printf("full\n");
+            }
+        }
+
+        // 要求があって実行中のものと異なる場合
+        if (request != NULL && request != current) {
+
+            // コマンドの終了
+            current->command->finalize();
+            current = &triggerNull;
+        }
+
+        // 何も処理していない場合に
+        if (current->trigger == nothing) {
+
+            // 要求があったら
+            if (request != NULL) {
+                
+                // コマンドを開始
+                current = request;
+                lcd.locate(0,15);
+                lcd.printf("        ");
+                lcd.locate(0,15);
+                lcd.printf(current->command->name);
+                current->command->processInitialize();
+            }
+        } else {
+            
+            // コマンドの実行
+            current->command->processRunning();
+            
+            // コマンドが終わったら
+            if (! current->command->processIsContinue()){
+
+                // コマンドの終了
+                current->command->finalize();
+                current = &triggerNull;
+            }
+        }
+    }
+}
\ No newline at end of file