Commits

iorodeo committed 7a69ee3

More debugging ... working out some buffer overflow problems.

Comments (0)

Files changed (4)

firmware/accel_adxl345/accel_adxl345.pde

             ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
                 state.mode = MODE_STOPPED;
             }
+            buffer.clear();
             break;
 
         case CMD_START_STREAM:
 
 // Sends accelerometer data to the host PC
 void sendAccelData() {
-    static int cnt = 0;
+    int sendCnt = 0;
+    static int lineCnt = 0;
     static AccelerometerRaw raw;
+    char valueStr[22];
 
-    while (buffer.getSize() > 0) {
+    while ((buffer.getSize() > 0) && (sendCnt < 20)) {
         raw = buffer.getVal();
-        Serial << raw.XAxis << " " << raw.YAxis << " " << raw.ZAxis;
-        cnt++;
-        if (cnt < maxSendCnt) {
-            Serial << ":";
+        if (lineCnt < maxLineCnt) {
+            sprintf(valueStr,"%06d %06d %06d:",raw.XAxis, raw.YAxis, raw.ZAxis);
+            Serial << valueStr;
+            lineCnt++;
         }
         else {
-            Serial << endl;
-            cnt = 0;
+            sprintf(valueStr,"%06d %06d %06d",raw.XAxis, raw.YAxis, raw.ZAxis);
+            Serial << valueStr << " "  << endl;
+            //Serial << valueStr << " " << buffer.getSize() << endl;
+            lineCnt = 0;
         }
+        sendCnt++;
     }
 }
 

firmware/accel_adxl345/constants.h

 // Constants
 const unsigned long baudRate = 115200;
 //const unsigned long baudRate = 1000000;
-const unsigned int maxSendCnt = 6;
+const unsigned int maxLineCnt = 6;
 const unsigned int bufferSize = 100;
 
-const unsigned long defaultTimerPeriod = 2000;
-const unsigned long minTimerPeriod = 2000;
+const unsigned long defaultTimerPeriod = 5000;
+const unsigned long minTimerPeriod = 5000;
 const unsigned long maxTimerPeriod = 100000;
 
 const unsigned int numRange = 4;

python/accel_adxl345/accel_adxl345.py

         """
         while self.inWaiting() > 0:
             line = self.readline()
+        self.flushInput()
 
     def checkAccelRange(self,value):
         """

python/gui/accel_sensor.py

 from accel_sensor_ui import Ui_AccelSensorMainWindow 
 from accel_adxl345 import AccelADXL345
 
-TIMER_INTERVAL_MS = 0.001
+TIMER_INTERVAL_MS = 0.01
 MIN_INWAITING_SIZE = 15
 
 # Default parameters
 DEFAULT_DURATION = 1.0
-DEFAULT_SAMPLE_RATE = 500.0
+DEFAULT_SAMPLE_RATE = 200.0
 DEFAULT_SAVE_FILE = 'sensor_data.txt'
 
 # Validator parameters
         # Stop streaming, empty buffer, etc
         self.dev.stopStreaming()
         self.dev.emptyBuffer()
-        self.dev.stopStreaming()
-        self.dev.emptyBuffer()
+        #self.dev.stopStreaming()
+        #self.dev.emptyBuffer()
         self.started = False
         self.statusLabel.setText('Status: connected')
         self.setStartStopText()
             self.axes[i].set_ylim(minData,maxData)
 
         self.mpl.canvas.fig.canvas.draw()
-        self.dev.emptyBuffer()
+        #self.dev.emptyBuffer()
 
 
     def setStartStopText(self):