Use a touchscreen display to select which sensor measurement to display

Dependencies:   mbed DisplayModule24_demo_day10

Files at this revision

API Documentation at this revision

Comitter:
ldelaney17
Date:
Tue Jan 17 21:28:13 2017 +0000
Parent:
7:b275c76de4ba
Commit message:
final commit; cleaned up debug code; added comments; set 10s ticker period

Changed in this revision

DisplayModule24_demo_day10.lib Show annotated file Show diff for this revision Revisions of this file
acc.cpp Show annotated file Show diff for this revision Revisions of this file
compass.cpp Show annotated file Show diff for this revision Revisions of this file
compass.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
tmp.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b275c76de4ba -r a7b7edb66de5 DisplayModule24_demo_day10.lib
--- a/DisplayModule24_demo_day10.lib	Tue Jan 17 21:08:45 2017 +0000
+++ b/DisplayModule24_demo_day10.lib	Tue Jan 17 21:28:13 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/igauli20/code/DisplayModule24_demo_day10/#e361b82dd6f0
+https://developer.mbed.org/users/igauli20/code/DisplayModule24_demo_day10/#939cbbe56322
diff -r b275c76de4ba -r a7b7edb66de5 acc.cpp
--- a/acc.cpp	Tue Jan 17 21:08:45 2017 +0000
+++ b/acc.cpp	Tue Jan 17 21:28:13 2017 +0000
@@ -18,19 +18,20 @@
     connection.read(addr_acc, acc_data, 6); //read the 6 bytes of data
     int16_t data[3];
     float x, y, z;
-    data[0] = acc_data[1] << 8 | acc_data[0];
+    data[0] = acc_data[1] << 8 | acc_data[0]; //shift the bytes into 16bit integers
     data[1] = acc_data[3] << 8 | acc_data[2];
     data[2] = acc_data[5] << 8 | acc_data[4];
-        x = 0.004 * data[0];
+        x = 0.004 * data[0]; //convert the raw data to a value in terms of g
         y = 0.004 * data[1];
         z = 0.004 * data[2];
-        float mag = sqrt(x*x + y*y + z*z);
+        float mag = sqrt(x*x + y*y + z*z); //calculate the magnitude
         #ifdef DEBUG_MODE
         pc.printf("x = %+1.2fg\t y = %1.2fg\t z = %1.2fg\t mag = %+1.2fg\n\r", x, y, z, mag);  
         #endif
     return mag;
 }
 
+//gets the average of n (default 5) readings
 float get_avg_mag(int n){
     if ( n <= 0)
         return 0;
diff -r b275c76de4ba -r a7b7edb66de5 compass.cpp
--- a/compass.cpp	Tue Jan 17 21:08:45 2017 +0000
+++ b/compass.cpp	Tue Jan 17 21:28:13 2017 +0000
@@ -7,7 +7,7 @@
 const char config_single_measure_mode[2] = {0x02, 0x01};
 const char compass_config_data[1] = {0x03};
 
-void compass_init(int num){
+void compass_init(){
     compass = &connection;
     compass->write(compass_addr, config_single_measure_mode, 2); //set single measure mode
 }
@@ -47,7 +47,7 @@
     #endif
     return heading;
 }
-
+//gets the average of n readings
 float get_avg_heading(float declination, int n){
     if (n <= 0)
         return 0;
diff -r b275c76de4ba -r a7b7edb66de5 compass.h
--- a/compass.h	Tue Jan 17 21:08:45 2017 +0000
+++ b/compass.h	Tue Jan 17 21:28:13 2017 +0000
@@ -9,7 +9,7 @@
 
 extern I2C connection;
 //initialize the sensor to single measure mode
-void compass_init(int num = 5);
+void compass_init();
 //calculates the heading from the data, prints the heading if DEBUG_MODE is defined
 float calc_heading(short mags[3], float declination); //x, z, y
 //gets the heading, adjusted for the given declination
diff -r b275c76de4ba -r a7b7edb66de5 main.cpp
--- a/main.cpp	Tue Jan 17 21:08:45 2017 +0000
+++ b/main.cpp	Tue Jan 17 21:28:13 2017 +0000
@@ -14,24 +14,18 @@
 Ticker tDisplay;
 Ticker tTouch;
 bool  a, t, c;
-bool in_A(int x, int y);
-bool in_T(int x, int y);
-bool in_C(int x, int y);
-void update_touch();
 
 int main() {
-    touch.init();
+    touch.init(); //initialize all connections
     temp_init();
     acc_init();
     compass_init();
-    a = false;
+    a = false; //set the global flag variables to start false
     t = false;
     c = false;
-    tDisplay.attach(&display, 3); //2s ticker
-    tTouch.attach(&update_touch, 0.07); //.007s ticker
-
-    while(1) {
-       
+    tDisplay.attach(&display, 10); //10s ticker, per spec, controls the display
+    tTouch.attach(&update_touch, 0.07); //.07s ticker, updates the flags for what is selected
+    while(1) { //loop doing nothing
         }
 }
 
@@ -45,6 +39,7 @@
         return false;
 }
 
+//check if coord is in T's circle
 bool in_T(int x, int y){
     //circle: 40, 100 | r = 40
     x -= 40;
@@ -65,29 +60,3 @@
         return false;
 }
 
-void update_touch(){
-    uint16_t x, y;
-    bool press;
-    x = 0;
-    y = 0;
-    press = false;
-    touch.readTouchData(x, y, press);
-    if (press){
-        if(in_A(x, y)){
-            a = true;
-            t = false;
-            c = false;    
-        }
-        else if (in_T(x, y)) {
-            a = false;
-            t = true;
-            c = false;    
-        }
-        else if (in_C(x, y))
-        {
-            a = false;
-            t = false;
-            c = true;
-        }
-    } 
-}
\ No newline at end of file
diff -r b275c76de4ba -r a7b7edb66de5 tmp.cpp
--- a/tmp.cpp	Tue Jan 17 21:08:45 2017 +0000
+++ b/tmp.cpp	Tue Jan 17 21:28:13 2017 +0000
@@ -30,6 +30,7 @@
         return temp;
 }
 
+// gets the average of n (default 5) temperature readings
 float get_avg_temp(int n){
     if (n <= 0)
         return 0;