Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for MaxBotix HRXL line of sonar ranging sensors #7814

Merged
merged 1 commit into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasmota/language/bg-BG.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/el-GR.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/es-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/he-HE.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ko-KO.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt-BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt-PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ru-RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "А"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sk-SK.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sv-SE.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/tr-TR.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "A"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/uk-UA.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "А"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "安"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh-TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@
#define D_SENSOR_LE01MR_TX "LE-01MR Tx"
#define D_SENSOR_CC1101_GDO0 "CC1101 GDO0"
#define D_SENSOR_CC1101_GDO2 "CC1101 GDO2"
#define D_SENSOR_HRXL_RX "HRXL Rx"

// Units
#define D_UNIT_AMPERE "安"
Expand Down
7 changes: 6 additions & 1 deletion tasmota/tasmota_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ enum UserSelectablePins {
GPIO_LE01MR_TX, // F&F LE-01MR energy meter
GPIO_CC1101_GDO0, // CC1101 pin for RX
GPIO_CC1101_GDO2, // CC1101 pin for RX
GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor
GPIO_SENSOR_END };

// Programmer selectable GPIO functionality
Expand Down Expand Up @@ -308,7 +309,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_DS18X20 "o|" D_SENSOR_DHT11 "o|"
D_SENSOR_HM10_RX "|" D_SENSOR_HM10_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 =
Expand Down Expand Up @@ -797,6 +799,9 @@ const uint8_t kGpioNiceList[] PROGMEM = {
GPIO_CC1101_GDO0, // CC1101 pin for RX
GPIO_CC1101_GDO2, // CC1101 pin for RX
#endif
#ifdef USE_HRXL
GPIO_HRXL_RX,
#endif
};

const uint8_t kModuleNiceList[] PROGMEM = {
Expand Down
126 changes: 126 additions & 0 deletions tasmota/xsns_64_hrxl.ino
Original file line number Diff line number Diff line change
@@ -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