Adding support for MaxBotix HRXL line of sonar ranging sensors

This commit is contained in:
Jon Little 2020-02-27 18:28:06 -06:00
parent 6d79d56956
commit c7ac3c833c
24 changed files with 154 additions and 1 deletions

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "А" #define D_UNIT_AMPERE "А"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "А" #define D_UNIT_AMPERE "А"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "安" #define D_UNIT_AMPERE "安"

View File

@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx" #define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0" #define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2" #define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"
// Units // Units
#define D_UNIT_AMPERE "安" #define D_UNIT_AMPERE "安"

View File

@ -224,6 +224,7 @@ enum UserSelectablePins {
GPIO_LE01MR_TX, // F&F LE-01MR energy meter GPIO_LE01MR_TX, // F&F LE-01MR energy meter
GPIO_CC1101_GDO0, // CC1101 pin for RX GPIO_CC1101_GDO0, // CC1101 pin for RX
GPIO_CC1101_GDO2, // CC1101 pin for RX GPIO_CC1101_GDO2, // CC1101 pin for RX
GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor
GPIO_SENSOR_END }; GPIO_SENSOR_END };
// Programmer selectable GPIO functionality // Programmer selectable GPIO functionality
@ -308,7 +309,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_DS18X20 "o|" D_SENSOR_DHT11 "o|" D_SENSOR_DS18X20 "o|" D_SENSOR_DHT11 "o|"
D_SENSOR_HM10_RX "|" D_SENSOR_HM10_TX "|" D_SENSOR_HM10_RX "|" D_SENSOR_HM10_TX "|"
D_SENSOR_LE01MR_RX "|" D_SENSOR_LE01MR_TX "|" D_SENSOR_LE01MR_RX "|" D_SENSOR_LE01MR_TX "|"
D_SENSOR_CC1101_GDO0 "|" D_SENSOR_CC1101_GDO2 D_SENSOR_CC1101_GDO0 "|" D_SENSOR_CC1101_GDO2 "|"
D_SENSOR_HRXL_RX
; ;
const char kSensorNamesFixed[] PROGMEM = const char kSensorNamesFixed[] PROGMEM =
@ -797,6 +799,9 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_CC1101_GDO0, // CC1101 pin for RX GPIO_CC1101_GDO0, // CC1101 pin for RX
GPIO_CC1101_GDO2, // CC1101 pin for RX GPIO_CC1101_GDO2, // CC1101 pin for RX
#endif #endif
#ifdef USE_HRXL
GPIO_HRXL_RX,
#endif
}; };
const uint8_t kModuleNiceList[] PROGMEM = { const uint8_t kModuleNiceList[] PROGMEM = {

126
tasmota/xsns_64_hrxl.ino Normal file
View File

@ -0,0 +1,126 @@
/*
xsns_64_hrxl.ino - MaxBotix HRXL serial interface
Copyright (C) 2020 Jon Little
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_HRXL
/*********************************************************************************************\
* MaxBotix HRXL-MaxSonar ultrasonic range finders
* Source: https://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf
*
* Hardware Serial will be selected if GPIO1 = [HRXL Rx]
\*********************************************************************************************/
#define XSNS_64 64
#include <TasmotaSerial.h>
#define HRXL_READ_TIMEOUT 400 // us; enough for 6 bytes@9600bps
TasmotaSerial *HRXLSerial = nullptr;
uint32_t hrxl_distance_mm = 0; // distance, mm
bool hrxl_found = false;
/*********************************************************************************************/
void HRXLInit(void)
{
hrxl_found = false;
if ((pin[GPIO_HRXL_RX] < 99))
{
HRXLSerial = new TasmotaSerial(pin[GPIO_HRXL_RX], -1, 1);
if (HRXLSerial->begin(9600))
{
if (HRXLSerial->hardwareSerial())
ClaimSerial();
hrxl_found = true;
HRXLSerial->setTimeout(HRXL_READ_TIMEOUT);
}
}
}
void HRXLEverySecond(void)
{
if (!hrxl_found)
return;
int num_read=0;
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)
hrxl_distance_mm = int(sum / num_read);
}
void HRXLShow(bool json)
{
char types[5] = "HRXL";
if (json)
{
ResponseAppend_P(PSTR(",\"%s\":{\"" D_DISTANCE "\":%d}"), types, hrxl_distance_mm);
#ifdef USE_WEBSERVER
}
else
{
WSContentSend_PD(HTTP_SNS_RANGE, types, hrxl_distance_mm);
#endif // USE_WEBSERVER
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns64(uint8_t function)
{
if (pin[GPIO_HRXL_RX] >= 99)
return false;
switch (function)
{
case FUNC_INIT:
HRXLInit();
break;
case FUNC_EVERY_SECOND:
HRXLEverySecond();
break;
case FUNC_JSON_APPEND:
HRXLShow(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
HRXLShow(0);
break;
#endif // USE_WEBSERVER
}
return false;
}
#endif // USE_HRXL