mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
Redesign distance sensors HRXL and DYP
Redesign distance sensors HRXL and DYP to use cm instead of mm (#17021)
This commit is contained in:
parent
c14e50820b
commit
05b43fb143
@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Support for BP1658CJ RGBCW led bulbs like Orein OS0100411267 by Cossid (#17011)
|
- Support for BP1658CJ RGBCW led bulbs like Orein OS0100411267 by Cossid (#17011)
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
- Redesign distance sensors HRXL and DYP to use cm instead of mm (#17021)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Default Flash Mode changed from ``DOUT`` to ``DIO`` for ESP8266/ESP8285
|
- Default Flash Mode changed from ``DOUT`` to ``DIO`` for ESP8266/ESP8285
|
||||||
|
@ -123,6 +123,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
|
|||||||
- ESP32 Support for DMX ArtNet Led matrix animations [#16984](https://github.com/arendst/Tasmota/issues/16984)
|
- ESP32 Support for DMX ArtNet Led matrix animations [#16984](https://github.com/arendst/Tasmota/issues/16984)
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
- Redesign distance sensors HRXL and DYP to use cm instead of mm [#17021](https://github.com/arendst/Tasmota/issues/17021)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- ESP32 Framework (Core) from v2.0.5 to v2.0.5.2
|
- ESP32 Framework (Core) from v2.0.5 to v2.0.5.2
|
||||||
|
@ -25,71 +25,54 @@
|
|||||||
* Hardware Serial will be selected if GPIO1 = [HRXL Rx]
|
* Hardware Serial will be selected if GPIO1 = [HRXL Rx]
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_64 64
|
#define XSNS_64 64
|
||||||
|
|
||||||
#include <TasmotaSerial.h>
|
|
||||||
|
|
||||||
#define HRXL_READ_TIMEOUT 400 // us; enough for 6 bytes@9600bps
|
#define HRXL_READ_TIMEOUT 400 // us; enough for 6 bytes@9600bps
|
||||||
|
|
||||||
|
#include <TasmotaSerial.h>
|
||||||
TasmotaSerial *HRXLSerial = nullptr;
|
TasmotaSerial *HRXLSerial = nullptr;
|
||||||
|
|
||||||
uint32_t hrxl_distance_mm = 0; // distance, mm
|
uint32_t hrxl_distance_cm = 0; // distance, cm
|
||||||
bool hrxl_found = false;
|
|
||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
void HRXLInit(void)
|
void HRXLInit(void) {
|
||||||
{
|
if (PinUsed(GPIO_HRXL_RX)) {
|
||||||
hrxl_found = false;
|
HRXLSerial = new TasmotaSerial(Pin(GPIO_HRXL_RX), -1, 1);
|
||||||
if (PinUsed(GPIO_HRXL_RX))
|
if (HRXLSerial->begin(9600)) {
|
||||||
{
|
if (HRXLSerial->hardwareSerial()) {
|
||||||
HRXLSerial = new TasmotaSerial(Pin(GPIO_HRXL_RX), -1, 1);
|
ClaimSerial();
|
||||||
if (HRXLSerial->begin(9600))
|
}
|
||||||
{
|
HRXLSerial->setTimeout(HRXL_READ_TIMEOUT);
|
||||||
if (HRXLSerial->hardwareSerial())
|
|
||||||
ClaimSerial();
|
|
||||||
hrxl_found = true;
|
|
||||||
HRXLSerial->setTimeout(HRXL_READ_TIMEOUT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HRXLEverySecond(void)
|
void HRXLEverySecond(void) {
|
||||||
{
|
int num_read = 0;
|
||||||
if (!hrxl_found)
|
int sum = 0;
|
||||||
return;
|
while (HRXLSerial->available() > 5) {
|
||||||
|
if (HRXLSerial->read() != 'R') {
|
||||||
int num_read=0;
|
continue;
|
||||||
int sum=0;
|
|
||||||
while (HRXLSerial->available()>5)
|
|
||||||
{
|
|
||||||
if (HRXLSerial->read() != 'R')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int d = HRXLSerial->parseInt();
|
|
||||||
if (d >= 30 && d<=5000)
|
|
||||||
{
|
|
||||||
sum += d;
|
|
||||||
num_read++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (num_read>1)
|
int d = HRXLSerial->parseInt();
|
||||||
hrxl_distance_mm = int(sum / num_read);
|
if (d >= 30 && d <= 5000) {
|
||||||
|
sum += d;
|
||||||
|
num_read++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (num_read > 1) {
|
||||||
|
hrxl_distance_cm = int(sum / num_read) / 10; // cm
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HRXLShow(bool json) {
|
||||||
void HRXLShow(bool json)
|
|
||||||
{
|
|
||||||
char types[5] = "HRXL";
|
char types[5] = "HRXL";
|
||||||
if (json)
|
if (json) {
|
||||||
{
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%d}"), types, hrxl_distance_cm);
|
||||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_DISTANCE "\":%d}"), types, hrxl_distance_mm);
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
}
|
} else {
|
||||||
else
|
WSContentSend_PD(HTTP_SNS_DISTANCE_CM, types, hrxl_distance_cm);
|
||||||
{
|
|
||||||
WSContentSend_PD(HTTP_SNS_RANGE, types, hrxl_distance_mm);
|
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,15 +81,12 @@ void HRXLShow(bool json)
|
|||||||
* Interface
|
* Interface
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
bool Xsns64(uint8_t function)
|
bool Xsns64(uint8_t function) {
|
||||||
{
|
if (FUNC_INIT == function) {
|
||||||
if (!PinUsed(GPIO_HRXL_RX)) { return false; }
|
HRXLInit();
|
||||||
|
}
|
||||||
switch (function)
|
else if (HRXLSerial) {
|
||||||
{
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
HRXLInit();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
HRXLEverySecond();
|
HRXLEverySecond();
|
||||||
break;
|
break;
|
||||||
@ -118,8 +98,9 @@ bool Xsns64(uint8_t function)
|
|||||||
HRXLShow(0);
|
HRXLShow(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_HRXL
|
#endif // USE_HRXL
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef USE_DYP
|
#ifdef USE_DYP
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* DYP ME007 ultrasonic distance sensor (300...4000mm), serial version
|
* DYP ME007 ultrasonic distance sensor (300...4000mm), serial version
|
||||||
*
|
*
|
||||||
@ -28,13 +27,11 @@
|
|||||||
* 300...4000 for measured distance
|
* 300...4000 for measured distance
|
||||||
* 4999 for distance above 4000mm
|
* 4999 for distance above 4000mm
|
||||||
* 5999 for not connected sensor
|
* 5999 for not connected sensor
|
||||||
*
|
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_76 76
|
#define XSNS_76 76
|
||||||
|
|
||||||
#include <TasmotaSerial.h>
|
#include <TasmotaSerial.h>
|
||||||
|
|
||||||
TasmotaSerial *DYPSerial = nullptr;
|
TasmotaSerial *DYPSerial = nullptr;
|
||||||
|
|
||||||
#define DYP_CRCERROR -1
|
#define DYP_CRCERROR -1
|
||||||
@ -44,27 +41,22 @@ TasmotaSerial *DYPSerial = nullptr;
|
|||||||
#define DYP_ABOVEMAX 4999
|
#define DYP_ABOVEMAX 4999
|
||||||
#define DYP_NOSENSOR 5999
|
#define DYP_NOSENSOR 5999
|
||||||
|
|
||||||
uint16_t DYPDistance = 0; // distance in milimeters
|
uint16_t DYPDistance = 0; // distance in centimeters
|
||||||
bool DYPSensor = false; // sensor available
|
|
||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
void DYPInit(void) {
|
void DYPInit(void) {
|
||||||
DYPSensor = false;
|
|
||||||
if (PinUsed(GPIO_DYP_RX)) {
|
if (PinUsed(GPIO_DYP_RX)) {
|
||||||
DYPSerial = new TasmotaSerial(Pin(GPIO_DYP_RX), -1, 1);
|
DYPSerial = new TasmotaSerial(Pin(GPIO_DYP_RX), -1, 1);
|
||||||
if (DYPSerial->begin(9600)) {
|
if (DYPSerial->begin(9600)) {
|
||||||
if (DYPSerial->hardwareSerial()) {
|
if (DYPSerial->hardwareSerial()) {
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
}
|
}
|
||||||
DYPSensor = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DYPEverySecond(void) {
|
void DYPEverySecond(void) {
|
||||||
if (!DYPSensor) { return; }
|
|
||||||
|
|
||||||
// check for serial data
|
// check for serial data
|
||||||
if (DYPSerial->available() < 6) {
|
if (DYPSerial->available() < 6) {
|
||||||
DYPDistance = DYP_NOSENSOR;
|
DYPDistance = DYP_NOSENSOR;
|
||||||
@ -95,7 +87,7 @@ void DYPEverySecond(void) {
|
|||||||
if (data > DYP_MAX) {
|
if (data > DYP_MAX) {
|
||||||
data = DYP_ABOVEMAX;
|
data = DYP_ABOVEMAX;
|
||||||
}
|
}
|
||||||
DYPDistance = data;
|
DYPDistance = data / 10; // cm
|
||||||
} else {
|
} else {
|
||||||
DYPDistance = DYP_CRCERROR;
|
DYPDistance = DYP_CRCERROR;
|
||||||
}
|
}
|
||||||
@ -104,12 +96,12 @@ void DYPEverySecond(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DYPShow(bool json) {
|
void DYPShow(bool json) {
|
||||||
char types[5] = "DYP";
|
char types[4] = "DYP";
|
||||||
if (json) {
|
if (json) {
|
||||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_DISTANCE "\":%d}"), types, DYPDistance);
|
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%d}"), types, DYPDistance);
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_PD(HTTP_SNS_RANGE, types, DYPDistance);
|
WSContentSend_PD(HTTP_SNS_DISTANCE_CM, types, DYPDistance);
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,23 +111,23 @@ void DYPShow(bool json) {
|
|||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
bool Xsns76(uint8_t function) {
|
bool Xsns76(uint8_t function) {
|
||||||
if (!PinUsed(GPIO_DYP_RX)) { return false; }
|
if (FUNC_INIT == function) {
|
||||||
|
DYPInit();
|
||||||
switch (function) {
|
}
|
||||||
case FUNC_INIT:
|
else if (DYPSerial) {
|
||||||
DYPInit();
|
switch (function) {
|
||||||
break;
|
case FUNC_EVERY_SECOND:
|
||||||
case FUNC_EVERY_SECOND:
|
DYPEverySecond();
|
||||||
DYPEverySecond();
|
break;
|
||||||
break;
|
case FUNC_JSON_APPEND:
|
||||||
case FUNC_JSON_APPEND:
|
DYPShow(1);
|
||||||
DYPShow(1);
|
break;
|
||||||
break;
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
DYPShow(0);
|
DYPShow(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user