summaryrefslogtreecommitdiff
path: root/Mode
diff options
context:
space:
mode:
authorLeon Lindenfelser <llindenfelser@multitech.com>2015-12-09 08:27:10 -0600
committerLeon Lindenfelser <llindenfelser@multitech.com>2015-12-09 08:27:10 -0600
commitc29f4bf9b0b628df0749cf668bd27894d678785b (patch)
treeab848bdf62c205b963140739ed9c8915382f74c4 /Mode
parent5a74150c78737daf2764570835b59b45141f3775 (diff)
parent61c66f590786b6ff3af5564a86166350d7c4aa31 (diff)
downloadmtdot-box-evb-factory-firmware-c29f4bf9b0b628df0749cf668bd27894d678785b.tar.gz
mtdot-box-evb-factory-firmware-c29f4bf9b0b628df0749cf668bd27894d678785b.tar.bz2
mtdot-box-evb-factory-firmware-c29f4bf9b0b628df0749cf668bd27894d678785b.zip
Merge branch 'sensors'
Diffstat (limited to 'Mode')
-rw-r--r--Mode/Mode.cpp45
-rw-r--r--Mode/Mode.h14
2 files changed, 55 insertions, 4 deletions
diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp
index 70a3f49..a97b226 100644
--- a/Mode/Mode.cpp
+++ b/Mode/Mode.cpp
@@ -2,6 +2,15 @@
#include "MTSLog.h"
/*
+ * union for converting from 32-bit to 4 8-bit values
+ */
+union convert32 {
+ int32_t f_s; // convert from signed 32 bit int
+ uint32_t f_u; // convert from unsigned 32 bit int
+ uint8_t t_u[4]; // convert to 8 bit unsigned array
+}convertL;
+
+/*
* union for converting from 16- bit to 2 8-bit values
*/
union convert16 {
@@ -25,7 +34,10 @@ Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, G
_power(2),
_next_tx(0),
_send_data(false),
- _gps_available(_gps->gpsDetected())
+ _gps_available(_gps->gpsDetected()),
+ _gpsUART(PA_2, PA_3),
+ _mdot_gps(&_gpsUART),
+ _mdot_sensors()
{}
Mode::~Mode() {}
@@ -143,6 +155,16 @@ void Mode::updateData(DataItem& data, DataType type, bool status) {
data.power = _power;
}
+void Mode::updateSensors(SensorItem& data) {
+ data.accel_data = _mdot_sensors.getAcceleration();
+ data.baro_data = _mdot_sensors.getBarometer();
+ data.lux_data_raw = _mdot_sensors.getLightRaw();
+ data.pressure_raw = _mdot_sensors.getPressureRaw();
+ data.light = _mdot_sensors.getLight();
+ data.pressure = _mdot_sensors.getPressure();
+ data.altitude = _mdot_sensors.getAltitude();
+}
+
uint32_t Mode::getIndex(DataType type) {
uint32_t index = 0;
mDot::mdot_file file;
@@ -273,6 +295,27 @@ std::vector<uint8_t> Mode::formatSurveyData(DataItem& data) {
std::vector<uint8_t> Mode::formatSensorData(SensorItem& data) {
std::vector<uint8_t> send_data;
+ send_data.clear();
+ send_data.push_back(0x0E); // key for Current Acceleration 3-Axis Value
+ convertS.f_s = data.accel_data._x *4; // shift data 2 bits while retaining sign
+ send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value
+ convertS.f_s = data.accel_data._y * 4; // shift data 2 bits while retaining sign
+ send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value
+ convertS.f_s = data.accel_data._z * 4; // shift data 2 bits while retaining sign
+ send_data.push_back(convertS.t_u[1]); // get 8 MSB of 14 bit value
+ send_data.push_back(0x08); // key for Current Pressure Value
+ convertL.f_u = data.pressure_raw; // pressure data is 20 bits unsigned
+ send_data.push_back(convertL.t_u[2]);
+ send_data.push_back(convertL.t_u[1]);
+ send_data.push_back(convertL.t_u[0]);
+ send_data.push_back(0x05); // key for Current Ambient Light Value
+ convertS.f_u = data.lux_data_raw; // data is 16 bits unsigned
+ send_data.push_back(convertS.t_u[1]);
+ send_data.push_back(convertS.t_u[0]);
+ send_data.push_back(0x0B); // key for Current Temperature Value
+ convertS.f_s = data.baro_data._temp; // temperature is signed 12 bit
+ send_data.push_back(convertS.t_u[1]);
+ send_data.push_back(convertS.t_u[0]);
return send_data;
}
diff --git a/Mode/Mode.h b/Mode/Mode.h
index 61687f1..ca8433a 100644
--- a/Mode/Mode.h
+++ b/Mode/Mode.h
@@ -10,6 +10,7 @@
#include "MMA845x.h"
#include "MPL3115A2.h"
#include "FileName.h"
+#include "SensorHandler.h"
class Mode {
public:
@@ -36,9 +37,12 @@ class Mode {
typedef struct {
MMA845x_DATA accel_data;
MPL3115A2_DATA baro_data;
- uint16_t lux_data;
- uint32_t pressure;
- } SensorItem;
+ uint16_t lux_data_raw;
+ uint32_t pressure_raw;
+ float light;
+ float pressure;
+ float altitude;
+ } SensorItem;
Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps);
~Mode();
@@ -49,6 +53,7 @@ class Mode {
bool deleteDataFile();
bool appendDataFile(const DataItem& data);
void updateData(DataItem& data, DataType type, bool status);
+ void updateSensors(SensorItem& data);
uint32_t getIndex(DataType type);
std::vector<uint8_t> formatSurveyData(DataItem& data);
@@ -72,6 +77,9 @@ class Mode {
uint8_t _state;
bool _send_data;
bool _gps_available;
+ mts::MTSSerial _gpsUART;
+ GPSPARSER _mdot_gps;
+ SensorHandler _mdot_sensors;
};
#endif