Commit 9cbdff15 authored by Patrick's avatar Patrick

updates to red-peg library version

parent 03d1932a
......@@ -5,10 +5,11 @@
// master only functions
void red_peg::begin(uint8_t ss_pin, bool report_serial)
void red_peg::begin(bool sd_write, uint8_t ss_pin, bool report_serial)
{
// set the slave select pin
_ss_pin = ss_pin;
_sd_write = sd_write;
pinMode(_ss_pin, OUTPUT);
digitalWrite(_ss_pin, HIGH);
pinMode(RP_SDI_PIN, INPUT);
......@@ -64,11 +65,11 @@ t_SensorData red_peg::get(sensor_e request)
delay(PROCESSING_DELAY*2);
//delay(100);
for (uint8_t i=0; i<BUFFER_LEN+1; i++) {
// send an empty get
incoming = ask();
if (incoming.the_sensor == request) {
return incoming;
}
// send an empty get
incoming = ask();
delay(PROCESSING_DELAY);
}
// otherwise indicate an empty response
......@@ -87,14 +88,19 @@ void red_peg::print_data(t_SensorData data_record)
Serial.write(',');
Serial.print(data_record.y);
Serial.write('-');
if (data_record.m < 10) { Serial.write('0'); }
Serial.print(data_record.m);
Serial.write('-');
if (data_record.d < 10) { Serial.write('0'); }
Serial.print(data_record.d);
Serial.write('T');
if (data_record.hh < 10) { Serial.write('0'); }
Serial.print(data_record.hh);
Serial.write(':');
if (data_record.mm < 10) { Serial.write('0'); }
Serial.print(data_record.mm);
Serial.write(':');
if (data_record.ss < 10) { Serial.write('0'); }
Serial.print(data_record.ss);
Serial.write('Z');
Serial.write(',');
......@@ -217,11 +223,13 @@ long red_peg::level(t_SensorData data_record, long max_level)
}
}
long red_peg::distance(t_SensorData data_record)
long red_peg::distance(t_SensorData data_record, usound_e sensor_type)
{
long max_distance = 765L; // default MX7060 is 0-765cm
if (sensor_type == MB7366) { max_distance = 10240L; } // MB7366 is 0–10,240mm
if (data_record.the_command == ANA) {
long distance = map(data_record.the_reading, 0, MAX_20MA, 0, 765L);
return distance; // in cm
long distance = map(data_record.the_reading, 0, MAX_20MA, 0, max_distance);
return distance; // in mm or cm
} else {
return -1L;
}
......
......@@ -27,7 +27,7 @@
#define START_BYTE 0xFF
#define END_BYTE 0x00
#define TRANSFER_DELAY 25 // µs spi inter-byte delay
#define PROCESSING_DELAY 100 // no. ms to allow for the slave to process the request
#define PROCESSING_DELAY 10 // no. ms to allow for the slave to process the request
// possible inputs for the_command or the_sensor
enum sensor_e {EMPTY, AVAILABLE, OK, RTC, ADC1, ADC2, ADC3, SDI_12, SET_RTC, SDI_12_FLOAT, SDI_12_SCAN, VERSION};
......@@ -36,6 +36,9 @@ enum sensor_e {EMPTY, AVAILABLE, OK, RTC, ADC1, ADC2, ADC3, SDI_12, SET_RTC, SDI
#define ANA ADC2
#define TMP ADC3
// possible ultrasound sensors
enum usound_e {MB7060, MB7366};
// min and max values for 4-20mA readings
// ADC max is 2.048V
#ifndef MIN_4MA
......@@ -82,6 +85,7 @@ private:
volatile uint8_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail;
bool _sd_write = false;
uint8_t _ss_pin;
uint8_t _get_timeout = 4;
void printHex(byte* data, int data_len);
......@@ -90,7 +94,7 @@ public:
const size_t size_t_SensorData = sizeof(t_SensorData);
// set up the red-peg library requirements (call during setup())
void begin(uint8_t ss_pin = 8, bool report_serial = true);
void begin(bool sd_write = false, uint8_t ss_pin = 8, bool report_serial = true);
// use RP.ask(REQUEST) to retrieve the value from the requested sensor
t_SensorData ask(sensor_e request = EMPTY, uint8_t _y = END_BYTE, uint8_t _m = END_BYTE, uint8_t _d = END_BYTE, uint8_t _hh = END_BYTE, uint8_t _mm = END_BYTE, uint8_t _ss = END_BYTE, uint16_t _the_reading = END_BYTE); //, float _the_data = 0.0);
// use RP.get(REQUEST) to queue a request for a reading
......@@ -115,7 +119,7 @@ public:
float level(t_SensorData data_record, double max_level);
float level(t_SensorData data_record, float max_level);
// TODO:
long distance(t_SensorData data_record); // Ultrasonic distance reading
long distance(t_SensorData data_record, usound_e sensor_type = MB7060); // Ultrasonic distance reading (and sensor type)
};
#endif // red_peg_h
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