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

Dependencies:   C12832 FXOS8700Q LM75B MMA7660

Revision:
3:1ab88130bb9d
Parent:
2:c871dc21467b
Child:
4:50e2aefe516b
--- a/FrdmK64f_AppShield_Input.hpp	Tue Feb 23 18:56:50 2016 +0000
+++ b/FrdmK64f_AppShield_Input.hpp	Thu Feb 25 14:28:48 2016 +0000
@@ -4,7 +4,7 @@
 #include "LM75B.h"
 #include "MMA7660.h"
 
-#include "Vector.hpp"
+#include "Vector.h"
 #include "Utils.h"
 
 template <class Parent>
@@ -51,33 +51,34 @@
     AnalogIn            _potRight;
     float               _potLeftValue;
     float               _potRightValue;
-    float               _potLeftPrecision;
-    float               _potRightPrecision;
 
     // Tempeture sensor
     LM75B               _temp;
     float               _tempValue;
-    float               _tempPrecision;
     
     bool                _analogInputEnable[IDAnalogInput_MAX];
+    float               _analogInputPrec[IDAnalogInput_MAX];
     
     // Accelerometer
     MMA7660             _accel;
-    Vector<float>       _accelValue;
-    float               _accelPrecision;
+    Vector              _accelValue;
     bool                _vectorInputEnable[IDVectorInput_MAX];
+    float               _vectorInputPrec[IDVectorInput_MAX];
     
 public:
 
     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)
+        _potLeft(A0), _potRight(A1), _potLeftValue(0.0f), _potRightValue(0.0f),
+        _temp(D14, D15), _tempValue(0.0f),
+        _accel(I2C_SDA, I2C_SCL)
     {
         memset(_binaryInputEnable, 1, sizeof(_binaryInputEnable));
-        memset(_analogInputEnable, 1, sizeof(_analogInputEnable));
-        memset(_vectorInputEnable, 1, sizeof(_vectorInputEnable));
+        memset(_analogInputEnable, 0, sizeof(_analogInputEnable));
+        memset(_vectorInputEnable, 0, sizeof(_vectorInputEnable));
+        
+        for (int it = 0; it < IDAnalogInput_MAX; ++it) _analogInputPrec[it] = 100.0f;
+        for (int it = 0; it < IDVectorInput_MAX; ++it) _vectorInputPrec[it] = 10.0f;
         
         _joystickUp.rise(this, &FrdmK64f_AppShield_Input::onJoystickUpRise);
         _joystickUp.fall(this, &FrdmK64f_AppShield_Input::onJoystickUpFall);
@@ -90,9 +91,9 @@
         _joystickMiddle.rise(this, &FrdmK64f_AppShield_Input::onJoystickMiddleRise);
         _joystickMiddle.fall(this, &FrdmK64f_AppShield_Input::onJoystickMiddleFall);
         
-        _potLeftValue = prec(_potLeft, _potLeftPrecision);
-        _potRightValue = prec(_potRight, _potRightPrecision);
-        _tempValue = prec(_temp.read(), _tempPrecision);
+        _potLeftValue = prec(_potLeft, _analogInputPrec[PotLeft]);
+        _potRightValue = prec(_potRight, _analogInputPrec[PotRight]);
+        _tempValue = prec(_temp.read(), _analogInputPrec[Temp]);
     }
     
     using   Parent::setEnable;
@@ -100,10 +101,9 @@
     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); }
-    void    setTempPrecision(short int pres) { _tempPrecision = pow(10.0f, pres); }
-    void    setAccelPrecision(short int pres) { _accelPrecision = pow(10.0f, pres); }
+    using   Parent::setPrecision;
+    void    setPrecision(FrdmK64f_AppShield_Input::IDAnalogInput inp, float prec) { _analogInputPrec[inp] = prec; }
+    void    setPrecision(FrdmK64f_AppShield_Input::IDVectorInput inp, float prec) { _vectorInputPrec[inp] = prec; }
     
     // Not interresting section (do not use those methods)
     // Callbacks for joystick
@@ -119,13 +119,13 @@
     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)
+    virtual void    checkAnalog(void)
     {
-        Parent::chechAnalog();
+        Parent::checkAnalog();
         
         if(_analogInputEnable[PotLeft])
         {
-            Event   event(Event::AppShield, Event::AnalogInput, PotLeft, prec(_potLeft, _potLeftPrecision));
+            Event   event(Event::AppShield, Event::AnalogInput, PotLeft, prec(_potLeft, _analogInputPrec[PotLeft]));
             if (event.analog != _potLeftValue)
             {
                 _potLeftValue = event.analog;
@@ -135,7 +135,7 @@
         
         if(_analogInputEnable[PotRight])
         {
-            Event   event(Event::AppShield, Event::AnalogInput, PotRight, prec(_potRight, _potRightPrecision));
+            Event   event(Event::AppShield, Event::AnalogInput, PotRight, prec(_potRight, _analogInputPrec[PotRight]));
             if (event.analog != _potRightValue)
             {
                 _potRightValue = event.analog;
@@ -145,18 +145,23 @@
         
         if(_analogInputEnable[Temp])
         {
-            Event   event(Event::AppShield, Event::AnalogInput, Temp, prec(_temp.read(), _tempPrecision));
+            Event   event(Event::AppShield, Event::AnalogInput, Temp, prec(_temp.read(), _analogInputPrec[Temp]));
             if (event.analog != _tempValue)
             {
                 _tempValue = event.analog;
                 Parent::_events.push(event);
             }
         }
+    }
+    
+    void    checkVector(void)
+    {
+        Parent::checkVector();
         
         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)))
+            Event   event(Event::AppShield, Event::VectorInput, Accel, Vector(prec(_accel.x(), _analogInputPrec[Accel]), prec(_accel.y(), _analogInputPrec[Accel]), prec(_accel.z(), _analogInputPrec[Accel])));
+            if (!(event.vector.eq(_accelValue, 1.0f / _analogInputPrec[Accel])))
             {
                 _accelValue = event.vector;
                 Parent::_events.push(event);