Skip to content
Snippets Groups Projects
Verified Commit b666c62f authored by Zoe Michaela Dietmar Pfister's avatar Zoe Michaela Dietmar Pfister :gay_pride_flag:
Browse files

teros type change

parent 0caa3523
No related branches found
No related tags found
2 merge requests!39Merge Develop into Main,!32Implement Teros Sensors
Pipeline #105024 passed
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include "ESPNow.hpp" #include "ESPNow.hpp"
#include <Arduino.h> #include <Arduino.h>
#include <DS18B20.h> #include <DS18B20.h>
#include <Terros10.h> #include <Teros10.h>
#include <Terros11.h> #include <Teros11.h>
#include <f_deep_sleep.hpp> #include <f_deep_sleep.hpp>
#include <soc/rtc_cntl_reg.h> #include <soc/rtc_cntl_reg.h>
...@@ -21,11 +21,11 @@ DS18B20 ds18b20_2{ONE_WIRE_BUS, 2}; ...@@ -21,11 +21,11 @@ DS18B20 ds18b20_2{ONE_WIRE_BUS, 2};
// Pass our oneWire reference to Dallas Temperature. // Pass our oneWire reference to Dallas Temperature.
Terros11 terros11_1(4, 1); Teros11 terros11_1(4, 1);
Terros11 terros11_0(4, 0); Teros11 terros11_0(4, 0);
Terros10 terros10_a0; Teros10 terros10_a0;
Terros10 terros10_a1; Teros10 terros10_a1;
Terros10 terros10_a2; Teros10 terros10_a2;
void readout(); void readout();
void setup() { void setup() {
...@@ -64,7 +64,7 @@ void readout() { ...@@ -64,7 +64,7 @@ void readout() {
auto ds18b20_data_2 = ds18b20_2.buildMessages(); auto ds18b20_data_2 = ds18b20_2.buildMessages();
// combine messages from all sensors // combine messages from all sensors
std::__cxx11::list<Message> messages; std::list<Message> messages;
messages.splice(messages.end(), terros_11_0_data); messages.splice(messages.end(), terros_11_0_data);
messages.splice(messages.end(), terros_11_1_data); messages.splice(messages.end(), terros_11_1_data);
......
#include "Terros10.h" #include "Teros10.h"
//TODO: Refactor //TODO: Refactor
static const char *TAG = "DR26"; static const char *TAG = "DR26";
void Terros10::setup() { void Teros10::setup() {
if (sensorConnected) { if (sensorConnected) {
ESP_LOGD(TAG, "ADS already initialized"); ESP_LOGD(TAG, "ADS already initialized");
return; return;
...@@ -22,7 +22,7 @@ void Terros10::setup() { ...@@ -22,7 +22,7 @@ void Terros10::setup() {
channel = 0; channel = 0;
} }
Measurement Terros10::readData() { Measurement Teros10::readData() {
float volts = 0; float volts = 0;
int16_t adc = 0; int16_t adc = 0;
...@@ -60,21 +60,21 @@ Measurement Terros10::readData() { ...@@ -60,21 +60,21 @@ Measurement Terros10::readData() {
// GAIN_FOUR // 4x gain +/- 1.024V 1 bit = 0.03125mV // GAIN_FOUR // 4x gain +/- 1.024V 1 bit = 0.03125mV
// GAIN_EIGHT // 8x gain +/- 0.512V 1 bit = 0.015625mV // GAIN_EIGHT // 8x gain +/- 0.512V 1 bit = 0.015625mV
// GAIN_SIXTEEN // 16x gain +/- 0.256V 1 bit = 0.0078125mV // GAIN_SIXTEEN // 16x gain +/- 0.256V 1 bit = 0.0078125mV
void Terros10::changeGain(adsGain_t gain) { void Teros10::changeGain(adsGain_t gain) {
ads.setGain(gain); ads.setGain(gain);
} }
void Terros10::setChannel(int c) { void Teros10::setChannel(int c) {
channel = c; channel = c;
} }
std::list<Message> Terros10::buildMessages() { std::list<Message> Teros10::buildMessages() {
std::list<Message> messages; std::list<Message> messages;
auto data = readData(); auto data = readData();
messages.emplace_back(data, sensorInformation, Time::getInstance().getEpochSeconds()); messages.emplace_back(data, sensorInformation, Time::getInstance().getEpochSeconds());
return messages; return messages;
} }
SensorInformation Terros10::getSensorInformation() const { SensorInformation Teros10::getSensorInformation() const {
return sensorInformation; return sensorInformation;
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <Wire.h> #include <Wire.h>
#include "NoDataAvailableException.hpp" #include "NoDataAvailableException.hpp"
class Terros10: public ForteSensor<Measurement> { class Teros10 : public ForteSensor<Measurement> {
public: public:
void setup() override; void setup() override;
Measurement readData() override; Measurement readData() override;
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
// Created by zoe on 3/27/23. // Created by zoe on 3/27/23.
// //
#include "Terros11.h" #include "Teros11.h"
#include <Definitions.h>
static const char *TAG = "Terros11"; static const char *TAG = "Teros11";
std::list<Message> Terros11::buildMessages() { std::list<Message> Teros11::buildMessages() {
Terros11Data data = readData(); Terros11Data data = readData();
std::list<Message> messages; std::list<Message> messages;
messages.emplace_back(data.soilTemperature, getSensorInformation(), Time::getInstance().getEpochSeconds()); messages.emplace_back(data.soilTemperature, getSensorInformation(), Time::getInstance().getEpochSeconds());
...@@ -15,7 +14,7 @@ std::list<Message> Terros11::buildMessages() { ...@@ -15,7 +14,7 @@ std::list<Message> Terros11::buildMessages() {
return messages; return messages;
} }
void Terros11::setup() { void Teros11::setup() {
ESP_LOGD(TAG, "Scanning all addresses, please wait..."); ESP_LOGD(TAG, "Scanning all addresses, please wait...");
ESP_LOGD(TAG, "Sensor Address, Protocol Version, Sensor Vendor, Sensor Model, Sensor Version, Sensor ID"); ESP_LOGD(TAG, "Sensor Address, Protocol Version, Sensor Vendor, Sensor Model, Sensor Version, Sensor ID");
...@@ -28,7 +27,7 @@ void Terros11::setup() { ...@@ -28,7 +27,7 @@ void Terros11::setup() {
} }
} }
Terros11Data Terros11::takeMeasurement(const String &measurementType) { Terros11Data Teros11::takeMeasurement(const String &measurementType) {
sdi12.clearBuffer(); sdi12.clearBuffer();
sendTakeMeasurementCommand(measurementType); sendTakeMeasurementCommand(measurementType);
delay(100); delay(100);
...@@ -59,13 +58,13 @@ Terros11Data Terros11::takeMeasurement(const String &measurementType) { ...@@ -59,13 +58,13 @@ Terros11Data Terros11::takeMeasurement(const String &measurementType) {
ErrorType::SENSOR_DOES_NOT_RETURN_DATA)}; ErrorType::SENSOR_DOES_NOT_RETURN_DATA)};
} }
void Terros11::sendTakeMeasurementCommand(const String &meas_type) { void Teros11::sendTakeMeasurementCommand(const String &meas_type) {
auto address = SDI12Utilities::decToChar(sdiAddress); auto address = SDI12Utilities::decToChar(sdiAddress);
String command = String(address) + "M" + meas_type + "!"; String command = String(address) + "M" + meas_type + "!";
sdi12.sendCommand(command); sdi12.sendCommand(command);
} }
Terros11Data Terros11::getResults() { Terros11Data Teros11::getResults() {
uint8_t commandNumber = 0; uint8_t commandNumber = 0;
sendGetResultsCommand(commandNumber); sendGetResultsCommand(commandNumber);
...@@ -98,14 +97,14 @@ Terros11Data Terros11::getResults() { ...@@ -98,14 +97,14 @@ Terros11Data Terros11::getResults() {
* SDI-12 requires that a '+' be sent after the address if the sensor is expecting a response. * SDI-12 requires that a '+' be sent after the address if the sensor is expecting a response.
* This function checks if there is a '+' as the next sdi12 char and tosses it if so. * This function checks if there is a '+' as the next sdi12 char and tosses it if so.
*/ */
void Terros11::skipPlusCharacter() { void Teros11::skipPlusCharacter() {
char c = sdi12.peek(); // check if there's a '+' and toss if so char c = sdi12.peek(); // check if there's a '+' and toss if so
if (c == '+') { if (c == '+') {
sdi12.read(); sdi12.read();
} }
} }
void Terros11::sendGetResultsCommand(const uint8_t &commandNumber) { void Teros11::sendGetResultsCommand(const uint8_t &commandNumber) {
String command = ""; String command = "";
// in this example we will only take the 'DO' measurement // in this example we will only take the 'DO' measurement
command = ""; command = "";
...@@ -116,16 +115,16 @@ void Terros11::sendGetResultsCommand(const uint8_t &commandNumber) { ...@@ -116,16 +115,16 @@ void Terros11::sendGetResultsCommand(const uint8_t &commandNumber) {
sdi12.sendCommand(command); sdi12.sendCommand(command);
} }
SensorInformation Terros11::getSensorInformation() const { SensorInformation Teros11::getSensorInformation() const {
return sensorInformation; return sensorInformation;
} }
Terros11::Terros11(int8_t dataPin, int sdiAddress) : dataPin(dataPin), sdiAddress(sdiAddress) { Teros11::Teros11(int8_t dataPin, int sdiAddress) : dataPin(dataPin), sdiAddress(sdiAddress) {
sdi12.begin(dataPin); sdi12.begin(dataPin);
delay(50); delay(50);
} }
Terros11Data Terros11::readData() { Terros11Data Teros11::readData() {
char addr = SDI12Utilities::decToChar(sdiAddress); char addr = SDI12Utilities::decToChar(sdiAddress);
ESP_LOGD(TAG, "Reading data from sensor at address %c", addr); ESP_LOGD(TAG, "Reading data from sensor at address %c", addr);
ESP_LOGD(TAG, "Timestamp: %lu", millis()); ESP_LOGD(TAG, "Timestamp: %lu", millis());
......
...@@ -2,26 +2,28 @@ ...@@ -2,26 +2,28 @@
// Created by zoe on 3/27/23. // Created by zoe on 3/27/23.
// //
#ifndef CLIENT_SATELLITE_TERROS11_H #ifndef CLIENT_SATELLITE_TEROS11_H
#define CLIENT_SATELLITE_TERROS11_H #define CLIENT_SATELLITE_TEROS11_H
#include "SDI12Utilities.h" #include "SDI12Utilities.h"
#include <ForteSensor.hpp> #include <ForteSensor.hpp>
#include <Definitions.h> #include <Definitions.h>
#include <SDI12.h> #include <SDI12.h>
#include <Definitions.h>
struct Terros11Data { struct Terros11Data {
Measurement soilTemperature; Measurement soilTemperature;
Measurement soilMoisture; Measurement soilMoisture;
}; };
class Terros11 : ForteSensor<Terros11Data> { class Teros11 : ForteSensor<Terros11Data> {
public: public:
Terros11Data readData() override; Terros11Data readData() override;
void setup() override; void setup() override;
std::list<Message> buildMessages() override; std::list<Message> buildMessages() override;
[[nodiscard]] SensorInformation getSensorInformation() const override; [[nodiscard]] SensorInformation getSensorInformation() const override;
Terros11(int8_t dataPin, int sdiAddress); Teros11(int8_t dataPin, int sdiAddress);
private: private:
Terros11Data takeMeasurement(const String& measurementType = ""); Terros11Data takeMeasurement(const String& measurementType = "");
...@@ -35,4 +37,4 @@ class Terros11 : ForteSensor<Terros11Data> { ...@@ -35,4 +37,4 @@ class Terros11 : ForteSensor<Terros11Data> {
void skipPlusCharacter(); void skipPlusCharacter();
}; };
#endif // CLIENT_SATELLITE_TERROS11_H #endif // CLIENT_SATELLITE_TEROS11_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment