Tasmota/tasmota/xsns_77_vl53l1x.ino

129 lines
3.4 KiB
Arduino
Raw Normal View History

Squashed commit of the following: commit 0917b430c3b76e26fad584ddacb1fc389e1b4c36 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 17:13:53 2020 +0200 Domoticz commit e878ae5ac4e2b72443598d699f76f1efbe90b5c2 Merge: 77957d70 46789ef4 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 13:24:37 2020 +0200 Merge pull request #118 from device111/vl53l1x VL53L1X correction commit 46789ef40b6b8a3fbf730ed69712e0790b876075 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:41:32 2020 +0200 Update support_features.ino commit 8f8720d37e5d81d6c483620a83936b2f5ffd9f43 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:36:24 2020 +0200 VL53L1X correction sorry, but i have killed all of my repos..:-( commit 77957d70435e99bb42b64b39acb7b7a176ecac79 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri Aug 28 13:54:25 2020 +0200 use registry commit d85954db359fb789c685fbf1ceb6d80fadc5132c Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:43:20 2020 +0200 No DOMOTICZ commit e6d763f10b0d34420f908382442af21581358a84 Merge: 788e4681 6c5fdb4d Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:42:29 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 788e468145520f3832255d92bf50d0ee70c18e0c Merge: 51491df1 33f3f9ef Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:50:28 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 51491df1419fa50d1327565b61a40ca5f81a99d6 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:49:56 2020 +0200 Real 0x52 is 0x29 in Arduino 7 bit commit 00dad36b086b03a93dd02ffa28e5d097ba479f10 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon Aug 24 11:41:11 2020 +0200 1.01 commit 50e88038c3de477f6b657b3d3caa5e53992ca838 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 20:04:47 2020 +0200 correct support_feature commit e5baabc41c1c016066a0ba9d3a8d8006cadd32ec Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 19:53:15 2020 +0200 VL53L1X
2020-09-01 16:24:36 +01:00
/*
xsns_77_vl53l1x.ino - VL53L1X
Copyright (C) 2018 Theo Arends, Rui Marinho and Johann Obermeier
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_I2C
#ifdef USE_VL53L1X
/*********************************************************************************************\
* VL53L1X
*
* Source:
*
* I2C Address: 0x29
\*********************************************************************************************/
#define XSNS_77 77
2020-09-29 10:08:03 +01:00
#define XI2C_54 54 // See I2CDEVICES.md
Squashed commit of the following: commit 0917b430c3b76e26fad584ddacb1fc389e1b4c36 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 17:13:53 2020 +0200 Domoticz commit e878ae5ac4e2b72443598d699f76f1efbe90b5c2 Merge: 77957d70 46789ef4 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 13:24:37 2020 +0200 Merge pull request #118 from device111/vl53l1x VL53L1X correction commit 46789ef40b6b8a3fbf730ed69712e0790b876075 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:41:32 2020 +0200 Update support_features.ino commit 8f8720d37e5d81d6c483620a83936b2f5ffd9f43 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:36:24 2020 +0200 VL53L1X correction sorry, but i have killed all of my repos..:-( commit 77957d70435e99bb42b64b39acb7b7a176ecac79 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri Aug 28 13:54:25 2020 +0200 use registry commit d85954db359fb789c685fbf1ceb6d80fadc5132c Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:43:20 2020 +0200 No DOMOTICZ commit e6d763f10b0d34420f908382442af21581358a84 Merge: 788e4681 6c5fdb4d Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:42:29 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 788e468145520f3832255d92bf50d0ee70c18e0c Merge: 51491df1 33f3f9ef Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:50:28 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 51491df1419fa50d1327565b61a40ca5f81a99d6 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:49:56 2020 +0200 Real 0x52 is 0x29 in Arduino 7 bit commit 00dad36b086b03a93dd02ffa28e5d097ba479f10 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon Aug 24 11:41:11 2020 +0200 1.01 commit 50e88038c3de477f6b657b3d3caa5e53992ca838 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 20:04:47 2020 +0200 correct support_feature commit e5baabc41c1c016066a0ba9d3a8d8006cadd32ec Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 19:53:15 2020 +0200 VL53L1X
2020-09-01 16:24:36 +01:00
#include "VL53L1X.h"
VL53L1X vl53l1x = VL53L1X(); // create object copy
#define VL53L1X_ADDRESS 0x29
struct {
bool ready = false;
uint16_t distance = 0;
} vl53l1x_sensors;
/********************************************************************************************/
void Vl53l1Detect(void) {
if (!I2cSetDevice(VL53L1X_ADDRESS)) { return; }
if (!vl53l1x.init()) { return; }
I2cSetActiveFound(vl53l1x.getAddress(), "VL53L1X");
vl53l1x.setTimeout(500);
vl53l1x.setDistanceMode(VL53L1X::Long); // could be Short, Medium, Long
vl53l1x.setMeasurementTimingBudget(140000);
vl53l1x.startContinuous(50);
vl53l1x_sensors.ready = true;
}
#ifdef USE_WEBSERVER
const char HTTP_SNS_VL53L1X[] PROGMEM =
"{s}VL53L1X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // USE_WEBSERVER
void Vl53l1Every_250MSecond(void) {
// every 250 ms
uint16_t dist = vl53l1x.read();
if (!dist || dist > 4000) {
dist = 9999;
}
vl53l1x_sensors.distance = dist;
}
#ifdef USE_DOMOTICZ
void Vl53l1Every_Second(void) {
DomoticzSensor(DZ_ILLUMINANCE, vl53l1x_sensors.distance);
}
#endif // USE_DOMOTICZ
void Vl53l1Show(boolean json) {
if (json) {
#ifdef USE_DOMOTICZ
if (0 == tele_period) {
DomoticzSensor(DZ_ILLUMINANCE, vl53l1x_sensors.distance);
}
#endif // USE_DOMOTICZ
ResponseAppend_P(PSTR(",\"VL53L1X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l1x_sensors.distance);
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_VL53L1X, vl53l1x_sensors.distance);
#endif
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns77(byte function)
{
2020-09-29 10:08:03 +01:00
if (!I2cEnabled(XI2C_54)) { return false; }
Squashed commit of the following: commit 0917b430c3b76e26fad584ddacb1fc389e1b4c36 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 17:13:53 2020 +0200 Domoticz commit e878ae5ac4e2b72443598d699f76f1efbe90b5c2 Merge: 77957d70 46789ef4 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Tue Sep 1 13:24:37 2020 +0200 Merge pull request #118 from device111/vl53l1x VL53L1X correction commit 46789ef40b6b8a3fbf730ed69712e0790b876075 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:41:32 2020 +0200 Update support_features.ino commit 8f8720d37e5d81d6c483620a83936b2f5ffd9f43 Author: device111 <48546979+device111@users.noreply.github.com> Date: Sun Aug 30 11:36:24 2020 +0200 VL53L1X correction sorry, but i have killed all of my repos..:-( commit 77957d70435e99bb42b64b39acb7b7a176ecac79 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri Aug 28 13:54:25 2020 +0200 use registry commit d85954db359fb789c685fbf1ceb6d80fadc5132c Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:43:20 2020 +0200 No DOMOTICZ commit e6d763f10b0d34420f908382442af21581358a84 Merge: 788e4681 6c5fdb4d Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Thu Aug 27 14:42:29 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 788e468145520f3832255d92bf50d0ee70c18e0c Merge: 51491df1 33f3f9ef Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:50:28 2020 +0200 Merge remote-tracking branch 'Tasmota/development' into vl53l1x commit 51491df1419fa50d1327565b61a40ca5f81a99d6 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed Aug 26 14:49:56 2020 +0200 Real 0x52 is 0x29 in Arduino 7 bit commit 00dad36b086b03a93dd02ffa28e5d097ba479f10 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon Aug 24 11:41:11 2020 +0200 1.01 commit 50e88038c3de477f6b657b3d3caa5e53992ca838 Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 20:04:47 2020 +0200 correct support_feature commit e5baabc41c1c016066a0ba9d3a8d8006cadd32ec Author: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sun Aug 23 19:53:15 2020 +0200 VL53L1X
2020-09-01 16:24:36 +01:00
bool result = false;
if (FUNC_INIT == function) {
Vl53l1Detect();
}
else if (vl53l1x_sensors.ready) {
switch (function) {
case FUNC_EVERY_250_MSECOND:
Vl53l1Every_250MSecond();
break;
#ifdef USE_DOMOTICZ
case FUNC_EVERY_SECOND:
Vl53l1Every_Second();
break;
#endif // USE_DOMOTICZ
case FUNC_JSON_APPEND:
Vl53l1Show(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
Vl53l1Show(0);
break;
#endif // USE_WEBSERVER
}
}
return result;
}
#endif // USE_VL53L1X
#endif // USE_I2C