Merge branch 'mega' into feature/P128-neopixelbusfx-migrate-from-playground

This commit is contained in:
Ton Huisman
2022-01-21 22:47:15 +01:00
committed by GitHub
18 changed files with 313 additions and 108 deletions
+111 -3
View File
@@ -1,4 +1,4 @@
.. include:: ../Plugin/_plugin_substitutions_p06x.repl
.. include:: ../Plugin/_plugin_substitutions_p06x.repl
.. _P062_page:
|P062_typename|
@@ -21,18 +21,122 @@ Maintainer: |P062_maintainer|
Used libraries: |P062_usedlibraries|
Introduction
------------
The NXP MPR121 I2C touch controller is often used as a keypad to allow data entry without mechanical or dome switches. This plugin supports up to 12 inputs, with optional separate configuration and calibration.
When mounting the keypad behind a glass shield, for added electrical safety, the Panel sensitivity can be increased to still be able to detect touch.
Supported hardware
------------------
|P062_usedby|
.. image:: P062_Keypad.png
:alt: MPR121 based, 12 key, keypad
A keypad based on the MPR121 controller.
.. image:: P062_MPR121board.png
:alt: MPR121 board without touchpads
A board having the MPR121 controller. Here some external touch-pads should be connected.
(Images taken from Aliexpress website, random seller.)
Configuration
-------------
.. image:: P062_DeviceConfiguration.png
:alt: Device configuration
* **Name** A unique name should be entered here.
* **Enabled** The device can be disabled or enabled. When not enabled the device should not use any resources.
I2C Options
^^^^^^^^^^^^
* The available settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`
* **I2C Address**: The address the device is using. Depending on the board used, when available a SDO or ADD(R) pin, can be used to select the used address. If that address selection is not available, then an I2C multiplexer (in a matching ESPEasy build) can be used to use multiple sensors on a single ESPEasy unit.
.. list-table:: Addresses
:widths: 15 15 70
:header-rows: 1
* - ADDR to
- Address
-
* - GND
- 0x5A (90)
-
* - VCC
- 0x5B (91)
-
* - SDA
- 0x5C (92)
-
* - SCL
- 0x5D (93)
-
.. image:: P062_I2CAddressOptions.png
:alt: Address options
Device Settings
^^^^^^^^^^^^^^^
* **ScanCode** Select this option to get the 'scancode' for the key pressed, in range 1..12. If this is unchecked, the raw bitmap for the key pressed is returned (values: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048).
Sensitivity
^^^^^^^^^^^
* **Touch treshold (1..255)** The amount of 'touch' needed to register a touch. This is the global configuration value, see below for per-key configuration.
* **Release treshold (1..255)** The amount of 'touch' until a touch is no longer registered (released). This is the global configuration value, see below for per-key configuration.
* **Panel sensitivity** When having direct access to the keypad, the sensitivity should be set to Normal. When mounting the keypad behind a sheet of glass or another capacitive inert material, the sensitivity can be set to Extra sensitive, to accomodate for a glass sheet of 4-6 mm.
.. image:: P062_PanelSensitivityOptions.png
:alt: Panel sensitivity options.
When mounting the keypad behind a glass panel, this should be very tight, without any air gap, to avoid unreliable registration of touches.
Per key configuration
^^^^^^^^^^^^^^^^^^^^^
To have better control per touch key, for each key a separate Touch and Release treshold can be set. When either of the settings per object is 0 it is ignored, and the global setting is applied.
* **Enable Calibration** When the sensor is enabled, the calibration data per key (Current/Min/Max) can viewed, and depending on values the tresholds can be changed (user should experiment with settings to see what changes). By changing this option from No to Yes, the page will reload and show the calibration data, as collected by the sensor (the sensor does auto-calibration). When reverting to No, the page will reload again, without the calibration options visible.
.. image:: P062_ObjectCalibration.png
:alt: Object list with calibration data
* **Clear calibrationdata** This checkbox can be checked to clear the calibration data from the sensor, so it can restart the calibration process. This will be applied when the Submit button is used *or* the page is reloaded by changing the **Enable Calibration** option!. The initial setting is always unchecked, and is not stored.
Data Acquisition
^^^^^^^^^^^^^^^^
The Data Acquisition, Send to Controller and Interval settings are standard available configuration items. Send to Controller only when one or more Controllers are configured.
* **Interval** By default, Interval will be set to 0 sec (off). If a value > 0 is used, then every <Interval> seconds an event with the last value is generated.
Values
^^^^^^
The last touched key is available in ``ScanCode``.
.. Commands available
.. ^^^^^^^^^^^^^^^^^^
.. .. include:: P062_commands.repl
.. Events
.. ~~~~~~
Events
~~~~~~
When a key is touched, the new data is sent out as an event, using the format ``<TaskName>#<ValueName>``. This can be handled from the rules.
.. .. include:: P062_events.repl
@@ -42,6 +146,10 @@ Change log
.. versionchanged:: 2.0
...
|added| 2021-12-29 Panel sensitivity setting added.
|added| 2020-10 Tresholds per touchkey.
|added|
Major overhaul for 2.0 release.
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

@@ -31,11 +31,11 @@
.. |P062_status| replace:: :yellow:`TESTING`
.. |P062_github| replace:: P062_MPR121_KeyPad.ino
.. _P062_github: https://github.com/letscontrolit/ESPEasy/blob/mega/src/_P062_MPR121_KeyPad.ino
.. |P062_usedby| replace:: `.`
.. |P062_usedby| replace:: `NXP MPR121 I2C controller`
.. |P062_shortinfo| replace:: `.`
.. |P062_maintainer| replace:: `.`
.. |P062_compileinfo| replace:: `.`
.. |P062_usedlibraries| replace:: `.`
.. |P062_usedlibraries| replace:: `Adafruit_MPR121 (Local copy, with added extra sensitivity option)`
.. |P063_name| replace:: :cyan:`TTP229 Touch`
.. |P063_type| replace:: :cyan:`Keypad`
+14 -4
View File
@@ -19,10 +19,11 @@
Adafruit_MPR121::Adafruit_MPR121() {
}
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
boolean Adafruit_MPR121::begin(uint8_t i2caddr, uint8_t sensitivity) {
//Wire.begin(); called in ESPEasy framework
_i2caddr = i2caddr;
_sensitivity = sensitivity;
// soft reset
writeRegister(MPR121_SOFTRESET, 0x63);
@@ -56,8 +57,16 @@ boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
writeRegister(MPR121_FDLT, 0x00);
writeRegister(MPR121_DEBOUNCE, 0);
writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current
writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period
switch(_sensitivity) {
case MPR212_EXTRA_SENSITIVITY:
writeRegister(MPR121_CONFIG1, 0x20); // increased to 32uA charge current
writeRegister(MPR121_CONFIG2, 0x3A); // 0.5uS encoding, 18 samples, 4ms period
break;
default: // MPR212_NORMAL_SENSITIVITY
writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current
writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period
break;
}
// writeRegister(MPR121_AUTOCONFIG0, 0x8F);
@@ -94,7 +103,8 @@ uint16_t Adafruit_MPR121::filteredData(uint8_t t) {
}
uint16_t Adafruit_MPR121::baselineData(uint8_t t) {
if (t > 12) return 0;
if ((_sensitivity == MPR212_EXTRA_SENSITIVITY) && (t > 3)) return 0;
if (t > 12) return 0; // MPR212_NORMAL_SENSITIVITY
uint16_t bl = readRegister8(MPR121_BASELINE_0 + t);
return (bl << 2);
}
+6 -1
View File
@@ -66,13 +66,17 @@
#define MPR121_SOFTRESET 0x80
#define MPR212_NORMAL_SENSITIVITY 0
#define MPR212_EXTRA_SENSITIVITY 1
//.. thru to 0x1C/0x1D
class Adafruit_MPR121 {
public:
// Hardware I2C
Adafruit_MPR121(void);
boolean begin(uint8_t i2caddr = MPR121_I2CADDR_DEFAULT);
boolean begin(uint8_t i2caddr = MPR121_I2CADDR_DEFAULT,
uint8_t sensitivity = MPR212_NORMAL_SENSITIVITY);
uint16_t filteredData(uint8_t t);
uint16_t baselineData(uint8_t t);
@@ -88,6 +92,7 @@ class Adafruit_MPR121 {
private:
int8_t _i2caddr;
uint8_t _sensitivity;
};
#endif // ADAFRUIT_MPR121_H
+27 -16
View File
@@ -306,6 +306,8 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
addFormCheckBox(F("Add new received code to command lines"), F("p016_AddNewCode"), bAddNewCode);
bool bExecuteCmd = bitRead(PCONFIG_LONG(0), P016_BitExecuteCmd);
addFormCheckBox(F("Execute commands"), F("p016_ExecuteCmd"), bExecuteCmd);
bool bAcceptUnknownType = bitRead(PCONFIG_LONG(0), P016_BitAcceptUnknownType);
addFormCheckBox(F("Accept DecodeType UNKNOWN"), F("p016_AcceptUnknownType"), bAcceptUnknownType);
addFormNumericBox(F("Inhibit time for the same command [ms]"),
F("p016_cmdinhibit"),
P016_CMDINHIBIT,
@@ -446,6 +448,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
uint32_t lSettings = 0;
bitWrite(lSettings, P016_BitAddNewCode, isFormItemChecked(F("p016_AddNewCode")));
bitWrite(lSettings, P016_BitExecuteCmd, isFormItemChecked(F("p016_ExecuteCmd")));
bitWrite(lSettings, P016_BitAcceptUnknownType, isFormItemChecked(F("p016_AcceptUnknownType")));
bEnableIRcodeAdding = true;
PCONFIG_LONG(0) = lSettings;
@@ -577,7 +580,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
output.reserve(100); // Length of expected string, needed for strings > 11 chars
// Display the basic output of what we found.
if (results.decode_type != decode_type_t::UNKNOWN)
if ((results.decode_type != decode_type_t::UNKNOWN) || (bitRead(PCONFIG_LONG(0), P016_BitAcceptUnknownType)))
{
// String output = String(F("IRSEND,")) + typeToString(results.decode_type, results.repeat) + ',' + resultToHexidecimal(&results)
// + ',' + uint64ToString(results.bits);
@@ -617,6 +620,11 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
if (strCode.length() <= P16_Cchars) {
iCode += hexToULL(strCode);
if (iCodeDecodeType == decode_type_t::UNKNOWN) {
// set iCodeDecodeType UNKNOWN to RAW, otherwise AddCode() or ExecuteCode() will fail
iCodeDecodeType=decode_type_t::RAW;
}
if (bitRead(PCONFIG_LONG(0), P016_BitAddNewCode) && bEnableIRcodeAdding) {
P016_data->AddCode(iCode, iCodeDecodeType, iCodeFlags); // add code if not saved so far
}
@@ -628,23 +636,26 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
}
}
// Check if a solution for RAW2 is found and if not give the user the option to access the timings info.
# ifdef P016_P035_USE_RAW_RAW2
if (!bitRead(PCONFIG_LONG(0), P016_BitAcceptUnknownType)) {
// decode_type_t::UNKNOWN is not used as a valid IR code
// Check if a solution for RAW2 is found and if not give the user the option to access the timings info.
# ifdef P016_P035_USE_RAW_RAW2
if ((results.decode_type == decode_type_t::UNKNOWN) && !displayRawToReadableB32Hex(event->String2, results))
# else // ifdef P016_P035_USE_RAW_RAW2
if ((results.decode_type == decode_type_t::UNKNOWN) && !displayRawToReadableB32Hex(event->String2, results))
# else // ifdef P016_P035_USE_RAW_RAW2
if (results.decode_type == decode_type_t::UNKNOWN)
# endif // ifdef P016_P035_USE_RAW_RAW2
{
addLog(LOG_LEVEL_INFO,
F("IR: No replay solutions found! Press button again or try RAW encoding (timings are in the serial output)"));
serialPrint(F("IR: RAW TIMINGS: "));
serialPrint(resultToSourceCode(&results));
event->String2 = F("NaN");
yield(); // Feed the WDT as it can take a while to print.
// addLog(LOG_LEVEL_DEBUG,(String(F("IR: RAW TIMINGS: ")) + resultToSourceCode(&results))); // Output the results as RAW
// source code //not showing up nicely in the web log
if (results.decode_type == decode_type_t::UNKNOWN)
# endif // ifdef P016_P035_USE_RAW_RAW2
{
addLog(LOG_LEVEL_INFO,
F("IR: No replay solutions found! Press button again or try RAW encoding (timings are in the serial output)"));
serialPrint(F("IR: RAW TIMINGS: "));
serialPrint(resultToSourceCode(&results));
event->String2 = F("NaN");
yield(); // Feed the WDT as it can take a while to print.
// addLog(LOG_LEVEL_DEBUG,(String(F("IR: RAW TIMINGS: ")) + resultToSourceCode(&results))); // Output the results as RAW
// source code //not showing up nicely in the web log
}
}
# ifdef P016_P035_Extended_AC
+77 -44
View File
@@ -7,6 +7,8 @@
// ESPEasy Plugin to scan a 12 key touch pad chip MPR121
// written by Jochen Krapf (jk@nerd2nerd.org)
// 2021-12-29 tonhuisman: Add setting for panel sensitivity, as requested in https://github.com/letscontrolit/ESPEasy/issues/3828
// Reformat source using Uncrustify
// 2020-10-14 tonhuisman: Added settings for global and per-sensor sensitivity
// and getting 'calibration' touch pressure data (current, min, max)
@@ -19,21 +21,20 @@
// If more than one key is pressed, the value is sum of all KeyMap-values
#define PLUGIN_062
#define PLUGIN_ID_062 62
#define PLUGIN_NAME_062 "Keypad - MPR121 Touch [TESTING]"
#define PLUGIN_VALUENAME1_062 "ScanCode"
# define PLUGIN_062
# define PLUGIN_ID_062 62
# define PLUGIN_NAME_062 "Keypad - MPR121 Touch [TESTING]"
# define PLUGIN_VALUENAME1_062 "ScanCode"
# include "src/PluginStructs/P062_data_struct.h"
#include "src/PluginStructs/P062_data_struct.h"
# define P062_FLAGS_USE_CALIBRATION 0 // Set in P062_CONFIG_FLAGS
#define P062_FLAGS_USE_CALIBRATION 0 // Set in P062_CONFIG_FLAGS
# define P062_CONFIG_FLAGS PCONFIG_LONG(0) // 0-31 flags
#define P062_CONFIG_FLAGS PCONFIG_LONG(0) // 0-31 flags
#define P062_DEFAULT_TOUCH_TRESHOLD 12 // Defaults got from MPR_121 source
#define P062_DEFAULT_RELEASE_TRESHOLD 6
# define P062_DEFAULT_TOUCH_TRESHOLD 12 // Defaults got from MPR_121 source
# define P062_DEFAULT_RELEASE_TRESHOLD 6
boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
{
@@ -74,6 +75,7 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
{
const uint8_t i2cAddressValues[] = { 0x5A, 0x5B, 0x5C, 0x5D };
if (function == PLUGIN_WEBFORM_SHOW_I2C_PARAMS) {
addFormSelectorI2C(F("i2c_addr"), 4, i2cAddressValues, PCONFIG(0));
} else {
@@ -88,35 +90,49 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
addFormSubHeader(F("Sensitivity"));
{
uint8_t touch_treshold = PCONFIG(2);
if(touch_treshold == 0) {
touch_treshold = P062_DEFAULT_TOUCH_TRESHOLD; //default value
uint8_t touch_treshold = PCONFIG(2);
if (touch_treshold == 0) {
touch_treshold = P062_DEFAULT_TOUCH_TRESHOLD; // default value
}
addFormNumericBox(F("Touch treshold (1..255)"), F("p062_touch_treshold"), touch_treshold, 0, 255);
String unit_ = F("Default: ");
unit_ += String(P062_DEFAULT_TOUCH_TRESHOLD);
unit_ += P062_DEFAULT_TOUCH_TRESHOLD;
addUnit(unit_);
}
{
uint8_t release_treshold = PCONFIG(3);
if(release_treshold == 0) {
release_treshold = P062_DEFAULT_RELEASE_TRESHOLD; //default value
if (release_treshold == 0) {
release_treshold = P062_DEFAULT_RELEASE_TRESHOLD; // default value
}
addFormNumericBox(F("Release treshold (1..255)"), F("p062_release_treshold"), release_treshold, 0, 255);
String unit_ = F("Default: ");
unit_ += String(P062_DEFAULT_RELEASE_TRESHOLD);
unit_ += P062_DEFAULT_RELEASE_TRESHOLD;
addUnit(unit_);
}
{
bool canCalibrate = true;
const __FlashStringHelper *sensitivityOptions[] = {
F("Normal"),
F("Extra sensitive (behind 4-6mm glass cover)")
};
const int sensitivityValues[] = {
MPR212_NORMAL_SENSITIVITY,
MPR212_EXTRA_SENSITIVITY
};
addFormSelector(F("Panel sensitivity"), F("p062_panel_sensitivity"), 2, sensitivityOptions, sensitivityValues, PCONFIG(4));
}
{
bool canCalibrate = true;
bool tbUseCalibration = bitRead(P062_CONFIG_FLAGS, P062_FLAGS_USE_CALIBRATION);
P062_data_struct *P062_data = static_cast<P062_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr == P062_data) {
P062_data = new (std::nothrow) P062_data_struct();
P062_data = new (std::nothrow) P062_data_struct();
canCalibrate = false;
if (P062_data == nullptr) {
return success;
}
@@ -124,10 +140,11 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
P062_data->loadTouchObjects(event->TaskIndex);
addRowLabel(F("Object"));
html_table(EMPTY_STRING, false); // Sub-table
html_table(EMPTY_STRING, false); // Sub-table
html_table_header(F("&nbsp;#&nbsp;"));
html_table_header(F("Touch (0..255)"));
html_table_header(F("Release (0..255)"));
if (tbUseCalibration && canCalibrate) {
html_table_header(F("Current"));
html_table_header(F("Min"));
@@ -139,9 +156,10 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
addHtml(F("&nbsp;"));
addHtmlInt(objectNr + 1);
html_TD();
addNumericBox(getPluginCustomArgName(objectNr + 100), P062_data->StoredSettings.TouchObjects[objectNr].touch, 0, 255);
addNumericBox(getPluginCustomArgName(objectNr + 100), P062_data->StoredSettings.TouchObjects[objectNr].touch, 0, 255);
html_TD();
addNumericBox(getPluginCustomArgName(objectNr + 200), P062_data->StoredSettings.TouchObjects[objectNr].release, 0, 255);
addNumericBox(getPluginCustomArgName(objectNr + 200), P062_data->StoredSettings.TouchObjects[objectNr].release, 0, 255);
if (tbUseCalibration && canCalibrate) {
uint16_t current = 0;
uint16_t min = 0;
@@ -156,11 +174,13 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
}
}
html_end_table();
if (canCalibrate) {
const __FlashStringHelper * options1[2] = { F("No"), F("Yes") };
int optionValues1[2] = { 0, 1 };
int choice1 = tbUseCalibration ? 1 : 0;
const __FlashStringHelper *options1[2] = { F("No"), F("Yes") };
int optionValues1[2] = { 0, 1 };
int choice1 = tbUseCalibration ? 1 : 0;
addFormSelector(F("Enable Calibration"), F("p062_use_calibration"), 2, options1, optionValues1, choice1, true);
if (tbUseCalibration) {
addFormCheckBox(F("Clear calibrationdata"), F("p062_clear_calibrate"), false);
}
@@ -179,19 +199,21 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
PCONFIG(2) = getFormItemInt(F("p062_touch_treshold"));
PCONFIG(3) = getFormItemInt(F("p062_release_treshold"));
PCONFIG(4) = getFormItemInt(F("p062_panel_sensitivity"));
uint32_t lSettings = 0;
bool tbUseCalibration = getFormItemInt(F("p062_use_calibration")) == 1;
uint32_t lSettings = 0;
bool tbUseCalibration = getFormItemInt(F("p062_use_calibration")) == 1;
bitWrite(lSettings, P062_FLAGS_USE_CALIBRATION, tbUseCalibration);
P062_CONFIG_FLAGS = lSettings;
P062_CONFIG_FLAGS = lSettings;
{
bool canCalibrate = true;
bool canCalibrate = true;
P062_data_struct *P062_data = static_cast<P062_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr == P062_data) {
P062_data = new (std::nothrow) P062_data_struct();
P062_data = new (std::nothrow) P062_data_struct();
canCalibrate = false;
if (P062_data == nullptr) {
return success; // Save other settings even though this didn't initialize properly
}
@@ -202,22 +224,25 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
P062_data->StoredSettings.TouchObjects[objectNr].touch = getFormItemInt(getPluginCustomArgName(objectNr + 100));
P062_data->StoredSettings.TouchObjects[objectNr].release = getFormItemInt(getPluginCustomArgName(objectNr + 200));
}
#ifdef PLUGIN_062_DEBUG
# ifdef PLUGIN_062_DEBUG
String log = F("p062_data save size: ");
log += sizeof(P062_data->StoredSettings);
addLog(LOG_LEVEL_INFO, log);
#endif // PLUGIN_062_DEBUG
SaveCustomTaskSettings(event->TaskIndex, reinterpret_cast<const uint8_t *>(&(P062_data->StoredSettings)), sizeof(P062_data->StoredSettings));
# endif // PLUGIN_062_DEBUG
SaveCustomTaskSettings(event->TaskIndex, reinterpret_cast<const uint8_t *>(&(P062_data->StoredSettings)),
sizeof(P062_data->StoredSettings));
if (!canCalibrate) {
delete P062_data;
P062_data = nullptr;
} else {
bool clearCalibration = isFormItemChecked(F("p062_clear_calibrate"));
if (clearCalibration) {
P062_data->clearCalibrationData();
#ifdef PLUGIN_062_DEBUG
# ifdef PLUGIN_062_DEBUG
addLog(LOG_LEVEL_INFO, F("p062 clear calibration"));
#endif // PLUGIN_062_DEBUG
# endif // PLUGIN_062_DEBUG
}
}
}
@@ -233,26 +258,33 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
P062_data_struct *P062_data = static_cast<P062_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr != P062_data) {
if (!P062_data->init(event->TaskIndex, PCONFIG(0), PCONFIG(1), tbUseCalibration)) {
if (!P062_data->init(event->TaskIndex, PCONFIG(0), PCONFIG(1), tbUseCalibration, PCONFIG(4))) {
clearPluginTaskData(event->TaskIndex);
P062_data = nullptr;
} else {
success = true;
uint8_t touch_treshold = PCONFIG(2);
if(touch_treshold == 0) {
touch_treshold = P062_DEFAULT_TOUCH_TRESHOLD; //default value
uint8_t touch_treshold = PCONFIG(2);
if (touch_treshold == 0) {
touch_treshold = P062_DEFAULT_TOUCH_TRESHOLD; // default value
}
uint8_t release_treshold = PCONFIG(3);
if(release_treshold == 0) {
release_treshold = P062_DEFAULT_RELEASE_TRESHOLD; //default value
if (release_treshold == 0) {
release_treshold = P062_DEFAULT_RELEASE_TRESHOLD; // default value
}
if (touch_treshold != P062_DEFAULT_TOUCH_TRESHOLD && release_treshold != P062_DEFAULT_RELEASE_TRESHOLD) {
if ((touch_treshold != P062_DEFAULT_TOUCH_TRESHOLD) && (release_treshold != P062_DEFAULT_RELEASE_TRESHOLD)) {
P062_data->setThresholds(touch_treshold, release_treshold); // Set custom tresholds, ignore default values
}
for (uint8_t objectNr = 0; objectNr < P062_MaxTouchObjects; objectNr++) {
if (P062_data->StoredSettings.TouchObjects[objectNr].touch != 0 && P062_data->StoredSettings.TouchObjects[objectNr].release != 0) {
P062_data->setThreshold(objectNr, P062_data->StoredSettings.TouchObjects[objectNr].touch, P062_data->StoredSettings.TouchObjects[objectNr].release);
if ((P062_data->StoredSettings.TouchObjects[objectNr].touch != 0) &&
(P062_data->StoredSettings.TouchObjects[objectNr].release != 0)) {
P062_data->setThreshold(objectNr,
P062_data->StoredSettings.TouchObjects[objectNr].touch,
P062_data->StoredSettings.TouchObjects[objectNr].release);
}
}
}
@@ -311,6 +343,7 @@ boolean Plugin_062(uint8_t function, struct EventStruct *event, String& string)
log += F(" max: ");
log += max;
addLog(LOG_LEVEL_INFO, log);
if (!PCONFIG(1)) {
break;
}
+7 -6
View File
@@ -1167,7 +1167,6 @@ To create/register a plugin, you have to :
#define USES_P092 // DL-Bus
#define USES_P111 // RC522 RFID reader
#define USES_P119 // ITG3205 Gyro
#endif
#ifdef PLUGIN_SET_TESTING_D
@@ -1181,8 +1180,10 @@ To create/register a plugin, you have to :
#endif
#ifdef PLUGIN_SET_TESTING_E
#define USES_P120 // ADXL345 I2C
// #define USES_P125 // ADXL345 SPI
#define USES_P119 // ITG3205 Gyro
#define USES_P120 // ADXL345 I2C
#define USES_P121 // HMC5883L
#define USES_P125 // ADXL345 SPI
#endif
@@ -1474,10 +1475,10 @@ To create/register a plugin, you have to :
#define USES_P119 // ITG3205 Gyro
#endif
#ifndef USES_P120
#define USES_P120 // ADXL345 Acceleration / Gravity
#define USES_P120 // ADXL345 I2C Acceleration / Gravity
#endif
#ifndef USES_P121
#define USES_P121 //
#define USES_P121 // HMC5883L
#endif
#ifndef USES_P122
#define USES_P122 //
@@ -1489,7 +1490,7 @@ To create/register a plugin, you have to :
#define USES_P124 //
#endif
#ifndef USES_P125
#define USES_P125 //
#define USES_P125 // ADXL345 SPI Acceleration / Gravity
#endif
#ifndef USES_P126
#define USES_P126 //
+1
View File
@@ -244,6 +244,7 @@ String toString(const float& value, uint8_t decimals)
String doubleToString(const double& value, int decimals, bool trimTrailingZeros) {
String res(value, decimals);
res.trim();
if (trimTrailingZeros) {
int dot_pos = res.lastIndexOf('.');
if (dot_pos != -1) {
@@ -265,6 +265,24 @@ void P016_data_struct::ExecuteCode(uint64_t Code, decode_type_t DecodeType, uint
}
return;
}
# ifdef PLUGIN_016_DEBUG
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
String log;
log.reserve(128); // estimated
log = F("[P36] ValidateCode failed: ");
log += typeToString(DecodeType, bitRead(CodeFlags, P16_FLAGS_REPEAT));
log += F(" Code: 0x");
log += uint64ToString(Code, 16);
log += F(" / [");
log += (i + 1);
log += F("] = {");
log += typeToString(CommandLines[i].CodeDecodeType, bitRead(CommandLines[i].CodeFlags, P16_FLAGS_REPEAT));
log += F(" Code: 0x");
log += uint64ToString(CommandLines[i].Code, 16);
log += '}';
addLog(LOG_LEVEL_INFO, log);
}
# endif // PLUGIN_016_DEBUG
}
}
+1
View File
@@ -11,6 +11,7 @@
// bit definition in PCONFIG_LONG(0)
# define P016_BitAddNewCode 0 // Add automatically new code into Code of the command structure
# define P016_BitExecuteCmd 1 // Execute command if received code matches Code or AlternativeCode of the command structure
# define P016_BitAcceptUnknownType 2 // Accept unknown DecodeType as valid IR code (will be set to RAW before calling AddCode() or ExecuteCode())
# define P16_Nlines 10 // The number of different lines which can be displayed - each line is 64 chars max
# define P16_Nchars 64 // max chars per command line
+27 -19
View File
@@ -1,16 +1,16 @@
#include "../PluginStructs/P062_data_struct.h"
// Needed also here for PlatformIO's library finder as the .h file
// Needed also here for PlatformIO's library finder as the .h file
// is in a directory which is excluded in the src_filter
# include <Adafruit_MPR121.h>
#ifdef USES_P062
#include "../Helpers/ESPEasy_Storage.h"
# include <Adafruit_MPR121.h>
# include "../Helpers/ESPEasy_Storage.h"
P062_data_struct::P062_data_struct() {
#ifdef PLUGIN_062_DEBUG
# ifdef PLUGIN_062_DEBUG
addLog(LOG_LEVEL_INFO, F("P062_data_struct constructor"));
#endif
# endif // ifdef PLUGIN_062_DEBUG
clearCalibrationData(); // Reset
}
@@ -22,21 +22,24 @@ P062_data_struct::~P062_data_struct() {
}
bool P062_data_struct::init(taskIndex_t taskIndex,
uint8_t i2c_addr,
bool scancode,
bool keepCalibrationData) {
#ifdef PLUGIN_062_DEBUG
uint8_t i2c_addr,
bool scancode,
bool keepCalibrationData,
uint8_t sensitivity) {
# ifdef PLUGIN_062_DEBUG
addLog(LOG_LEVEL_INFO, F("P062_data_struct init()"));
#endif
# endif // ifdef PLUGIN_062_DEBUG
_i2c_addr = i2c_addr;
_use_scancode = scancode;
_keepCalibrationData = keepCalibrationData;
_sensitivity = sensitivity;
if (!keypad) {
keypad = new (std::nothrow) Adafruit_MPR121();
}
if (keypad) {
keypad->begin(_i2c_addr);
keypad->begin(_i2c_addr, _sensitivity);
loadTouchObjects(taskIndex);
return true;
}
@@ -44,21 +47,24 @@ bool P062_data_struct::init(taskIndex_t taskIndex,
}
void P062_data_struct::updateCalibration(uint8_t t) {
if (t >= P062_MaxTouchObjects) return;
if (t >= P062_MaxTouchObjects) { return; }
if (_keepCalibrationData) {
uint16_t current = keypad->filteredData(t);
CalibrationData.CalibrationValues[t].current = current;
if (CalibrationData.CalibrationValues[t].min == 0 || current < CalibrationData.CalibrationValues[t].min) {
if ((CalibrationData.CalibrationValues[t].min == 0) || (current < CalibrationData.CalibrationValues[t].min)) {
CalibrationData.CalibrationValues[t].min = current;
}
if (CalibrationData.CalibrationValues[t].max == 0 || current > CalibrationData.CalibrationValues[t].max) {
if ((CalibrationData.CalibrationValues[t].max == 0) || (current > CalibrationData.CalibrationValues[t].max)) {
CalibrationData.CalibrationValues[t].max = current;
}
}
}
bool P062_data_struct::readKey(uint16_t& key) {
if (!keypad) return false;
if (!keypad) { return false; }
key = keypad->touched();
if (key)
@@ -70,6 +76,7 @@ bool P062_data_struct::readKey(uint16_t& key) {
if (key & colMask) // this key pressed?
{
updateCalibration(col - 1);
if (_use_scancode) {
key = col;
break;
@@ -105,11 +112,11 @@ void P062_data_struct::setThreshold(uint8_t t, uint8_t touch, uint8_t release) {
* Load the touch objects from the settings, and initialize then properly where needed.
*/
void P062_data_struct::loadTouchObjects(taskIndex_t taskIndex) {
#ifdef PLUGIN_062_DEBUG
# ifdef PLUGIN_062_DEBUG
String log = F("P062 DEBUG loadTouchObjects size: ");
log += sizeof(StoredSettings);
addLog(LOG_LEVEL_INFO, log);
#endif // PLUGIN_062_DEBUG
# endif // PLUGIN_062_DEBUG
LoadCustomTaskSettings(taskIndex, reinterpret_cast<uint8_t *>(&StoredSettings), sizeof(StoredSettings));
}
@@ -117,7 +124,7 @@ void P062_data_struct::loadTouchObjects(taskIndex_t taskIndex) {
* Get the Calibration data for 1 touch object, return false if all zeroes or invalid input for t.
*/
bool P062_data_struct::getCalibrationData(uint8_t t, uint16_t *current, uint16_t *min, uint16_t *max) {
if (t >= P062_MaxTouchObjects) return false;
if (t >= P062_MaxTouchObjects) { return false; }
*current = CalibrationData.CalibrationValues[t].current;
*min = CalibrationData.CalibrationValues[t].min;
*max = CalibrationData.CalibrationValues[t].max;
@@ -134,4 +141,5 @@ void P062_data_struct::clearCalibrationData() {
CalibrationData.CalibrationValues[t].max = 0;
}
}
#endif // ifdef USES_P062
+22 -13
View File
@@ -8,7 +8,7 @@
# include <Adafruit_MPR121.h>
#define P062_MaxTouchObjects 12 // Max. number of (separate) touch inputs
# define P062_MaxTouchObjects 12 // Max. number of (separate) touch inputs
struct P062_data_struct : public PluginTaskData_base {
public:
@@ -18,12 +18,19 @@ public:
bool init(taskIndex_t taskIndex,
uint8_t i2c_addr,
bool scancode,
bool keepCalibrationData);
bool keepCalibrationData,
uint8_t sensitivity = MPR212_NORMAL_SENSITIVITY);
bool readKey(uint16_t& key);
void setThresholds(uint8_t touch, uint8_t release);
void setThreshold(uint8_t t, uint8_t touch, uint8_t release);
bool getCalibrationData(uint8_t t, uint16_t *current, uint16_t *min, uint16_t *max);
void setThresholds(uint8_t touch,
uint8_t release);
void setThreshold(uint8_t t,
uint8_t touch,
uint8_t release);
bool getCalibrationData(uint8_t t,
uint16_t *current,
uint16_t *min,
uint16_t *max);
void clearCalibrationData();
void loadTouchObjects(taskIndex_t taskIndex);
@@ -31,7 +38,7 @@ public:
* Structs for StoredSettings
*/
struct tP062_Sensitivity {
uint8_t touch = 0;
uint8_t touch = 0;
uint8_t release = 0;
};
@@ -46,8 +53,8 @@ public:
*/
struct tP062_CalibrationValue {
uint16_t current = 0;
uint16_t min = 0;
uint16_t max = 0;
uint16_t min = 0;
uint16_t max = 0;
};
struct tP062_CalibrationData_struct {
@@ -57,13 +64,15 @@ public:
tP062_CalibrationData_struct CalibrationData;
private:
void updateCalibration(uint8_t t);
Adafruit_MPR121 *keypad = nullptr;
uint16_t keyLast = 0;
int8_t _i2c_addr = -1;
bool _use_scancode = false;
bool _keepCalibrationData = false;
Adafruit_MPR121 *keypad = nullptr;
uint16_t keyLast = 0;
int8_t _i2c_addr = -1;
bool _use_scancode = false;
bool _keepCalibrationData = false;
uint8_t _sensitivity;
};
#endif // ifdef USES_P062