2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Wed Dec 12 17:32:24 2018 +0000
Parent:
11:8ec858b7c6d1
Child:
13:5566df1250f1
Commit message:
pass back 3 gyro axis data; implement reset shell cmd

Changed in this revision

Updater.cpp Show annotated file Show diff for this revision Revisions of this file
Updater.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/Updater.cpp	Wed Dec 12 17:20:16 2018 +0000
+++ b/Updater.cpp	Wed Dec 12 17:32:24 2018 +0000
@@ -1,7 +1,18 @@
 #include "Updater.h"
 
 
-Updater *Updater::instance() {
+void Updater::gyro(int g[3]) 
+{
+    for (int i=0; i < 3; i++) {
+        g[i] = _gyro[i];
+    }
+    
+    return;
+}
+
+
+Updater *Updater::instance() 
+{
     static Updater instance;
 
     return &instance;
@@ -37,9 +48,7 @@
 
     // Read encoders
     // Read gyro
-    int g_a[3];
-    gyro.read(g_a);
-    g = g_a[2];
+    gyro.read(_gyro);
     
     //gyro[_z_] = (g_sign[_z_] * (g[_z_] - g_offset[_z_])) / g_scale[_z_];
 
--- a/Updater.h	Wed Dec 12 17:20:16 2018 +0000
+++ b/Updater.h	Wed Dec 12 17:32:24 2018 +0000
@@ -4,24 +4,17 @@
 #include "mbed.h"
 #include "L3G4200D.h"
 
-class Updater {
+class Updater: private mbed::NonCopyable<Updater> {
 public:
     void start(int interval_ms);
-
     static Updater *instance();
-    
-    int get_gyro() { return g; }
+    void gyro(int g[3]);
       
 private:
-    typedef struct {
-        int g[3]; // gyro
-        float dt;  // delta time
-    } sensor_data_t;
-
     Updater() {} // parameterize
     Timer *t;
     void update();
-    int g;
+    int _gyro[3];
     int thisTime;
     int lastTime;
 };
--- a/main.cpp	Wed Dec 12 17:20:16 2018 +0000
+++ b/main.cpp	Wed Dec 12 17:32:24 2018 +0000
@@ -31,11 +31,18 @@
 
 void read_gyro() 
 {
+    int g[3];
+    
     Updater *u = Updater::instance();
     
-    printf("Gyro: %d\n", u->get_gyro());
+    u->gyro(g);
     
-    //printf("Gyro: %d, %d, %d\n", g[0], g[1], g[2]);
+    printf("Gyro: %d, %d, %d\n", g[0], g[1], g[2]);
+}
+
+void reset()
+{
+    NVIC_SystemReset();
 }
 
 /******** MAIN ********/
@@ -76,6 +83,7 @@
     // Startup shell    
     sh.attach(test, "test");
     sh.attach(read_gyro, "gyro");
+    sh.attach(reset, "reset");
     thread.start(callback(&sh, &SimpleShell::run));
 
     // Startup updater