mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 20:56:35 +00:00
Tune HRG-15 driver
This commit is contained in:
parent
f890c2d85a
commit
3515bd3251
@ -62,11 +62,11 @@ bool Rg15ReadLine(char* buffer) {
|
|||||||
uint32_t cmillis = millis();
|
uint32_t cmillis = millis();
|
||||||
while (HydreonSerial->available() ) {
|
while (HydreonSerial->available() ) {
|
||||||
char c = HydreonSerial->read();
|
char c = HydreonSerial->read();
|
||||||
if (c == 10) { break; } // New line ends the message
|
if (c == 10) { break; } // New line ends the message
|
||||||
|
|
||||||
if ((c >= 32) && (c < 127)) { // Accept only valid characters
|
if ((c >= 32) && (c < 127)) { // Accept only valid characters
|
||||||
buffer[i++] = c;
|
buffer[i++] = c;
|
||||||
if (i == RG15_BUFFER_SIZE -1) { break; } // Overflow
|
if (i == RG15_BUFFER_SIZE -1) { break; } // Overflow
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((millis() - cmillis) > RG15_READ_TIMEOUT) {
|
if ((millis() - cmillis) > RG15_READ_TIMEOUT) {
|
||||||
@ -84,9 +84,9 @@ bool Rg15ReadLine(char* buffer) {
|
|||||||
float Rg15Parse(char* buffer, const char* item) {
|
float Rg15Parse(char* buffer, const char* item) {
|
||||||
char* start = strstr(buffer, item);
|
char* start = strstr(buffer, item);
|
||||||
if (start != nullptr) {
|
if (start != nullptr) {
|
||||||
char* end = strstr(start, " mm"); // Metric (mm or mmph)
|
char* end = strstr(start, " mm"); // Metric (mm or mmph)
|
||||||
if (end == nullptr) {
|
if (end == nullptr) {
|
||||||
end = strstr(start, " i"); // Imperial (in or iph)
|
end = strstr(start, " i"); // Imperial (in or iph)
|
||||||
}
|
}
|
||||||
if (end != nullptr) {
|
if (end != nullptr) {
|
||||||
char tmp = end[0];
|
char tmp = end[0];
|
||||||
@ -111,7 +111,7 @@ bool Rg15Process(char* buffer) {
|
|||||||
Rg15.rate = Rg15Parse(buffer, "RInt");
|
Rg15.rate = Rg15Parse(buffer, "RInt");
|
||||||
|
|
||||||
if (Rg15.acc > 0.0f) {
|
if (Rg15.acc > 0.0f) {
|
||||||
Rg15.time = RG15_EVENT_TIMEOUT; // We have some data, so the rain event is on-going
|
Rg15.time = RG15_EVENT_TIMEOUT; // We have some data, so the rain event is on-going
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ void Rg15Init(void) {
|
|||||||
if (HydreonSerial) {
|
if (HydreonSerial) {
|
||||||
if (HydreonSerial->begin(RG15_BAUDRATE)) {
|
if (HydreonSerial->begin(RG15_BAUDRATE)) {
|
||||||
if (HydreonSerial->hardwareSerial()) { ClaimSerial(); }
|
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;
|
bool publish = false;
|
||||||
|
|
||||||
if (!HydreonSerial->available()) {
|
if (!HydreonSerial->available()) {
|
||||||
// Check if the rain event has timed out, reset rate to 0
|
if (Rg15.time) { // Check if the rain event has timed out, reset rate to 0
|
||||||
if (Rg15.time) {
|
|
||||||
Rg15.time--;
|
Rg15.time--;
|
||||||
if (!Rg15.time) {
|
if (!Rg15.time) {
|
||||||
Rg15.acc = 0;
|
Rg15.acc = 0;
|
||||||
@ -148,11 +147,10 @@ void Rg15Poll(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Now read what's available
|
char rg15_buffer[RG15_BUFFER_SIZE]; // Read what's available
|
||||||
char rg15_buffer[RG15_BUFFER_SIZE];
|
|
||||||
while (HydreonSerial->available()) {
|
while (HydreonSerial->available()) {
|
||||||
Rg15ReadLine(rg15_buffer);
|
Rg15ReadLine(rg15_buffer);
|
||||||
if (Rg15Process(rg15_buffer)) { // Do NOT use "publish = Rg15Process(rg15_buffer)"
|
if (Rg15Process(rg15_buffer)) { // Do NOT use "publish = Rg15Process(rg15_buffer)"
|
||||||
publish = true;
|
publish = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,20 +160,18 @@ void Rg15Poll(void) {
|
|||||||
MqttPublishSensor();
|
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) {
|
if (Rg15.init_step) {
|
||||||
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)
|
char cmnd = init_commands[Rg15.init_step];
|
||||||
HydreonSerial->println('L'); // Low resolution (0.01)
|
if (cmnd != ' ') {
|
||||||
|
HydreonSerial->println(cmnd);
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,22 +195,15 @@ bool Rg15Command(void) {
|
|||||||
bool serviced = true;
|
bool serviced = true;
|
||||||
|
|
||||||
if (XdrvMailbox.data_len == 1) {
|
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->println(send);
|
||||||
HydreonSerial->flush();
|
|
||||||
|
|
||||||
if (send[0] == 'k' || send[0] == 'K' || send[0] == 'o' || send[0] == 'O') {
|
if ('K' == send) {
|
||||||
ResponseCmndDone();
|
Rg15.init_step = 5; // Perform RG-15 init
|
||||||
return serviced;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char rg15_buffer[RG15_BUFFER_SIZE];
|
ResponseCmndDone();
|
||||||
if (Rg15ReadLine(rg15_buffer)) {
|
|
||||||
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), rg15_buffer);
|
|
||||||
Rg15Process(rg15_buffer);
|
|
||||||
} else {
|
|
||||||
ResponseCmndDone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviced;
|
return serviced;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user