Tune HRG-15 driver

This commit is contained in:
Theo Arends 2022-01-03 12:45:47 +01:00
parent f890c2d85a
commit 3515bd3251

View File

@ -128,7 +128,7 @@ void Rg15Init(void) {
if (HydreonSerial) {
if (HydreonSerial->begin(RG15_BAUDRATE)) {
if (HydreonSerial->hardwareSerial()) { ClaimSerial(); }
Rg15.init_step = 3;
Rg15.init_step = 5; // Perform RG-15 init
}
}
}
@ -138,8 +138,7 @@ void Rg15Poll(void) {
bool publish = false;
if (!HydreonSerial->available()) {
// Check if the rain event has timed out, reset rate to 0
if (Rg15.time) {
if (Rg15.time) { // Check if the rain event has timed out, reset rate to 0
Rg15.time--;
if (!Rg15.time) {
Rg15.acc = 0;
@ -148,8 +147,7 @@ void Rg15Poll(void) {
}
}
} else {
// Now read what's available
char rg15_buffer[RG15_BUFFER_SIZE];
char rg15_buffer[RG15_BUFFER_SIZE]; // Read what's available
while (HydreonSerial->available()) {
Rg15ReadLine(rg15_buffer);
if (Rg15Process(rg15_buffer)) { // Do NOT use "publish = Rg15Process(rg15_buffer)"
@ -162,20 +160,18 @@ void Rg15Poll(void) {
MqttPublishSensor();
}
// Units: I = Imperial (in) or M = Metric (mm)
// Resolution: H = High (0.001) or L = Low (0.01)
// Mode: P = Request mode (Polling) or C = Continuous mode - report any change
// Request: R = Read available data once
char init_commands[] = "R CLM "; // Indexed by Rg15.init_step
if (Rg15.init_step) {
Rg15.init_step--;
if (1 == Rg15.init_step) {
// HydreonSerial->println('I'); // Imperial (in)
HydreonSerial->println('M'); // Metric (mm)
// HydreonSerial->println('H'); // High resolution (0.001)
HydreonSerial->println('L'); // Low resolution (0.01)
// HydreonSerial->println('P'); // Request mode (Polling)
HydreonSerial->println('C'); // Continuous mode - report any change
}
if (0 == Rg15.init_step) {
HydreonSerial->println('R'); // Read available data once
char cmnd = init_commands[Rg15.init_step];
if (cmnd != ' ') {
HydreonSerial->println(cmnd);
}
}
}
@ -199,23 +195,16 @@ bool Rg15Command(void) {
bool serviced = true;
if (XdrvMailbox.data_len == 1) {
char *send = XdrvMailbox.data;
char send = XdrvMailbox.data[0] & 0xDF; // Make uppercase
HydreonSerial->flush(); // Flush receive buffer
HydreonSerial->println(send);
HydreonSerial->flush();
if (send[0] == 'k' || send[0] == 'K' || send[0] == 'o' || send[0] == 'O') {
ResponseCmndDone();
return serviced;
if ('K' == send) {
Rg15.init_step = 5; // Perform RG-15 init
}
char rg15_buffer[RG15_BUFFER_SIZE];
if (Rg15ReadLine(rg15_buffer)) {
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), rg15_buffer);
Rg15Process(rg15_buffer);
} else {
ResponseCmndDone();
}
}
return serviced;
}