mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-26 20:26:32 +00:00
Tune HRG-15 driver
This commit is contained in:
parent
f890c2d85a
commit
3515bd3251
@ -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,8 +147,7 @@ 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)"
|
||||||
@ -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,23 +195,16 @@ 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];
|
|
||||||
if (Rg15ReadLine(rg15_buffer)) {
|
|
||||||
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), rg15_buffer);
|
|
||||||
Rg15Process(rg15_buffer);
|
|
||||||
} else {
|
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return serviced;
|
return serviced;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user