Merge branch 'development' into gesture_structure

This commit is contained in:
Mickael Gaillard 2020-04-24 23:02:40 +02:00 committed by GitHub
commit 3fbd454600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 102 additions and 54 deletions

View File

@ -6,6 +6,7 @@
- [ ] The pull request is done against the latest dev branch - [ ] The pull request is done against the latest dev branch
- [ ] Only relevant files were touched - [ ] Only relevant files were touched
- [ ] Only one feature/fix was added per PR. - [ ] 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** - [ ] 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). - [ ] I accept the [CLA](https://github.com/arendst/Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla).

View File

@ -107,14 +107,14 @@ build_flags = -DUSE_IR_REMOTE_FULL
-DDECODE_PRONTO=false -DSEND_PRONTO=false -DDECODE_PRONTO=false -DSEND_PRONTO=false
[core_active] [core_active]
platform = ${tasmota_core_stage.platform} platform = ${tasmota_core.platform}
platform_packages = ${tasmota_core_stage.platform_packages} platform_packages = ${tasmota_core.platform_packages}
build_flags = ${tasmota_core_stage.build_flags} build_flags = ${tasmota_core.build_flags}
[tasmota_core_stage] [tasmota_core]
; *** Esp8266 core for Arduino version stable beta ; *** Esp8266 Arduino core version Tasmota
platform = espressif8266@2.4.0 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} build_flags = ${esp82xx_defaults.build_flags}
-DBEARSSL_SSL_BASIC -DBEARSSL_SSL_BASIC
; NONOSDK22x_190703 = 2.2.2-dev(38a443e) ; NONOSDK22x_190703 = 2.2.2-dev(38a443e)

View File

@ -132,7 +132,7 @@ build_flags = ${esp82xx_defaults.build_flags}
[tasmota_feature_stage] [tasmota_feature_stage]
; *** Esp8266 core for Arduino version Tasmota feature stage ; *** Esp8266 core for Arduino version Tasmota feature stage
platform = espressif8266@2.4.0 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} build_flags = ${esp82xx_defaults.build_flags}
-DBEARSSL_SSL_BASIC -DBEARSSL_SSL_BASIC
; NONOSDK221 ; NONOSDK221
@ -235,6 +235,7 @@ board_build.partitions = esp32_partition_app1984k_spiffs64k.csv
board_build.flash_mode = ${common.board_build.flash_mode} board_build.flash_mode = ${common.board_build.flash_mode}
board_build.f_cpu = ${common.board_build.f_cpu} board_build.f_cpu = ${common.board_build.f_cpu}
build_unflags = ${common.build_unflags} build_unflags = ${common.build_unflags}
-Wpointer-arith
monitor_speed = ${common.monitor_speed} monitor_speed = ${common.monitor_speed}
upload_port = ${common.upload_port} upload_port = ${common.upload_port}
upload_resetmethod = ${common.upload_resetmethod} upload_resetmethod = ${common.upload_resetmethod}

View File

@ -741,7 +741,7 @@ void SettingsDefaultSet2(void)
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
Settings.module = MODULE; Settings.module = MODULE;
ModuleDefault(WEMOS); 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_FRIENDLYNAME1, FRIENDLY_NAME);
SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2"); SettingsUpdateText(SET_FRIENDLYNAME2, FRIENDLY_NAME"2");
SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3"); SettingsUpdateText(SET_FRIENDLYNAME3, FRIENDLY_NAME"3");
@ -1098,7 +1098,7 @@ void SettingsDelta(void)
Settings.switchmode[i] = SWITCH_MODE; 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 if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
Settings.my_gp.io[i] += 4; Settings.my_gp.io[i] += 4;
} }

View File

@ -1120,10 +1120,15 @@ String ModuleName(void)
void ModuleGpios(myio *gp) void ModuleGpios(myio *gp)
{ {
//#ifdef ESP8266
uint8_t *dest = (uint8_t *)gp; 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) { if (USER_MODULE == Settings.module) {
memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio)); memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio));
} else { } else {
@ -1138,7 +1143,7 @@ void ModuleGpios(myio *gp)
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio)); // AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
uint32_t j = 0; 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 (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
dest[j] = src[i]; dest[j] = src[i];
@ -1226,7 +1231,11 @@ bool ValidAdc(void)
return (ADC0_USER == template_adc0); return (ADC0_USER == template_adc0);
} }
//#ifdef ESP8266
bool GetUsedInModule(uint32_t val, uint8_t *arr) bool GetUsedInModule(uint32_t val, uint8_t *arr)
//#else
//bool GetUsedInModule(uint32_t val, uint16_t *arr)
//#endif
{ {
int offset = 0; int offset = 0;
@ -1307,7 +1316,7 @@ bool JsonTemplate(const char* dataBuf)
SettingsUpdateText(SET_TEMPLATE_NAME, name); SettingsUpdateText(SET_TEMPLATE_NAME, name);
} }
if (obj[D_JSON_GPIO].success()) { 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; Settings.user_template.gp.io[i] = obj[D_JSON_GPIO][i] | 0;
} }
} }
@ -1326,7 +1335,7 @@ bool JsonTemplate(const char* dataBuf)
void TemplateJson(void) void TemplateJson(void)
{ {
Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME)); 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("%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); ResponseAppend_P(PSTR("],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), Settings.user_template.flag, Settings.user_template_base +1);

View File

@ -1000,7 +1000,7 @@ void CmndModule(void)
Settings.module = XdrvMailbox.payload; Settings.module = XdrvMailbox.payload;
SetModuleType(); SetModuleType();
if (Settings.last_module != XdrvMailbox.payload) { 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; Settings.my_gp.io[i] = GPIO_NONE;
} }
} }
@ -1036,7 +1036,7 @@ void CmndModules(void)
void CmndGpio(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; myio cmodule;
ModuleGpios(&cmodule); ModuleGpios(&cmodule);
if (ValidGPIO(XdrvMailbox.index, cmodule.io[XdrvMailbox.index]) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < GPIO_SENSOR_END)) { 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 (midx == XdrvMailbox.payload) { present = true; }
} }
if (present) { 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)) { if (ValidGPIO(i, cmodule.io[i]) && (Settings.my_gp.io[i] == XdrvMailbox.payload)) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} }
@ -1057,7 +1057,7 @@ void CmndGpio(void)
} }
Response_P(PSTR("{")); Response_P(PSTR("{"));
bool jsflg = false; 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 (ValidGPIO(i, cmodule.io[i]) || ((GPIO_USER == XdrvMailbox.payload) && !FlashPin(i))) {
if (jsflg) { ResponseAppend_P(PSTR(",")); } if (jsflg) { ResponseAppend_P(PSTR(",")); }
jsflg = true; jsflg = true;
@ -1137,7 +1137,7 @@ void CmndTemplate(void)
} }
SettingsUpdateText(SET_TEMPLATE_NAME, "Merged"); SettingsUpdateText(SET_TEMPLATE_NAME, "Merged");
uint32_t j = 0; 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 (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
if (my_module.io[j] > GPIO_NONE) { if (my_module.io[j] > GPIO_NONE) {

View File

@ -339,7 +339,7 @@ void SetPowerOnState(void)
void SetLedPowerIdx(uint32_t led, uint32_t state) 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 ((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; led = 1;
} }
} }
@ -1354,7 +1354,7 @@ void GpioInit(void)
Settings.serial_config = TS_SERIAL_8N1; 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)) { 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 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; myio def_gp;
ModuleGpios(&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)) { 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 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++) { for (uint32_t i = 0; i < GPIO_MAX; i++) {
pin[i] = 99; 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]); mpin = ValidPin(i, my_module.io[i]);
DEBUG_CORE_LOG(PSTR("INI: gpio pin %d, mpin %d"), i, mpin); 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 // Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
// Doing it here solves relay toggles at restart. // 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]); mpin = ValidPin(i, my_module.io[i]);
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("INI: gpio pin %d, mpin %d"), i, mpin); // 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 if (((i < 6) || (i > 11)) && (0 == mpin)) { // Skip SPI flash interface

