mirror of https://github.com/arendst/Tasmota.git
Merge branch 'development' into gesture_structure
This commit is contained in:
commit
3fbd454600
|
@ -6,6 +6,7 @@
|
|||
- [ ] The pull request is done against the latest dev branch
|
||||
- [ ] Only relevant files were touched
|
||||
- [ ] Only one feature/fix was added per PR.
|
||||
- [ ] The code change is tested and works on core Tasmota_core_stage
|
||||
- [ ] The code change is tested and works on core Tasmota_core
|
||||
- [ ] The code change is tested and works on core ESP32
|
||||
- [ ] The code change pass travis tests. **Your PR cannot be merged unless tests pass**
|
||||
- [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla).
|
||||
|
|
|
@ -107,14 +107,14 @@ build_flags = -DUSE_IR_REMOTE_FULL
|
|||
-DDECODE_PRONTO=false -DSEND_PRONTO=false
|
||||
|
||||
[core_active]
|
||||
platform = ${tasmota_core_stage.platform}
|
||||
platform_packages = ${tasmota_core_stage.platform_packages}
|
||||
build_flags = ${tasmota_core_stage.build_flags}
|
||||
platform = ${tasmota_core.platform}
|
||||
platform_packages = ${tasmota_core.platform_packages}
|
||||
build_flags = ${tasmota_core.build_flags}
|
||||
|
||||
[tasmota_core_stage]
|
||||
; *** Esp8266 core for Arduino version stable beta
|
||||
[tasmota_core]
|
||||
; *** Esp8266 Arduino core version Tasmota
|
||||
platform = espressif8266@2.4.0
|
||||
platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#372a3ec297dfe8501bed1ec4552244695b5e8ced
|
||||
platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#36e047e908cfa6eafaaf824988070b49f2c2ff2a
|
||||
build_flags = ${esp82xx_defaults.build_flags}
|
||||
-DBEARSSL_SSL_BASIC
|
||||
; NONOSDK22x_190703 = 2.2.2-dev(38a443e)
|
||||
|
|
|
@ -132,7 +132,7 @@ build_flags = ${esp82xx_defaults.build_flags}
|
|||
[tasmota_feature_stage]
|
||||
; *** Esp8266 core for Arduino version Tasmota feature stage
|
||||
platform = espressif8266@2.4.0
|
||||
platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#d600cc7fa6c3fc5c31ed903ec12fd2e2da2c3678
|
||||
platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git#36e047e908cfa6eafaaf824988070b49f2c2ff2a
|
||||
build_flags = ${esp82xx_defaults.build_flags}
|
||||
-DBEARSSL_SSL_BASIC
|
||||
; NONOSDK221
|
||||
|
@ -235,6 +235,7 @@ board_build.partitions = esp32_partition_app1984k_spiffs64k.csv
|
|||
board_build.flash_mode = ${common.board_build.flash_mode}
|
||||
board_build.f_cpu = ${common.board_build.f_cpu}
|
||||
build_unflags = ${common.build_unflags}
|
||||
-Wpointer-arith
|
||||
monitor_speed = ${common.monitor_speed}
|
||||
upload_port = ${common.upload_port}
|
||||
upload_resetmethod = ${common.upload_resetmethod}
|
||||
|
|
|
@ -741,7 +741,7 @@ void SettingsDefaultSet2(void)
|
|||
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
|
||||
Settings.module = MODULE;
|
||||
ModuleDefault(WEMOS);
|
||||
// for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
|
||||
// for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
|
||||
SettingsUpdateText(SET_FRIENDLYNAME1, FRIENDLY_NAME);
|
||||
SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2");
|
||||
SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3");
|
||||
|
@ -1098,7 +1098,7 @@ void SettingsDelta(void)
|
|||
Settings.switchmode[i] = SWITCH_MODE;
|
||||
}
|
||||
}
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
|
||||
Settings.my_gp.io[i] += 4;
|
||||
}
|
||||
|
|
|
@ -1120,10 +1120,15 @@ String ModuleName(void)
|
|||
|
||||
void ModuleGpios(myio *gp)
|
||||
{
|
||||
//#ifdef ESP8266
|
||||
uint8_t *dest = (uint8_t *)gp;
|
||||
memset(dest, GPIO_NONE, sizeof(myio));
|
||||
uint8_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])];
|
||||
//#else
|
||||
// uint16_t *dest = (uint16_t *)gp;
|
||||
// uint16_t src[sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0])];
|
||||
//#endif
|
||||
|
||||
uint8_t src[sizeof(mycfgio)];
|
||||
memset(dest, GPIO_NONE, sizeof(myio));
|
||||
if (USER_MODULE == Settings.module) {
|
||||
memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio));
|
||||
} else {
|
||||
|
@ -1138,7 +1143,7 @@ void ModuleGpios(myio *gp)
|
|||
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
|
||||
|
||||
uint32_t j = 0;
|
||||
for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
if (6 == i) { j = 9; }
|
||||
if (8 == i) { j = 12; }
|
||||
dest[j] = src[i];
|
||||
|
@ -1226,7 +1231,11 @@ bool ValidAdc(void)
|
|||
return (ADC0_USER == template_adc0);
|
||||
}
|
||||
|
||||
//#ifdef ESP8266
|
||||
bool GetUsedInModule(uint32_t val, uint8_t *arr)
|
||||
//#else
|
||||
//bool GetUsedInModule(uint32_t val, uint16_t *arr)
|
||||
//#endif
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
|
@ -1307,7 +1316,7 @@ bool JsonTemplate(const char* dataBuf)
|
|||
SettingsUpdateText(SET_TEMPLATE_NAME, name);
|
||||
}
|
||||
if (obj[D_JSON_GPIO].success()) {
|
||||
for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
|
||||
}
|
||||
}
|
||||
|
@ -1326,7 +1335,7 @@ bool JsonTemplate(const char* dataBuf)
|
|||
void TemplateJson(void)
|
||||
{
|
||||
Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME));
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
ResponseAppend_P(PSTR("%s%d"), (i>0)?",":"", Settings.user_template.gp.io[i]);
|
||||
}
|
||||
ResponseAppend_P(PSTR("],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), Settings.user_template.flag, Settings.user_template_base +1);
|
||||
|
|
|
@ -1000,7 +1000,7 @@ void CmndModule(void)
|
|||
Settings.module = XdrvMailbox.payload;
|
||||
SetModuleType();
|
||||
if (Settings.last_module != XdrvMailbox.payload) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
Settings.my_gp.io[i] = GPIO_NONE;
|
||||
}
|
||||
}
|
||||
|
@ -1036,7 +1036,7 @@ void CmndModules(void)
|
|||
|
||||
void CmndGpio(void)
|
||||
{
|
||||
if (XdrvMailbox.index < sizeof(Settings.my_gp)) {
|
||||
if (XdrvMailbox.index < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0])) {
|
||||
myio cmodule;
|
||||
ModuleGpios(&cmodule);
|
||||
if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) {
|
||||
|
@ -1046,7 +1046,7 @@ void CmndGpio(void)
|
|||
if (midx == XdrvMailbox.payload) { present = true; }
|
||||
}
|
||||
if (present) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) {
|
||||
Settings.my_gp.io[i] = GPIO_NONE;
|
||||
}
|
||||
|
@ -1057,7 +1057,7 @@ void CmndGpio(void)
|
|||
}
|
||||
Response_P(PSTR("{"));
|
||||
bool jsflg = false;
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
if (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) {
|
||||
if (jsflg) { ResponseAppend_P(PSTR(",")); }
|
||||
jsflg = true;
|
||||
|
@ -1137,7 +1137,7 @@ void CmndTemplate(void)
|
|||
}
|
||||
SettingsUpdateText(SET_TEMPLATE_NAME, "Merged");
|
||||
uint32_t j = 0;
|
||||
for (uint32_t i = 0; i < sizeof(mycfgio); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
if (6 == i) { j = 9; }
|
||||
if (8 == i) { j = 12; }
|
||||
if (my_module.io[j] > GPIO_NONE) {
|
||||
|
|
|
@ -339,7 +339,7 @@ void SetPowerOnState(void)
|
|||
void SetLedPowerIdx(uint32_t led, uint32_t state)
|
||||
{
|
||||
if ((99 == pin[GPIO_LEDLNK]) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present
|
||||
if (pin[GPIO_LED2] < 99) {
|
||||
if (pin[GPIO_LED1 +1] < 99) {
|
||||
led = 1;
|
||||
}
|
||||
}
|
||||
|
@ -1354,7 +1354,7 @@ void GpioInit(void)
|
|||
Settings.serial_config = TS_SERIAL_8N1;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
if ((Settings.user_template.gp.io[i] >= GPIO_SENSOR_END) && (Settings.user_template.gp.io[i] < GPIO_USER)) {
|
||||
Settings.user_template.gp.io[i] = GPIO_USER; // Fix not supported sensor ids in template
|
||||
}
|
||||
|
@ -1362,7 +1362,7 @@ void GpioInit(void)
|
|||
|
||||
myio def_gp;
|
||||
ModuleGpios(&def_gp);
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
if ((Settings.my_gp.io[i] >= GPIO_SENSOR_END) && (Settings.my_gp.io[i] < GPIO_USER)) {
|
||||
Settings.my_gp.io[i] = GPIO_NONE; // Fix not supported sensor ids in module
|
||||
}
|
||||
|
@ -1388,7 +1388,7 @@ void GpioInit(void)
|
|||
for (uint32_t i = 0; i < GPIO_MAX; i++) {
|
||||
pin[i] = 99;
|
||||
}
|
||||
for (uint32_t i = 0; i < sizeof(my_module.io); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) {
|
||||
mpin = ValidPin(i, my_module.io[i]);
|
||||
|
||||
DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
|
||||
|
@ -1465,7 +1465,7 @@ void GpioInit(void)
|
|||
|
||||
// Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
|
||||
// Doing it here solves relay toggles at restart.
|
||||
for (uint32_t i = 0; i < sizeof(my_module.io); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(my_module.io)/sizeof(my_module.io[0]); i++) {
|
||||
mpin = ValidPin(i, my_module.io[i]);
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin);
|
||||
if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface
|
||||
|
|
|
@ -260,7 +260,7 @@ void setup(void)
|
|||
Settings.rule_enabled = 0; // Disable all rules
|
||||
}
|
||||
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
|
||||
}
|
||||
Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors
|
||||
|
|
|
@ -1466,7 +1466,7 @@ void HandleTemplateConfiguration(void)
|
|||
}
|
||||
WSContentSend_P(PSTR("}1")); // Field separator
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(cmodule); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
|
||||
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) { // 17,148,29,149,7,255,255,255,138,255,139,255,255
|
||||
if (!FlashPin(i)) {
|
||||
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[i]);
|
||||
}
|
||||
|
@ -1518,7 +1518,7 @@ void TemplateSaveSettings(void)
|
|||
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
|
||||
|
||||
uint32_t j = 0;
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.user_template.gp.io)/sizeof(Settings.user_template.gp.io[0]); i++) {
|
||||
if (6 == i) { j = 9; }
|
||||
if (8 == i) { j = 12; }
|
||||
snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j);
|
||||
|
@ -1604,7 +1604,7 @@ void HandleModuleConfiguration(void)
|
|||
WSContentStart_P(S_CONFIGURE_MODULE);
|
||||
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
|
||||
WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module);
|
||||
for (uint32_t i = 0; i < sizeof(cmodule); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) {
|
||||
if (ValidGPIO(i, cmodule.io[i])) {
|
||||
WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16
|
||||
}
|
||||
|
@ -1612,7 +1612,7 @@ void HandleModuleConfiguration(void)
|
|||
WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0);
|
||||
WSContentSendStyle();
|
||||
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str());
|
||||
for (uint32_t i = 0; i < sizeof(cmodule); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) {
|
||||
if (ValidGPIO(i, cmodule.io[i])) {
|
||||
snprintf_P(stemp, 3, PINS_WEMOS +i*2);
|
||||
#ifdef ESP8266
|
||||
|
@ -1652,7 +1652,7 @@ void ModuleSaveSettings(void)
|
|||
myio cmodule;
|
||||
ModuleGpios(&cmodule);
|
||||
String gpios = "";
|
||||
for (uint32_t i = 0; i < sizeof(cmodule); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(cmodule.io)/sizeof(cmodule.io[0]); i++) {
|
||||
if (Settings.last_module != new_module) {
|
||||
Settings.my_gp.io[i] = GPIO_NONE;
|
||||
} else {
|
||||
|
|
|
@ -569,7 +569,7 @@ void TuyaNormalPowerModePacketProcess(void)
|
|||
uint8_t key1_gpio = Tuya.buffer[7];
|
||||
bool key1_set = false;
|
||||
bool led1_set = false;
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||
for (uint32_t i = 0; i < sizeof(Settings.my_gp.io)/sizeof(Settings.my_gp.io[0]); i++) {
|
||||
if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true;
|
||||
else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true;
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ const char HTTP_APDS9960_SNS[] PROGMEM =
|
|||
#define GWTIME_39_2MS 7
|
||||
|
||||
/* Default values */
|
||||
#define DEFAULT_ATIME 0xdb // 103ms = 0xdb
|
||||
#define DEFAULT_ATIME 0xdb // 103ms = 0xdb = 219
|
||||
#define DEFAULT_WTIME 246 // 27ms
|
||||
#define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses
|
||||
#define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses ---89
|
||||
|
@ -243,12 +243,16 @@ enum {
|
|||
DIR_RIGHT,
|
||||
DIR_UP,
|
||||
DIR_DOWN,
|
||||
DIR_NEAR,
|
||||
DIR_FAR,
|
||||
DIR_ALL
|
||||
};
|
||||
|
||||
/* State definitions*/
|
||||
enum {
|
||||
APDS9960_NA_STATE,
|
||||
APDS9960_NEAR_STATE,
|
||||
APDS9960_FAR_STATE,
|
||||
APDS9960_ALL_STATE
|
||||
};
|
||||
|
||||
|
@ -276,9 +280,9 @@ typedef struct gesture_type
|
|||
|
||||
typedef struct color_data_type {
|
||||
uint16_t a; // measured ambient
|
||||
uint16_t r;
|
||||
uint16_t g;
|
||||
uint16_t b;
|
||||
uint16_t r; // Red
|
||||
uint16_t g; // Green
|
||||
uint16_t b; // Blue
|
||||
uint8_t p; // proximity
|
||||
uint16_t cct; // calculated color temperature
|
||||
uint16_t lux; // calculated illuminance - atm only from rgb
|
||||
|
@ -393,6 +397,7 @@ uint8_t getProxIntLowThresh(void) {
|
|||
|
||||
/* Read value from PILT register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PILT);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -415,6 +420,7 @@ uint8_t getProxIntHighThresh(void) {
|
|||
|
||||
/* Read value from PIHT register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PIHT);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -443,6 +449,7 @@ uint8_t getLEDDrive(void) {
|
|||
|
||||
/* Read value from CONTROL register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL);
|
||||
|
||||
/* Shift and mask out LED drive bits */
|
||||
val = (val >> 6) & 0b00000011;
|
||||
|
||||
|
@ -492,6 +499,7 @@ uint8_t getProximityGain(void) {
|
|||
|
||||
/* Read value from CONTROL register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL);
|
||||
|
||||
/* Shift and mask out PDRIVE bits */
|
||||
val = (val >> 2) & 0b00000011;
|
||||
|
||||
|
@ -536,6 +544,17 @@ void setProximityGain(uint8_t drive) {
|
|||
*
|
||||
* @return the value of the ALS gain. 0xFF on failure.
|
||||
*/
|
||||
uint8_t getAmbientLightGain() {
|
||||
uint8_t val;
|
||||
|
||||
/* Read value from CONTROL register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL);
|
||||
|
||||
/* Shift and mask out ADRIVE bits */
|
||||
val &= 0b00000011;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the receiver gain for the ambient light sensor (ALS)
|
||||
|
@ -602,6 +621,7 @@ void setLEDBoost(uint8_t boost) {
|
|||
|
||||
/* Read value from CONFIG2 register */
|
||||
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONFIG2);
|
||||
|
||||
/* Set bits in register to given value */
|
||||
boost &= 0b00000011;
|
||||
boost = boost << 4;
|
||||
|
@ -1195,6 +1215,8 @@ void setGestureMode(uint8_t mode) {
|
|||
|
||||
|
||||
bool APDS9960_init(void) {
|
||||
setMode(ALL, OFF);
|
||||
|
||||
/* Set default values for ambient light and proximity registers */
|
||||
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_ATIME, DEFAULT_ATIME);
|
||||
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, DEFAULT_WTIME);
|
||||
|
@ -1298,9 +1320,9 @@ void setMode(uint8_t mode, uint8_t enable) {
|
|||
void enableLightSensor(void) {
|
||||
/* Set default gain, interrupts, enable power, and enable sensor */
|
||||
setAmbientLightGain(DEFAULT_AGAIN);
|
||||
setAmbientLightIntEnable(0);
|
||||
setAmbientLightIntEnable(OFF);
|
||||
enablePower();
|
||||
setMode(AMBIENT_LIGHT, 1);
|
||||
setMode(AMBIENT_LIGHT, ON);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1308,8 +1330,8 @@ void enableLightSensor(void) {
|
|||
*
|
||||
*/
|
||||
void disableLightSensor(void) {
|
||||
setAmbientLightIntEnable(0);
|
||||
setMode(AMBIENT_LIGHT, 0);
|
||||
setAmbientLightIntEnable(OFF);
|
||||
setMode(AMBIENT_LIGHT, OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1321,9 +1343,9 @@ void enableProximitySensor(void) {
|
|||
/* Set default gain, LED, interrupts, enable power, and enable sensor */
|
||||
setProximityGain(DEFAULT_PGAIN);
|
||||
setLEDDrive(DEFAULT_LDRIVE);
|
||||
setProximityIntEnable(0);
|
||||
setProximityIntEnable(OFF);
|
||||
enablePower();
|
||||
setMode(PROXIMITY, 1);
|
||||
setMode(PROXIMITY, ON);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1331,8 +1353,8 @@ void enableProximitySensor(void) {
|
|||
*
|
||||
*/
|
||||
void disableProximitySensor(void) {
|
||||
setProximityIntEnable(0);
|
||||
setMode(PROXIMITY, 0);
|
||||
setProximityIntEnable(OFF);
|
||||
setMode(PROXIMITY, OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1352,12 +1374,12 @@ void enableGestureSensor(void) {
|
|||
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, 0xFF);
|
||||
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE);
|
||||
setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 ---- 200 from Adafruit
|
||||
setGestureIntEnable(0);
|
||||
setGestureMode(1);
|
||||
setGestureIntEnable(OFF);
|
||||
setGestureMode(ON);
|
||||
enablePower();
|
||||
setMode(WAIT, 1);
|
||||
setMode(PROXIMITY, 1);
|
||||
setMode(GESTURE, 1);
|
||||
setMode(WAIT, ON);
|
||||
setMode(PROXIMITY, ON);
|
||||
setMode(GESTURE, ON);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1366,9 +1388,9 @@ void enableGestureSensor(void) {
|
|||
*/
|
||||
void disableGestureSensor(void) {
|
||||
resetGestureParameters();
|
||||
setGestureIntEnable(0);
|
||||
setGestureMode(0);
|
||||
setMode(GESTURE, 0);
|
||||
setGestureIntEnable(OFF);
|
||||
setGestureMode(OFF);
|
||||
setMode(GESTURE, OFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1416,6 +1438,7 @@ int16_t readGesture(void) {
|
|||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Sensor overload"));
|
||||
}
|
||||
gesture_loop_counter += 1;
|
||||
|
||||
/* Wait some time to collect next batch of FIFO data */
|
||||
delay(FIFO_PAUSE_TIME);
|
||||
|
||||
|
@ -1427,6 +1450,10 @@ int16_t readGesture(void) {
|
|||
/* Read the current FIFO level */
|
||||
fifo_level = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GFLVL);
|
||||
|
||||
#ifdef USE_DEBUG_DRIVER
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: FIFO Level : %d"), fifo_level);
|
||||
#endif // USE_DEBUG_DRIVER
|
||||
|
||||
/* If there's stuff in the FIFO, read it into our data block */
|
||||
if (fifo_level > 0) {
|
||||
bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4));
|
||||
|
@ -1434,6 +1461,16 @@ int16_t readGesture(void) {
|
|||
return APDS9960_ERROR;
|
||||
}
|
||||
|
||||
#ifdef USE_DEBUG_DRIVER
|
||||
char output[(bytes_read * 2) + 1];
|
||||
char *ptr = &output[0];
|
||||
|
||||
for ( i = 0; i < bytes_read; i++ ) {
|
||||
ptr += sprintf(ptr, "%02X", fifo_data[i]);
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("DRV: FIFO Dump : %s"), output);
|
||||
#endif // USE_DEBUG_DRIVER
|
||||
|
||||
/* If at least 1 set of data, sort the data into U/D/L/R */
|
||||
if (bytes_read >= 4) {
|
||||
for (i = 0; i < bytes_read; i += 4) {
|
||||
|
@ -1472,7 +1509,7 @@ int16_t readGesture(void) {
|
|||
*
|
||||
*/
|
||||
void enablePower(void) {
|
||||
setMode(POWER, 1);
|
||||
setMode(POWER, ON);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1480,7 +1517,7 @@ void enablePower(void) {
|
|||
*
|
||||
*/
|
||||
void disablePower(void) {
|
||||
setMode(POWER, 0);
|
||||
setMode(POWER, OFF);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue