Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P097] Updating code and documentation #5165

Open
wants to merge 24 commits into
base: mega
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 86 additions & 27 deletions src/_P097_Esp32Touch.ino
chromoxdor marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@


# define PLUGIN_097
# define PLUGIN_ID_097 97
# define PLUGIN_NAME_097 "Touch (ESP32) - internal"
# define PLUGIN_VALUENAME1_097 "Touch"


# ifdef ESP32
# define P097_MAX_ADC_VALUE 4095
# endif // ifdef ESP32
# ifdef ESP8266
# define P097_MAX_ADC_VALUE 1023
# endif // ifdef ESP8266


# define P097_SEND_TOUCH_EVENT PCONFIG(0)
# define P097_SEND_RELEASE_EVENT PCONFIG(1)
# define P097_SEND_DURATION_EVENT PCONFIG(2)
# define P097_TOUCH_THRESHOLD PCONFIG(3)
# define PLUGIN_ID_097 97
# define PLUGIN_NAME_097 "Touch (ESP32) - internal"
# define PLUGIN_VALUENAME1_097 "Touch"
# define PLUGIN_VALUENAME2_097 "State"
# define P097_MAX_ADC_VALUE 4095
# define P097_MAX_LONGPRESS_VALUE 10000


# define P097_SEND_TOUCH_EVENT PCONFIG(0)
# define P097_SEND_RELEASE_EVENT PCONFIG(1)
# define P097_SEND_DURATION_EVENT PCONFIG(2)
# define P097_TOUCH_THRESHOLD PCONFIG(3)
//# define P097_SEND_LONG_PRESS_EVENT PCONFIG(5)
//# define P097_LONG_PRESS_TIME PCONFIG(6)
# define P097_SLEEP_WAKEUP PCONFIG(4)

// Share this bitmap among all instances of this plugin
DRAM_ATTR uint32_t p097_pinTouched = 0;
Expand All @@ -61,12 +59,13 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].ValueCount = 2;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].DecimalsOnly = false;
Device[deviceCount].TimerOption = false;
Device[deviceCount].TimerOptional = true;
Device[deviceCount].GlobalSyncOption = true;
Device[deviceCount].OutputDataType = Output_Data_type_t::All;
break;
}

Expand All @@ -77,16 +76,25 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
}

case PLUGIN_GET_DEVICEVALUENAMES:
{
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_097));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_097));
ExtraTaskSettings.TaskDeviceValueDecimals[0] = 0;
ExtraTaskSettings.TaskDeviceValueDecimals[1] = 0;
break;
}

case PLUGIN_SET_DEFAULTS:
{
P097_SEND_TOUCH_EVENT = 1;
P097_SEND_DURATION_EVENT = 1;
P097_SEND_RELEASE_EVENT = 1;
P097_SEND_DURATION_EVENT = 0;
//P097_LONG_PRESS_TIME = 1000;
#if defined(ESP32S2) || defined(ESP32S3)
P097_TOUCH_THRESHOLD = 1500;
#else
P097_TOUCH_THRESHOLD = 20;
#endif
break;
}

Expand All @@ -99,8 +107,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)

addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT);
addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT);
//addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT);
//addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE);
addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT);
addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE);
addFormCheckBox(F("Wake Up from sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP);
#if defined(ESP32S2) || defined(ESP32S3)
addFormNote(F("Wake up from sleep is only supported on one touch pin!"));
#endif

// Show current value
addRowLabel(F("Current Pressure"));
Expand All @@ -114,16 +128,21 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
{
P097_SEND_TOUCH_EVENT = isFormItemChecked(F("sendtouch"));
P097_SEND_RELEASE_EVENT = isFormItemChecked(F("sendrelease"));
//P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress"));
//P097_LONG_PRESS_TIME = getFormItemInt(F("longpress"));
P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration"));
P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold"));

P097_SLEEP_WAKEUP = isFormItemChecked(F("sleepwakeup"));
success = true;
break;
}

case PLUGIN_INIT:
{
P097_setEventParams(CONFIG_PIN1, P097_TOUCH_THRESHOLD);
if (P097_SLEEP_WAKEUP) {
touchSleepWakeUpEnable(CONFIG_PIN1, P097_TOUCH_THRESHOLD);
chromoxdor marked this conversation as resolved.
Show resolved Hide resolved
}
success = true;
break;
}
Expand All @@ -139,6 +158,38 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
const bool touched = bitRead(p097_pinTouched, t);
const bool touched_prev = bitRead(p097_pinTouchedPrev, t);

#if defined(ESP32S2) || defined(ESP32S3)
if (touched) {
bitClear(p097_pinTouched, t);
UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1));

if (touchInterruptGetLastStatus(CONFIG_PIN1)) {
UserVar.setFloat(event->TaskIndex, 1, 1);
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1);
chromoxdor marked this conversation as resolved.
Show resolved Hide resolved

if (P097_SEND_TOUCH_EVENT) {
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0));
}

} else {
UserVar.setFloat(event->TaskIndex, 1, 0);
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0);

if (P097_SEND_RELEASE_EVENT) {
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0));
}

if (P097_SEND_DURATION_EVENT) {
if (Settings.UseRules) {
eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t]));
}
}

p097_timestamp[t] = 0;
}
}

#else
if (touched) {
bitClear(p097_pinTouched, t);
}
Expand All @@ -148,27 +199,35 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1));

if (touched) {
UserVar.setFloat(event->TaskIndex, 1, 1);
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1);

if (P097_SEND_TOUCH_EVENT) {
// schedule a read to update output values and send to controllers
Scheduler.schedule_task_device_timer(event->TaskIndex, millis());
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0));
}

bitSet(p097_pinTouchedPrev, t);
} else {
} else {
// Touch released
UserVar.setFloat(event->TaskIndex, 1, 0);
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0);

if (P097_SEND_RELEASE_EVENT) {
// schedule a read to update output values and send to controllers
Scheduler.schedule_task_device_timer(event->TaskIndex, millis());
eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0));
}

if (P097_SEND_DURATION_EVENT) {
if (Settings.UseRules) {
eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t]));
}
}

bitClear(p097_pinTouchedPrev, t);
p097_timestamp[t] = 0;
}
}
}
#endif
}
}
success = true;
break;
Expand Down
Loading