Commit 16f1cb44 authored by Patrick's avatar Patrick

use m range as float

parent 6f1505c3
......@@ -9,13 +9,22 @@ teal_mallet_gsm TM;
#include "SdFat.h"
SdFat SD;
File myFile;
#define SD_CS_PIN SD_SS
/* settings: */
#define MAX_DEPTH 15000 // sensor to bed depth in mm
#define OFFSET 0 // gauge offset in mm
#define ORDINAL_INTERVAL 15
#define NUM_MMNT 11 // measurement buffer length
#define NUM_TO_SEND 10
#define SERVER_NAME ((char*)"nw.teal-mallet.net")
#define ENTITY_ID ((char*)"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
/* end settings */
// set > 0 to get debug serial output
#define DEBUG_MODE 0
#define DEBUG_MODE 1
// choose processor sleep mode (1 = on)
#define SLEEP_MODE_ON 1
......@@ -24,7 +33,7 @@ File myFile;
const char level_param[] PROGMEM = "Level";
const char level_quali[] PROGMEM = "15 min";
const char level_dtype[] PROGMEM = "STAGE";
const char level_units[] PROGMEM = "mm";
const char level_units[] PROGMEM = "m";
const char level_perid[] PROGMEM = "INSTANT";
// then add the strings to an array (for multiple datastreams), also in progmem
......@@ -45,9 +54,6 @@ state_machine_e g_current_state = SLEEP_IDLE;
// readings are taken on ordinals (0/15/30/45)
t_SensorData last_reading_time;
#define ORDINAL_INTERVAL 15
#define NUM_MMNT 11 // measurement buffer length
// then create a pre-sized array of these structs to hold a set of timestamped measurements
uint8_t num_mmnt = NUM_MMNT;
t_measurement measurements[NUM_MMNT] = {};
......@@ -58,7 +64,6 @@ uint8_t readings_tail = 0;
// sends happen after a fixed number of ordinals
t_SensorData last_sending_time;
// how many readings should be collected for sending (<NUM_MMNT)
#define NUM_TO_SEND 10
#if NUM_TO_SEND >= NUM_MMNT
#error "Can't hold all the readings, reduce NUM_TO_SEND below NUM_MMNT"
......@@ -66,7 +71,7 @@ t_SensorData last_sending_time;
void setup() {
RP.begin(true);
TM.begin(((char*)"nw.teal-mallet.net"), ((char*)"aaaaaaaa-aaaa-aaa-aaa-aaaaaaaaaaaa"));
TM.begin(SERVER_NAME, ENTITY_ID);
delay(100);
Serial.begin(BAUD);
......@@ -174,11 +179,11 @@ void sleep_idle() {
void take_measurement() {
// create the distance variable to hold the stage reading
long temp = -1; // start with OOR
float temp = -1.0; // start with OOR
t_SensorData current_reading = get_reading(ANA);
if (current_reading.sensor == ANA) {
// if it's the correct reading, calculate the output
temp = MAX_DEPTH - RP.distance(current_reading, MB7366);
temp = float(MAX_DEPTH - RP.distance(current_reading, MB7366) - OFFSET) / 1000.0;
}
#if DEBUG_MODE > 1
Serial.print(F("take mmnt at: "));
......@@ -186,12 +191,12 @@ void take_measurement() {
Serial.print(F("STAGE: "));
#endif
#if DEBUG_MODE > 0
Serial.println(temp);
Serial.println(temp, 3);
delay(100);
#endif
// stage calculation should always return positive
if (temp >= 0) {
if (temp >= 0.0) {
// add the reading to the buffer
readings_head = (readings_head + 1) % NUM_MMNT;
#if DEBUG_MODE > 0
......@@ -237,7 +242,7 @@ void take_measurement() {
myFile = SD.open(buff, FILE_WRITE);
if (file_exists == false) {
// write headers
myFile.println(F("date,time,stage(mm)"));
myFile.println(F("date,time,stage(m)"));
}
myFile.print(current_reading.y);
myFile.write('-');
......@@ -255,7 +260,7 @@ void take_measurement() {
myFile.write(':');
myFile.print("00"); // zero seconds
myFile.write(',');
myFile.print(temp); // stage in mm
myFile.print(temp); // stage in m
myFile.println();
myFile.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment