TTDC / Mbed 2 deprecated switches

Dependencies:   C12832 MMA7660 mbed

Revision:
1:2967eac08981
Parent:
0:c3bc6981ad28
Child:
5:614e3ac042df
--- a/main.cpp	Wed Jan 31 10:58:19 2018 +0000
+++ b/main.cpp	Wed Feb 21 09:13:28 2018 +0000
@@ -1,16 +1,9 @@
 #include "mbed.h"
 #include "C12832.h"
 
-#include "color.h"
-#include "led3.h"
-#include "sound.h"
-#include "accel.h"
-#include "liner.h"
+#include "commands.h"
 
-#define JOY_UP      (0x01)
-#define JOY_DOWN    (0x02)
-#define JOY_LEFT    (0x04)
-#define JOY_RIGHT   (0x08)
+extern COMMAND_DEFINE *commandList[];
 
 BusIn joy(p15,p12,p13,p16);
 DigitalIn fire(p14);
@@ -22,53 +15,33 @@
     lcd.locate(0,3);
     lcd.printf("mbed Switches application");
     
-    ColorInitialize();
-    Led3Initialize();
-    SoundInitialize();
-    AccelInitialize();
-    LinerInitialize();
+    for(int index = 0; commandList[index] != NULL; index++) {
+        commandList[index]->initialize();
+    }
 
     while(true) {
-        char*   message = NULL;
-    
-        if (fire) {
-            message = "Fire!";
-            Led3Process();
-        } else {
-            switch (joy) {
-                case JOY_UP: {
-                    message = "Up!";
-                    SoundProcess();
-                    SoundFinalize();
-                    break;
-                }
-                case JOY_DOWN: {
-                    message = "Down!";
-                    AccelProcess();
-                    break;
-                }
-                case JOY_LEFT: {
-                    message = "Left!";
-                    ColorProcess();
-                    ColorFinalize();
-                    break;
-                }
-                case JOY_RIGHT: {
-                    message = "Right!";
-                    LinerProcess();
-                    break;
-                }
-                default: {
-                    message = NULL;
-                    break;
-                }
+        COMMAND_DEFINE *command = NULL;
+        int trigger = fire ? 0xff : joy;
+/*
+          switch (joy) {
+            case JOY_UP:    {message = "Up!";       SoundProcess(); SoundFinalize();    break;}
+            case JOY_DOWN:  {message = "Down!";     AccelProcess();                     break;}
+            case JOY_LEFT:  {message = "Left!";     ColorProcess(); ColorFinalize();    break;}
+            case JOY_RIGHT: {message = "Right!";    LinerProcess();                     break;}
+            default:        {message = NULL;                                            break;}
+        }
+*/
+        for(int index = 0; commandList[index] != NULL; index++) {
+            if (trigger == commandList[index]->trigger) {
+                command = commandList[index];
             }
         }
-        if (message != NULL) {
+        if (command != NULL) {
             lcd.locate(0,15);
             lcd.printf("        ");
             lcd.locate(0,15);
-            lcd.printf(message);
+            lcd.printf(command->name);
+            command->process();
         }
     }
 }
\ No newline at end of file