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

Dependencies:   C12832 FXOS8700Q LM75B MMA7660

Revision:
2:c871dc21467b
Parent:
1:7be9a82f3ab8
Child:
3:1ab88130bb9d
--- a/FrdmK64f_AppShield_Input.hpp	Tue Feb 23 18:38:27 2016 +0000
+++ b/FrdmK64f_AppShield_Input.hpp	Tue Feb 23 18:56:50 2016 +0000
@@ -26,12 +26,14 @@
     {
         PotLeft,
         PotRight,
-        Temp
+        Temp,
+        IDAnalogInput_MAX
     };
     
     enum IDVectorInput
     {
-        Accel
+        Accel,
+        IDVectorInput_MAX
     };
 
 private:
@@ -42,7 +44,7 @@
     InterruptIn         _joystickLeft;
     InterruptIn         _joystickRight;
     InterruptIn         _joystickMiddle;
-    bool                _joystickEnable[IDBinaryInput_MAX];
+    bool                _binaryInputEnable[IDBinaryInput_MAX];
     
     // Potentiometers
     AnalogIn            _potLeft;
@@ -57,10 +59,13 @@
     float               _tempValue;
     float               _tempPrecision;
     
+    bool                _analogInputEnable[IDAnalogInput_MAX];
+    
     // Accelerometer
     MMA7660             _accel;
     Vector<float>       _accelValue;
     float               _accelPrecision;
+    bool                _vectorInputEnable[IDVectorInput_MAX];
     
 public:
 
@@ -70,7 +75,9 @@
         _temp(D14, D15), _tempValue(0.0f), _tempPrecision(10.0f),
         _accel(I2C_SDA, I2C_SCL), _accelPrecision(10.0f)
     {
-        memset(_joystickEnable, 1, sizeof(_joystickEnable));
+        memset(_binaryInputEnable, 1, sizeof(_binaryInputEnable));
+        memset(_analogInputEnable, 1, sizeof(_analogInputEnable));
+        memset(_vectorInputEnable, 1, sizeof(_vectorInputEnable));
         
         _joystickUp.rise(this, &FrdmK64f_AppShield_Input::onJoystickUpRise);
         _joystickUp.fall(this, &FrdmK64f_AppShield_Input::onJoystickUpFall);
@@ -89,7 +96,9 @@
     }
     
     using   Parent::setEnable;
-    void    setEnable(FrdmK64f_AppShield_Input::IDBinaryInput inp, bool act) { _joystickEnable[inp] = act; }
+    void    setEnable(FrdmK64f_AppShield_Input::IDBinaryInput inp, bool act) { _binaryInputEnable[inp] = act; }
+    void    setEnable(FrdmK64f_AppShield_Input::IDAnalogInput inp, bool act) { _analogInputEnable[inp] = act; }
+    void    setEnable(FrdmK64f_AppShield_Input::IDVectorInput inp, bool act) { _vectorInputEnable[inp] = act; }
     
     void    setPotLeftPrecision(short int pres) { _potLeftPrecision = pow(10.0f, pres); }
     void    setPotRightPrecision(short int pres) { _potRightPrecision = pow(10.0f, pres); }
@@ -98,21 +107,23 @@
     
     // Not interresting section (do not use those methods)
     // Callbacks for joystick
-    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)); }
+    void    onJoystickUpRise(void) { if (_binaryInputEnable[JoystickUp]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Rise)); }
+    void    onJoystickUpFall(void) { if (_binaryInputEnable[JoystickUp]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickUp, Event::Fall)); }
+    void    onJoystickDownRise(void) { if (_binaryInputEnable[JoystickDown]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Rise)); }
+    void    onJoystickDownFall(void) { if (_binaryInputEnable[JoystickDown]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickDown, Event::Fall)); }
+    void    onJoystickLeftRise(void) { if (_binaryInputEnable[JoystickLeft]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Rise)); }
+    void    onJoystickLeftFall(void) { if (_binaryInputEnable[JoystickLeft]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickLeft, Event::Fall)); }
+    void    onJoystickRightRise(void) { if (_binaryInputEnable[JoystickRight]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Rise)); }
+    void    onJoystickRightFall(void) { if (_binaryInputEnable[JoystickRight]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickRight, Event::Fall)); }
+    void    onJoystickMiddleRise(void) { if (_binaryInputEnable[JoystickMiddle]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Rise)); }
+    void    onJoystickMiddleFall(void) { if (_binaryInputEnable[JoystickMiddle]) Parent::_events.push(Event(Event::AppShield, Event::BinaryInput, JoystickMiddle, Event::Fall)); }
     
     // Callback for others sensors
     virtual void    chechAnalog(void)
     {
         Parent::chechAnalog();
+        
+        if(_analogInputEnable[PotLeft])
         {
             Event   event(Event::AppShield, Event::AnalogInput, PotLeft, prec(_potLeft, _potLeftPrecision));
             if (event.analog != _potLeftValue)
@@ -121,6 +132,8 @@
                 Parent::_events.push(event);
             }
         }
+        
+        if(_analogInputEnable[PotRight])
         {
             Event   event(Event::AppShield, Event::AnalogInput, PotRight, prec(_potRight, _potRightPrecision));
             if (event.analog != _potRightValue)
@@ -129,6 +142,8 @@
                 Parent::_events.push(event);
             }
         }
+        
+        if(_analogInputEnable[Temp])
         {
             Event   event(Event::AppShield, Event::AnalogInput, Temp, prec(_temp.read(), _tempPrecision));
             if (event.analog != _tempValue)
@@ -137,6 +152,8 @@
                 Parent::_events.push(event);
             }
         }
+        
+        if(_vectorInputEnable[Accel])
         {
             Event   event(Event::AppShield, Event::VectorInput, Accel, Vector<float>(prec(_accel.x(), _accelPrecision), prec(_accel.y(), _accelPrecision), prec(_accel.z(), _accelPrecision)));
             if (!(event.vector.eq(_accelValue, 1.0f / _accelPrecision)))