mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 05:06:32 +00:00
Relax system load when not using SR04
This commit is contained in:
parent
670164f4d0
commit
56fcd0e634
@ -49,7 +49,7 @@ struct {
|
|||||||
TasmotaSerial* sonar_serial = nullptr;
|
TasmotaSerial* sonar_serial = nullptr;
|
||||||
} SR04[MAX_SR04];
|
} SR04[MAX_SR04];
|
||||||
|
|
||||||
uint8_t sensor_count = 0;
|
uint8_t sr04_sensor_count = 0;
|
||||||
|
|
||||||
uint16_t Sr04TMiddleValue(uint16_t first, uint16_t second, uint16_t third) {
|
uint16_t Sr04TMiddleValue(uint16_t first, uint16_t second, uint16_t third) {
|
||||||
uint16_t ret = first;
|
uint16_t ret = first;
|
||||||
@ -115,7 +115,7 @@ void Sr04TModeDetect(void) {
|
|||||||
for (uint32_t i = 0; i < MAX_SR04; i++) {
|
for (uint32_t i = 0; i < MAX_SR04; i++) {
|
||||||
SR04[i].type = SR04_MODE_NONE;
|
SR04[i].type = SR04_MODE_NONE;
|
||||||
if (!PinUsed(GPIO_SR04_ECHO, i)) { continue; }
|
if (!PinUsed(GPIO_SR04_ECHO, i)) { continue; }
|
||||||
sensor_count++;
|
sr04_sensor_count++;
|
||||||
int sr04_echo_pin = Pin(GPIO_SR04_ECHO, i);
|
int sr04_echo_pin = Pin(GPIO_SR04_ECHO, i);
|
||||||
int sr04_trig_pin = Pin(GPIO_SR04_TRIG, i); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_TRIG as -1
|
int sr04_trig_pin = Pin(GPIO_SR04_TRIG, i); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_TRIG as -1
|
||||||
SR04[i].sonar_serial = new TasmotaSerial(sr04_echo_pin, sr04_trig_pin, 1);
|
SR04[i].sonar_serial = new TasmotaSerial(sr04_echo_pin, sr04_trig_pin, 1);
|
||||||
@ -197,7 +197,7 @@ void Sr04Show(uint32_t i, bool json) {
|
|||||||
if (SR04[i].valid) {
|
if (SR04[i].valid) {
|
||||||
char types[12];
|
char types[12];
|
||||||
// backward compatibility check
|
// backward compatibility check
|
||||||
if (i == 0 && sensor_count == 1) {
|
if (i == 0 && sr04_sensor_count == 1) {
|
||||||
strcpy_P(types, PSTR("SR04"));
|
strcpy_P(types, PSTR("SR04"));
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(types, sizeof(types), PSTR("SR04%c%d"), IndexSeparator(), i+1);
|
snprintf_P(types, sizeof(types), PSTR("SR04%c%d"), IndexSeparator(), i+1);
|
||||||
@ -224,21 +224,23 @@ void Sr04Show(uint32_t i, bool json) {
|
|||||||
bool Xsns22(uint32_t function) {
|
bool Xsns22(uint32_t function) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < MAX_SR04; i++) {
|
if (PinUsed(GPIO_SR04_ECHO, GPIO_ANY)) {
|
||||||
if (SR04[i].type) {
|
for (uint32_t i = 0; i < MAX_SR04; i++) {
|
||||||
switch (function) {
|
if (SR04[i].type) {
|
||||||
case FUNC_EVERY_SECOND:
|
switch (function) {
|
||||||
Sr04TReading(i);
|
case FUNC_EVERY_SECOND:
|
||||||
result = true;
|
Sr04TReading(i);
|
||||||
break;
|
result = true;
|
||||||
case FUNC_JSON_APPEND:
|
break;
|
||||||
Sr04Show(i, 1);
|
case FUNC_JSON_APPEND:
|
||||||
break;
|
Sr04Show(i, 1);
|
||||||
#ifdef USE_WEBSERVER
|
break;
|
||||||
case FUNC_WEB_SENSOR:
|
#ifdef USE_WEBSERVER
|
||||||
Sr04Show(i, 0);
|
case FUNC_WEB_SENSOR:
|
||||||
break;
|
Sr04Show(i, 0);
|
||||||
#endif // USE_WEBSERVER
|
break;
|
||||||
|
#endif // USE_WEBSERVER
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user