This is the assessment project

Dependencies:   C12832 FXOS8700Q LM75B mbed

Fork of app-shield-LM75B by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
co838_am2073
Date:
Mon Feb 22 09:03:00 2016 +0000
Parent:
9:b14eedf2e34b
Commit message:
More options, update rate controll, and comments in code

Changed in this revision

core.cpp Show annotated file Show diff for this revision Revisions of this file
core.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/core.cpp	Mon Feb 22 08:26:43 2016 +0000
+++ b/core.cpp	Mon Feb 22 09:03:00 2016 +0000
@@ -40,14 +40,22 @@
     m_btnNext.mode(PullUp);
     m_btnNext.fall(this, &Core::nextTrigger);
     
-    m_stateTicker.attach(this, &Core::updateStateTrigger, 1);
+    m_stateTicker.attach(this, &Core::updateStateTrigger, m_updateRate);
 }
 
-
 void Core::update()
 {
     m_lcd.cls();
     (this->*m_states[m_mode])();
+    float rateValue = (float)m_potentiometerLeft * 10;
+    writeText("Update rate: %1.1fs", 0, 21, rateValue);
+    // update rate if modified
+    if (m_updateRate != rateValue)
+    {
+        m_updateRate = rateValue;
+        m_stateTicker.detach();
+        m_stateTicker.attach(this, &Core::updateStateTrigger, m_updateRate);
+    }
     sleep();
 }
 
@@ -102,7 +110,7 @@
     }
     m_accelerometer.getAxis(data);
     writeText("Accelerometer\n", 33, 3);
-    writeText("X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", 0, 12, data.x, data.y, data.z);
+    writeText("X=%4.1f Y=%4.1f Z=%4.1f\n", 0, 12, data.x, data.y, data.z);
 }
 
 void Core::stateMagnetometer()
@@ -116,5 +124,5 @@
     }
     m_magnetometer.getAxis(data);
     writeText("Magnetometer\n", 33, 3);
-    writeText("X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", 0, 12, data.x, data.y, data.z);
+    writeText("X=%4.1f Y=%4.1f Z=%4.1f\n", 0, 12, data.x, data.y, data.z);
 }
\ No newline at end of file
--- a/core.h	Mon Feb 22 08:26:43 2016 +0000
+++ b/core.h	Mon Feb 22 09:03:00 2016 +0000
@@ -25,7 +25,9 @@
                 m_i2c(PTE25, PTE24),
                 m_accelerometer(m_i2c, FXOS8700CQ_SLAVE_ADDR1),
                 m_magnetometer(m_i2c, FXOS8700CQ_SLAVE_ADDR1),
-                m_stateEntred(false)
+                m_stateEntred(false),
+                m_updateRate(SCREEN_REFRESH_VALUE),
+                m_potentiometerLeft(A0)
                 {}
         virtual ~Core() {}
         enum Mode {
@@ -49,7 +51,13 @@
         void update();
         
     private:
+        /**
+        * Used to change the shield led color
+        */
         void setLedColor(float red, float green, float blue);
+        /**
+        * Used to write text on the LCD screen
+        */
         void writeText(const char* text, int x, int y, ...);
         
     // Triggers
@@ -65,21 +73,23 @@
         void stateMagnetometer();
     
     private:
-        volatile Mode m_mode;
-        PwmOut m_ledR;
-        PwmOut m_ledG;
-        PwmOut m_ledB;
-        C12832 m_lcd;
-        LM75B m_temperature;
-        InterruptIn m_btnNext;
-        InterruptIn m_btnOpt;
-        void (Core::*m_states[MODES_COUNT])();
-        volatile bool m_optTrigger;
-        Ticker m_stateTicker;
-        I2C m_i2c;
-        FXOS8700QAccelerometer m_accelerometer;
-        FXOS8700QMagnetometer m_magnetometer;
-        bool m_stateEntred;
+        volatile Mode m_mode; /*< The current selected state */
+        PwmOut m_ledR; /*< the LED Red color controller */
+        PwmOut m_ledG; /*< the LED Green color controller */
+        PwmOut m_ledB; /*< the LED Blue color controller */
+        C12832 m_lcd; /*< The LCD Object */
+        LM75B m_temperature; /*< The temperature mesurement device */
+        InterruptIn m_btnNext; /*< The SW2 button */
+        InterruptIn m_btnOpt; /*< The SW3 button */
+        void (Core::*m_states[MODES_COUNT])(); /*< Method pointers array for the states */
+        volatile bool m_optTrigger; /*< Manage the states modes */
+        Ticker m_stateTicker; /*< The state ticker, to update the scene */
+        I2C m_i2c; /*< i2c definition */
+        FXOS8700QAccelerometer m_accelerometer; /*< the accelerometer device */
+        FXOS8700QMagnetometer m_magnetometer; /*< the magnetometer device */
+        bool m_stateEntred; /*< Defined to false when entring to a new state. Used to enable the used device */
+        float m_updateRate; /*< The update rate (in seconds */
+        AnalogIn m_potentiometerLeft; /*< the potentiometer device */
 };
 
 #endif /* !CORE_H_ */
\ No newline at end of file
--- a/main.cpp	Mon Feb 22 08:26:43 2016 +0000
+++ b/main.cpp	Mon Feb 22 09:03:00 2016 +0000
@@ -1,3 +1,24 @@
+/**
+* This project is using the following inputs:
+*  - SW2 Button (right): Used to navigate between the different states (views)
+*  - SW3 Button (left): Used to change the state mode -if the state has another mode-
+*  - POT1 Potentiometer (left): Used to change the update rate (in seconds)
+*
+* The project is constructed around one class: Core.
+* This class will manage the inputs, and the different states
+* (I am using a state machine, based on the state ID, and the function pointer of this state).
+* The states functions are called state*StateName*.
+*
+* The current states are:
+*  - Temperature state
+*    => This state has 2 modes (SW3 Button to switch): Celsius or Fahrenheit temperature
+*  - Accelerometer state
+*  - Magnetometer state
+*
+* All the outputs are done on the shield LCD.
+*
+* The documentation for each methods is defined in the core.h file
+*/
 #include "core.h"
 
 int main ()