View File

@ -260,7 +260,7 @@ void setup(void)
Settings.rule_enabled = 0; // Disable all rules Settings.rule_enabled = 0; // Disable all rules
} }
if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET] +3) { // Restarted 5 times 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_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors
} }
Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors Settings.my_adc0 = ADC0_NONE; // Reset user defined ADC0 disabling sensors

View File

@ -1466,7 +1466,7 @@ void HandleTemplateConfiguration(void)
} }
WSContentSend_P(PSTR("}1")); // Field separator 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)) { if (!FlashPin(i)) {
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", cmodule.io[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); snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp);
uint32_t j = 0; 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 (6 == i) { j = 9; }
if (8 == i) { j = 12; } if (8 == i) { j = 12; }
snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j); snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j);
@ -1604,7 +1604,7 @@ void HandleModuleConfiguration(void)
WSContentStart_P(S_CONFIGURE_MODULE); WSContentStart_P(S_CONFIGURE_MODULE);
WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE); WSContentSend_P(HTTP_SCRIPT_MODULE_TEMPLATE);
WSContentSend_P(HTTP_SCRIPT_MODULE1, Settings.module); 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])) { if (ValidGPIO(i, cmodule.io[i])) {
WSContentSend_P(PSTR("sk(%d,%d);"), my_module.io[i], i); // g0 - g16 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); WSContentSend_P(HTTP_SCRIPT_MODULE2, Settings.my_adc0);
WSContentSendStyle(); WSContentSendStyle();
WSContentSend_P(HTTP_FORM_MODULE, AnyModuleName(MODULE).c_str()); 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])) { if (ValidGPIO(i, cmodule.io[i])) {
snprintf_P(stemp, 3, PINS_WEMOS +i*2); snprintf_P(stemp, 3, PINS_WEMOS +i*2);
#ifdef ESP8266 #ifdef ESP8266
@ -1652,7 +1652,7 @@ void ModuleSaveSettings(void)
myio cmodule; myio cmodule;
ModuleGpios(&cmodule); ModuleGpios(&cmodule);
String gpios = ""; 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) { if (Settings.last_module != new_module) {
Settings.my_gp.io[i] = GPIO_NONE; Settings.my_gp.io[i] = GPIO_NONE;
} else { } else {

View File

@ -569,7 +569,7 @@ void TuyaNormalPowerModePacketProcess(void)
uint8_t key1_gpio = Tuya.buffer[7]; uint8_t key1_gpio = Tuya.buffer[7];
bool key1_set = false; bool key1_set = false;
bool led1_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; if (Settings.my_gp.io[i] == GPIO_LED1) led1_set = true;
else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true; else if (Settings.my_gp.io[i] == GPIO_KEY1) key1_set = true;
} }

View File

@ -206,7 +206,7 @@ const char HTTP_APDS9960_SNS[] PROGMEM =
#define GWTIME_39_2MS 7 #define GWTIME_39_2MS 7
/* Default values */ /* Default values */
#define DEFAULT_ATIME 0xdb // 103ms = 0xdb #define DEFAULT_ATIME 0xdb // 103ms = 0xdb = 219
#define DEFAULT_WTIME 246 // 27ms #define DEFAULT_WTIME 246 // 27ms
#define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses #define DEFAULT_PROX_PPULSE 0x87 // 16us, 8 pulses
#define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses ---89 #define DEFAULT_GESTURE_PPULSE 0x89 // 16us, 10 pulses ---89
@ -243,12 +243,16 @@ enum {
DIR_RIGHT, DIR_RIGHT,
DIR_UP, DIR_UP,
DIR_DOWN, DIR_DOWN,
DIR_NEAR,
DIR_FAR,
DIR_ALL DIR_ALL
}; };
/* State definitions*/ /* State definitions*/
enum { enum {
APDS9960_NA_STATE, APDS9960_NA_STATE,
APDS9960_NEAR_STATE,
APDS9960_FAR_STATE,
APDS9960_ALL_STATE APDS9960_ALL_STATE
}; };
@ -276,9 +280,9 @@ typedef struct gesture_type
typedef struct color_data_type { typedef struct color_data_type {
uint16_t a; // measured ambient uint16_t a; // measured ambient
uint16_t r; uint16_t r; // Red
uint16_t g; uint16_t g; // Green
uint16_t b; uint16_t b; // Blue
uint8_t p; // proximity uint8_t p; // proximity
uint16_t cct; // calculated color temperature uint16_t cct; // calculated color temperature
uint16_t lux; // calculated illuminance - atm only from rgb uint16_t lux; // calculated illuminance - atm only from rgb
@ -393,6 +397,7 @@ uint8_t getProxIntLowThresh(void) {
/* Read value from PILT register */ /* Read value from PILT register */
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PILT); val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PILT);
return val; return val;
} }
@ -415,6 +420,7 @@ uint8_t getProxIntHighThresh(void) {
/* Read value from PIHT register */ /* Read value from PIHT register */
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PIHT); val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_PIHT);
return val; return val;
} }
@ -443,6 +449,7 @@ uint8_t getLEDDrive(void) {
/* Read value from CONTROL register */ /* Read value from CONTROL register */
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL); val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL);
/* Shift and mask out LED drive bits */ /* Shift and mask out LED drive bits */
val = (val >> 6) & 0b00000011; val = (val >> 6) & 0b00000011;
@ -492,6 +499,7 @@ uint8_t getProximityGain(void) {
/* Read value from CONTROL register */ /* Read value from CONTROL register */
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL); val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONTROL);
/* Shift and mask out PDRIVE bits */ /* Shift and mask out PDRIVE bits */
val = (val >> 2) & 0b00000011; val = (val >> 2) & 0b00000011;
@ -536,6 +544,17 @@ void setProximityGain(uint8_t drive) {
* *
* @return the value of the ALS gain. 0xFF on failure. * @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) * @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 */ /* Read value from CONFIG2 register */
val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONFIG2); val = I2cRead8(APDS9960_I2C_ADDR, APDS9960_CONFIG2);
/* Set bits in register to given value */ /* Set bits in register to given value */
boost &= 0b00000011; boost &= 0b00000011;
boost = boost << 4; boost = boost << 4;
@ -1195,6 +1215,8 @@ void setGestureMode(uint8_t mode) {
bool APDS9960_init(void) { bool APDS9960_init(void) {
setMode(ALL, OFF);
/* Set default values for ambient light and proximity registers */ /* Set default values for ambient light and proximity registers */
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_ATIME, DEFAULT_ATIME); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_ATIME, DEFAULT_ATIME);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, DEFAULT_WTIME); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, DEFAULT_WTIME);
@ -1298,9 +1320,9 @@ void setMode(uint8_t mode, uint8_t enable) {
void enableLightSensor(void) { void enableLightSensor(void) {
/* Set default gain, interrupts, enable power, and enable sensor */ /* Set default gain, interrupts, enable power, and enable sensor */
setAmbientLightGain(DEFAULT_AGAIN); setAmbientLightGain(DEFAULT_AGAIN);
setAmbientLightIntEnable(0); setAmbientLightIntEnable(OFF);
enablePower(); enablePower();
setMode(AMBIENT_LIGHT, 1); setMode(AMBIENT_LIGHT, ON);
} }
/** /**
@ -1308,8 +1330,8 @@ void enableLightSensor(void) {
* *
*/ */
void disableLightSensor(void) { void disableLightSensor(void) {
setAmbientLightIntEnable(0); setAmbientLightIntEnable(OFF);
setMode(AMBIENT_LIGHT, 0); setMode(AMBIENT_LIGHT, OFF);
} }
/** /**
@ -1321,9 +1343,9 @@ void enableProximitySensor(void) {
/* Set default gain, LED, interrupts, enable power, and enable sensor */ /* Set default gain, LED, interrupts, enable power, and enable sensor */
setProximityGain(DEFAULT_PGAIN); setProximityGain(DEFAULT_PGAIN);
setLEDDrive(DEFAULT_LDRIVE); setLEDDrive(DEFAULT_LDRIVE);
setProximityIntEnable(0); setProximityIntEnable(OFF);
enablePower(); enablePower();
setMode(PROXIMITY, 1); setMode(PROXIMITY, ON);
} }
/** /**
@ -1331,8 +1353,8 @@ void enableProximitySensor(void) {
* *
*/ */
void disableProximitySensor(void) { void disableProximitySensor(void) {
setProximityIntEnable(0); setProximityIntEnable(OFF);
setMode(PROXIMITY, 0); setMode(PROXIMITY, OFF);
} }
/** /**
@ -1352,12 +1374,12 @@ void enableGestureSensor(void) {
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, 0xFF); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_WTIME, 0xFF);
I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE); I2cWrite8(APDS9960_I2C_ADDR, APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE);
setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 ---- 200 from Adafruit setLEDBoost(LED_BOOST_100); // tip from jonn26 - 100 for 300 ---- 200 from Adafruit
setGestureIntEnable(0); setGestureIntEnable(OFF);
setGestureMode(1); setGestureMode(ON);
enablePower(); enablePower();
setMode(WAIT, 1); setMode(WAIT, ON);
setMode(PROXIMITY, 1); setMode(PROXIMITY, ON);
setMode(GESTURE, 1); setMode(GESTURE, ON);
} }
/** /**
@ -1366,9 +1388,9 @@ void enableGestureSensor(void) {
*/ */
void disableGestureSensor(void) { void disableGestureSensor(void) {
resetGestureParameters(); resetGestureParameters();
setGestureIntEnable(0); setGestureIntEnable(OFF);
setGestureMode(0); setGestureMode(OFF);
setMode(GESTURE, 0); setMode(GESTURE, OFF);
} }
/** /**
@ -1416,6 +1438,7 @@ int16_t readGesture(void) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Sensor overload")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("Sensor overload"));
} }
gesture_loop_counter += 1; gesture_loop_counter += 1;
/* Wait some time to collect next batch of FIFO data */ /* Wait some time to collect next batch of FIFO data */
delay(FIFO_PAUSE_TIME); delay(FIFO_PAUSE_TIME);
@ -1427,6 +1450,10 @@ int16_t readGesture(void) {
/* Read the current FIFO level */ /* Read the current FIFO level */
fifo_level = I2cRead8(APDS9960_I2C_ADDR, APDS9960_GFLVL); 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 there's stuff in the FIFO, read it into our data block */
if (fifo_level > 0) { if (fifo_level > 0) {
bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4)); bytes_read = wireReadDataBlock(APDS9960_GFIFO_U, (uint8_t*)fifo_data, (fifo_level * 4));
@ -1434,6 +1461,16 @@ int16_t readGesture(void) {
return APDS9960_ERROR; 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 at least 1 set of data, sort the data into U/D/L/R */
if (bytes_read >= 4) { if (bytes_read >= 4) {
for (i = 0; i < bytes_read; i += 4) { for (i = 0; i < bytes_read; i += 4) {
@ -1472,7 +1509,7 @@ int16_t readGesture(void) {
* *
*/ */
void enablePower(void) { void enablePower(void) {
setMode(POWER, 1); setMode(POWER, ON);
} }
/** /**
@ -1480,7 +1517,7 @@ void enablePower(void) {
* *
*/ */
void disablePower(void) { void disablePower(void) {
setMode(POWER, 0); setMode(POWER, OFF);
} }