whatever

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Revision:
52:ba2017c3ef8d
Parent:
51:61a1ec3c56fc
Child:
53:3a99061b392f
--- a/main.cpp	Tue Jan 19 03:23:28 2016 +0000
+++ b/main.cpp	Wed Jan 20 20:44:15 2016 +0000
@@ -11,6 +11,8 @@
 #include "PowerControl.h"
 #include "EthernetPowerControl.h"
 
+// MOD I2C
+//#include "MODI2C.h"
 
 // M2X Support Libraries
 #include <jsonlite.h>
@@ -60,13 +62,16 @@
 AnalogIn   fsrPin(P0_24);      // Label A1 -- FSR output voltage
 //AnalogIn   tempGnd(P0_24);
 
-//I2C axis(P0_0, P0_1);       // SDA, SCL
+// Accelerometer
+I2C axis(P0_0, P0_1);       // SDA, SCL
+//MODI2C axisMod(P0_0, P0_1);   // Using MODI2C library
+
 //LIS331 axle(P0_0, P0_1);        // Library object
 
 
 /* POWER CONFIG
-5V: To thermistor systems
-
+5V:     To thermistor system, to FSR opamp
+3.3V:   To FSR input voltage, to LIS331 accelerometer
 
 */
 
@@ -114,24 +119,20 @@
 int main(void)
 {
     
-    printf("\r\n\n\n\n-----\r\nI'm alive - vers. uB - device codes PONY_v1.4\r\n\n");
-    #ifdef THROWAWAY
-    printf("Using THROWAWAY M2X device\r\n");
-    #endif
-    
-    #ifndef THROWAWAY
-    printf("Using PONY_v1.4 M2X device\r\n");
-    #endif    
+    printf("\r\n\n\n\n-----\r\nI'm alive - vers. uAXIS - accelerometer testing\r\n\n");
     
     // POWER MANAGEMENT
-    printf("Shut down ethernet interface.\r\n");
+    printf("\nShut down ethernet interface.\r\n");
     PHY_PowerDown();    // Turn off the ethernet interface; -175mW
     
     C027 thisBoard;
-    printf("Disable GPS power supply.\r\n");
+    printf("Disable GPS power supply.\r\n\n");
     thisBoard.gpsPower(false);      // Turn off the GPS power supply
     
+    
 
+
+/*
     MDMSerial mdm;
     MDMParser::DevStatus devStatus = {};
     MDMParser::NetStatus netStatus = {};
@@ -157,6 +158,8 @@
     // Cell location data
     MDMSerial::CellLocData thisLoc;
     
+    */
+    
     // Location loop driving variables
     int loopIter = 0;
     bool sendStatus = false;
@@ -182,6 +185,8 @@
     const int sensorMask = 2;  // 1 = GNSS, 2 = CellLocate (aka cell grid position info), 3 = Hybrid: GNSS + CellLocate
     int cellLocReqTimeout = cellLocPeriod - timeoutMargin;  // in seconds       
     const int targetAccuracy = 1; // in meters
+    
+    
 
     
     // -----------------------
@@ -195,6 +200,150 @@
         
         //printf("tick\r\n");
         
+        
+        
+        // Let's play with the accelerometer (STM LIS331)
+        
+        printf("LIS331 experiments\r\n\n");
+        
+        axis.frequency(100000);     // in Hz
+        
+        int whowho;
+        int I2Cret;
+        
+        // RAW WHOAMI
+
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x0F << 1);
+        axis.start();
+        axis.write(0x3B);
+        whowho = axis.read(1);
+        axis.stop();
+        printf("raw WhoAmI = 0x%02x\r\n\n", whowho);   
+        delay(500);
+
+        // RAW config1 set
+        printf("Set CONFIG1 to 0xC7\r\n");
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20 << 1);
+        axis.write(0xC7);
+        axis.stop();
+        delay(10);
+        
+        
+        // RAW config1 read
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20 << 1);
+        axis.start();
+        axis.write(0x3B);
+        I2Cret = axis.read(1);
+        axis.stop();
+        printf("raw config1 = 0x%02x\r\n", I2Cret);
+        delay(10);
+
+        
+        
+        // RAW WHOAMI
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x0F);
+        axis.start();
+        axis.write(0x3B);
+        whowho = axis.read(1);
+        axis.stop();
+        printf("post-CONFIG1 raw WhoAmI = 0x%02x\r\n", whowho);
+        delay(10);         
+        
+        /*
+        
+        // RAW config1 read
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20);
+        axis.start();
+        axis.write(0x3B);
+        I2Cret = axis.read(1);
+        axis.stop();
+        printf("raw config1 = 0x%02x\r\n", I2Cret);        
+        delay(10);        
+        
+        // RAW config1 read
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20);
+        axis.start();
+        axis.write(0x3B);
+        I2Cret = axis.read(1);
+        axis.stop();
+        printf("raw config1 = 0x%02x\r\n", I2Cret);        
+        delay(10);
+        
+        
+        // RAW config1 set
+        printf("Set CONFIG1 to 0xC7\r\n");
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20);
+        axis.write(0xC7);
+        axis.stop();
+        delay(10);
+        
+        
+        // RAW config1 read
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20);
+        axis.start();
+        axis.write(0x3B);
+        I2Cret = axis.read(1);
+        axis.stop();
+        printf("raw config1 = 0x%02x\r\n", I2Cret);        
+        delay(10);        
+                
+        // RAW config1 read
+        axis.start();
+        axis.write(0x3A);
+        axis.write(0x20);
+        axis.start();
+        axis.write(0x3B);
+        I2Cret = axis.read(1);
+        axis.stop();
+        printf("raw config1 = 0x%02x\r\n", I2Cret);        
+        delay(10);                
+        
+        
+        
+        /* MCB using mbed I2C
+        
+        printf("LIS331 whoAmI = 0x%02x\r\n", accelWhoAmI(&axis));
+        delay(1000);
+        
+        
+        printf("Configure accelerometer...\r\n");
+        int axisRet = configureAccel(&axis);
+        printf("config response = 0x%02x\r\n", axisRet);
+        
+        delay(1000);
+        printf("LIS331 whoAmI = 0x%02x\r\n", accelWhoAmI(&axis));
+        
+        
+        
+        
+        
+        */
+        
+        
+        printf("-- LOOP END --\r\n\n");
+        
+        // COMMENT OUT NON-AXIS CODE
+        /*
+        
+        
+        
+        
         // Wake up the modem
         printf("Wake up the modem...\r\n");
         thisBoard.mdmWakeup();
@@ -223,7 +372,7 @@
         /* N.B.
         Right now I'm conducting these tests serially in the loop in ancitipation of behavior that will modify itself based on whether we're seeing lots of highly uncertain or extrapolated readings;
         not sure what that behavior is yet, but we're not optimizing enough that I care about nesting conditionals yet.
-        */
+        *
         
         // 1. Does the location data exist?
         if( thisLoc.validData ) {//if( (mdm.cellLocGet(&thisLoc)) ) {
@@ -296,7 +445,7 @@
                     
                     // Report keg fill  kegweight
                     if (float kegW = getWeight(&fsrPin) ) {
-                        printf("fill weight=%.1fkg\r\n",kegW);    
+                        printf("keg weight=%.1fkg\r\n",kegW);    
                         M2X_response = m2xClient.updateStreamValue(DEVID, "kegweight", kegW);
                         if(M2X_response == 202)
                             printf("Keg weight (%.2f) POST successful\r\n", kegW);                        
@@ -352,7 +501,7 @@
         
         // Successful read
         if( (!fail1count) && (!fail2count) && (!fail3count) ) {
-            kLocLoopDelay = 1 * (60 * 1000);    // Set # minute wait before next read
+            kLocLoopDelay = 30; //20 * (60 * 1000);    // Set # minute wait before next read
             printf("Successful LOC read; ");
         }
         // Too many invalid location reads
@@ -410,6 +559,10 @@
         delay(kLocLoopDelay);
         led1 = 0;   // Turn that LED off!
         
+        */
+        
+        delay(5000);
+        
     }