IO is an event based input manager which permit to select which composents are manged on your system

Dependencies:   C12832 FXOS8700Q LM75B MMA7660

Revision:
1:7be9a82f3ab8
Parent:
0:2ac59c564ab0
Child:
2:c871dc21467b
--- a/FrdmK64f_AppShield_Input.hpp	Tue Feb 23 17:25:07 2016 +0000
+++ b/FrdmK64f_AppShield_Input.hpp	Tue Feb 23 18:38:27 2016 +0000
@@ -10,12 +10,39 @@
 template <class Parent>
 class FrdmK64f_AppShield_Input : public Parent
 {
+public: // List of manged Inputs
+
+    enum IDBinaryInput
+    {
+        JoystickUp,
+        JoystickDown,
+        JoystickLeft,
+        JoystickRight,
+        JoystickMiddle,
+        IDBinaryInput_MAX
+    };
+    
+    enum IDAnalogInput
+    {
+        PotLeft,
+        PotRight,
+        Temp
+    };
+    
+    enum IDVectorInput
+    {
+        Accel
+    };
+
+private:
+    
     // Joystick
     InterruptIn         _joystickUp;
     InterruptIn         _joystickDown;
     InterruptIn         _joystickLeft;
     InterruptIn         _joystickRight;
     InterruptIn         _joystickMiddle;
+    bool                _joystickEnable[IDBinaryInput_MAX];
     
     // Potentiometers
     AnalogIn            _potLeft;
@@ -37,33 +64,14 @@
     
 public:
 
-    enum IDBinaryInput
-    {
-        JoystickUp,
-        JoystickDown,
-        JoystickLeft,
-        JoystickRight,
-        JoystickMiddle
-    };
-    
-    enum IDAnalogInput
-    {
-        PotLeft,
-        PotRight,
-        Temp
-    };
-    
-    enum IDVectorInput
-    {
-        Accel
-    };
-
     FrdmK64f_AppShield_Input(void)
         : _joystickUp(A2), _joystickDown(A3), _joystickLeft(A4), _joystickRight(A5), _joystickMiddle(D4),
         _potLeft(A0), _potRight(A1), _potLeftValue(0.0f), _potRightValue(0.0f), _potLeftPrecision(1000.0f), _potRightPrecision(1000.0f),
         _temp(D14, D15), _tempValue(0.0f), _tempPrecision(10.0f),
         _accel(I2C_SDA, I2C_SCL), _accelPrecision(10.0f)
     {
+        memset(_joystickEnable, 1, sizeof(_joystickEnable));
+        
         _joystickUp.rise(this, &FrdmK64f_AppShield_Input::onJoystickUpRise);
         _joystickUp.fall(this, &FrdmK64f_AppShield_Input::onJoystickUpFall);
         _joystickDown.rise(this, &FrdmK64f_AppShield_Input::onJoystickDownRise);
@@ -80,6 +88,9 @@
         _tempValue = prec(_temp.read(), _tempPrecision);
     }
     
+    using   Parent::setEnable;
+    void    setEnable(FrdmK64f_AppShield_Input::IDBinaryInput inp, bool act) { _joystickEnable[inp] = act; }
+    
     void    setPotLeftPrecision(short int pres) { _potLeftPrecision = pow(10.0f, pres); }
     void    setPotRightPrecision(short int pres) { _potRightPrecision = pow(10.0f, pres); }
     void    setTempPrecision(short int pres) { _tempPrecision = pow(10.0f, pres); }
@@ -87,16 +98,16 @@
     
     // Not interresting section (do not use those methods)
     // Callbacks for joystick
-    void    onJoystickUpRise(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Rise)); }
-    void    onJoystickUpFall(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Fall)); }
-    void    onJoystickDownRise(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Rise)); }
-    void    onJoystickDownFall(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Fall)); }
-    void    onJoystickLeftRise(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Rise)); }
-    void    onJoystickLeftFall(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Fall)); }
-    void    onJoystickRightRise(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Rise)); }
-    void    onJoystickRightFall(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Fall)); }
-    void    onJoystickMiddleRise(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Rise)); }
-    void    onJoystickMiddleFall(void) { Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Fall)); }
+    void    onJoystickUpRise(void) { if (_joystickEnable[JoystickUp]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Rise)); }
+    void    onJoystickUpFall(void) { if (_joystickEnable[JoystickUp]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Fall)); }
+    void    onJoystickDownRise(void) { if (_joystickEnable[JoystickDown]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Rise)); }
+    void    onJoystickDownFall(void) { if (_joystickEnable[JoystickDown]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Fall)); }
+    void    onJoystickLeftRise(void) { if (_joystickEnable[JoystickLeft]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Rise)); }
+    void    onJoystickLeftFall(void) { if (_joystickEnable[JoystickLeft]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Fall)); }
+    void    onJoystickRightRise(void) { if (_joystickEnable[JoystickRight]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Rise)); }
+    void    onJoystickRightFall(void) { if (_joystickEnable[JoystickRight]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Fall)); }
+    void    onJoystickMiddleRise(void) { if (_joystickEnable[JoystickMiddle]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Rise)); }
+    void    onJoystickMiddleFall(void) { if (_joystickEnable[JoystickMiddle]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Fall)); }
     
     // Callback for others sensors
     virtual void    chechAnalog(void)