mirror of https://github.com/arendst/Tasmota.git
Add support for APDS9960 proximity sensor
6.0.0a * Add support for APDS9960 proximity sensor (#3051)
This commit is contained in:
parent
04e1416eaa
commit
b1258477a5
|
@ -1,4 +1,5 @@
|
||||||
/* 6.0.0a
|
/* 6.0.0a
|
||||||
|
* Add support for APDS9960 proximity sensor (#3051)
|
||||||
* Add increment and decrement value to command Counter (#2838)
|
* Add increment and decrement value to command Counter (#2838)
|
||||||
* Add option 0 to command Timers disarming all timers (#2962)
|
* Add option 0 to command Timers disarming all timers (#2962)
|
||||||
* Add time in minutes to rule Time#Initialized, Time#set and Time#Minute (#2669)
|
* Add time in minutes to rule Time#Initialized, Time#set and Time#Minute (#2669)
|
||||||
|
|
|
@ -276,6 +276,7 @@
|
||||||
// #define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
|
// #define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
|
||||||
// #define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
// #define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
|
||||||
#define MGS_SENSOR_ADDR 0x04 // Default Mutichannel Gas sensor i2c address
|
#define MGS_SENSOR_ADDR 0x04 // Default Mutichannel Gas sensor i2c address
|
||||||
|
// #define USE_APDS9960 // Add I2C code for APDS9960 Proximity Sensor. Disables SHT and VEML6070 (+4k7 code)
|
||||||
#endif // USE_I2C
|
#endif // USE_I2C
|
||||||
|
|
||||||
// -- SPI sensors ---------------------------------
|
// -- SPI sensors ---------------------------------
|
||||||
|
|
|
@ -1,52 +1,52 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2017 Shawn Hymel/Sparkfun and Theo Arends. All rights reserved.
|
xdrv_13_apds9960.ino - Support for I2C APDS9960 Proximity Sensor for Sonoff-Tasmota
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Copyright (C) 2018 Shawn Hymel/Sparkfun and Theo Arends
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright notice,
|
Redistribution and use in source and binary forms, with or without
|
||||||
this list of conditions and the following disclaimer.
|
modification, are permitted provided that the following conditions are met:
|
||||||
- Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
- Redistributions of source code must retain the above copyright notice,
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
this list of conditions and the following disclaimer.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
- Redistributions in binary form must reproduce the above copyright notice,
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
this list of conditions and the following disclaimer in the documentation
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
and/or other materials provided with the distribution.
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define USE_APDS9960 // uncomment to enable the sensor
|
|
||||||
// !!!!!! turn off conflicting drivers !!!!
|
|
||||||
#if defined(USE_SHT) || defined(USE_VEML6070)
|
|
||||||
#warning I will turn off conflicting drivers (SHT and VEML6070) !!!
|
|
||||||
#undef USE_SHT // SHT-Driver blocks gesture sensor
|
|
||||||
#undef USE_VEML6070 // address conflict on the I2C-bus
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_I2C
|
#ifdef USE_I2C
|
||||||
#ifdef USE_APDS9960
|
#ifdef USE_APDS9960
|
||||||
|
|
||||||
enum GestureCommands {
|
|
||||||
CMND_GESTURE };
|
|
||||||
|
|
||||||
const char kGestureCommands[] PROGMEM =
|
|
||||||
"Gesture" ;
|
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* APDS9960
|
* APDS9960 - Digital Proximity Ambient Light RGB and Gesture Sensor
|
||||||
*
|
*
|
||||||
* Source: Shawn Hymel (SparkFun Electronics)
|
* Source: Shawn Hymel (SparkFun Electronics)
|
||||||
* Adaption for TASMOTA: Christian Baars
|
* Adaption for TASMOTA: Christian Baars
|
||||||
|
*
|
||||||
|
* I2C Address: 0x39
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(USE_SHT) || defined(USE_VEML6070)
|
||||||
|
#warning **** Turned off conflicting drivers SHT and VEML6070 ****
|
||||||
|
#ifdef USE_SHT
|
||||||
|
#undef USE_SHT // SHT-Driver blocks gesture sensor
|
||||||
|
#endif
|
||||||
|
#ifdef USE_VEML6070
|
||||||
|
#undef USE_VEML6070 // address conflict on the I2C-bus
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define APDS9960_I2C_ADDR 0x39
|
#define APDS9960_I2C_ADDR 0x39
|
||||||
|
|
||||||
#define APDS9960_CHIPID_1 0xAB
|
#define APDS9960_CHIPID_1 0xAB
|
||||||
|
@ -57,7 +57,11 @@ const char kGestureCommands[] PROGMEM =
|
||||||
#define GESTURE_SENSITIVITY_1 50
|
#define GESTURE_SENSITIVITY_1 50
|
||||||
#define GESTURE_SENSITIVITY_2 20
|
#define GESTURE_SENSITIVITY_2 20
|
||||||
|
|
||||||
|
enum GestureCommands {
|
||||||
|
CMND_GESTURE };
|
||||||
|
|
||||||
|
const char kGestureCommands[] PROGMEM =
|
||||||
|
"Gesture" ;
|
||||||
|
|
||||||
uint8_t APDS9960addr;
|
uint8_t APDS9960addr;
|
||||||
uint8_t APDS9960type = 0;
|
uint8_t APDS9960type = 0;
|
||||||
|
@ -65,7 +69,6 @@ char APDS9960stype[7];
|
||||||
char currentGesture[6];
|
char currentGesture[6];
|
||||||
bool gesture_mode = true;
|
bool gesture_mode = true;
|
||||||
|
|
||||||
|
|
||||||
volatile uint8_t recovery_loop_counter = 0; //count number of stateloops to switch the sensor off, if needed
|
volatile uint8_t recovery_loop_counter = 0; //count number of stateloops to switch the sensor off, if needed
|
||||||
#define APDS9960_LONG_RECOVERY 50 //long pause after sensor overload in loops
|
#define APDS9960_LONG_RECOVERY 50 //long pause after sensor overload in loops
|
||||||
#define APDS9960_MAX_GESTURE_CYCLES 50 //how many FIFO-reads are allowed to prevent crash
|
#define APDS9960_MAX_GESTURE_CYCLES 50 //how many FIFO-reads are allowed to prevent crash
|
||||||
|
@ -80,14 +83,12 @@ const char HTTP_APDS_9960_SNS[] PROGMEM = "%s"
|
||||||
"{s}" "Proximity" "{m}%s{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
"{s}" "Proximity" "{m}%s{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* APDS9960
|
* APDS9960
|
||||||
*
|
*
|
||||||
* Programmer : APDS9960 Datasheet and Sparkfun
|
* Programmer : APDS9960 Datasheet and Sparkfun
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/* Misc parameters */
|
/* Misc parameters */
|
||||||
#define FIFO_PAUSE_TIME 30 // Wait period (ms) between FIFO reads
|
#define FIFO_PAUSE_TIME 30 // Wait period (ms) between FIFO reads
|
||||||
|
|
||||||
|
@ -253,7 +254,6 @@ enum {
|
||||||
APDS9960_ALL_STATE
|
APDS9960_ALL_STATE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Container for gesture data */
|
/* Container for gesture data */
|
||||||
typedef struct gesture_data_type {
|
typedef struct gesture_data_type {
|
||||||
uint8_t u_data[32];
|
uint8_t u_data[32];
|
||||||
|
@ -275,8 +275,6 @@ typedef struct gesture_data_type {
|
||||||
int16_t gesture_state_ = 0;
|
int16_t gesture_state_ = 0;
|
||||||
int16_t gesture_motion_ = DIR_NONE;
|
int16_t gesture_motion_ = DIR_NONE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Helper functions
|
* Helper functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
Loading…
Reference in New Issue