Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

trying to get smoothing implemented

  • Loading branch information...
commit 1005495b71708673415ee8cce575e81fd4178999 1 parent 5db6417
@rambo authored
View
8 bma180.cpp
@@ -42,16 +42,10 @@ void bma180::read_sensor_data()
{
*(buff++) = Wire.receive();
}
-
// Calculate checksum
last_data_buffer[4] = last_data_buffer[1] + last_data_buffer[2] + last_data_buffer[3];
- // FIXME: Use circular buffer
- byte buffer_i = 0;
- // Put data to buffer
- smooth_buffer[buffer_i][0] = last_data_buffer[1] >> 2;
- smooth_buffer[buffer_i][1] = last_data_buffer[2] >> 2;
- smooth_buffer[buffer_i][2] = last_data_buffer[3] >> 2;
+ i2c_accelerometer::push_to_smoothing_buffer(last_data_buffer[1] >> 2, last_data_buffer[2] >> 2, last_data_buffer[3] >> 2);
}
View
11 i2c_accelerometer.cpp
@@ -15,3 +15,14 @@ void i2c_accelerometer::begin(byte dev_addr, boolean wire_begin)
i2c_sensor::begin(dev_addr, wire_begin);
}
+void i2c_accelerometer::push_to_smoothing_buffer(int val_x, int val_y, int val_z)
+{
+ smoothing_buffer[0].enqueue(val_x);
+ smoothing_buffer[1].enqueue(val_y);
+ smoothing_buffer[2].enqueue(val_z);
+}
+
+void i2c_accelerometer::smooth()
+{
+
+}
View
13 i2c_accelerometer.h
@@ -4,6 +4,12 @@
#include <WProgram.h>
#include "i2c_sensor.h"
#include <Wire.h>
+#include <SimpleFIFO.h>
+
+
+#ifndef I2C_ACCELEROMETER_SMOOTH_BUFFER_SIZE
+#define I2C_ACCELEROMETER_SMOOTH_BUFFER_SIZE 5
+#endif
class i2c_accelerometer : public i2c_sensor
{
@@ -13,8 +19,13 @@ class i2c_accelerometer : public i2c_sensor
void begin(byte dev_addr, boolean wire_begin);
protected:
- int smooth_buffer[5][3];
+ SimpleFIFO<int,I2C_ACCELEROMETER_SMOOTH_BUFFER_SIZE> smoothing_buffer[3]; // One buffer for each channel
+ //int smoothing_buffer[I2C_ACCELEROMETER_SMOOTH_BUFFER_SIZE][3];
int last_data_buffer[3];
+ int smoothed_buffer[3];
+ void push_to_smoothing_buffer(int val_x, int val_y, int val_z);
+ void smooth();
+
};
#endif
View
3  i2c_sensor_test.pde
@@ -1,5 +1,8 @@
// If this is not here we get compile error on i2c_sensor.h
#include <Wire.h>
+// If this is not here we get a compile error on i2c_accelerometer.h
+#include <SimpleFIFO.h>
+
#include "bma180.h"
bma180 sensor;
Please sign in to comment.
Something went wrong with that request. Please try again.