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

[P109] add button pin mode #5066

Open
wants to merge 5 commits into
base: mega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
9 changes: 7 additions & 2 deletions src/_P109_ThermOLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
}

addFormPinSelect(PinSelectPurpose::Generic_input, F("Button left/down"), F("taskdevicepin1"), CONFIG_PIN1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these are optional selections, right?

addFormCheckBox(F("Button left/down Pull mode (0=IntPullUp, 1=Input)"), F("invertbutton1"), P109_GET_BUTTON1_INVERT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is quite confusing.
Unchecked is pulled up?

What do you want to tell the user? Is it about the pull-up or invert up/down button?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed variables.

addFormPinSelect(PinSelectPurpose::Generic_input, F("Button right/up"), F("taskdevicepin2"), CONFIG_PIN2);
addFormCheckBox(F("Button right/up Pull mode (0=IntPullUp, 1=Input)"), F("invertbutton2"), P109_GET_BUTTON2_INVERT);
addFormPinSelect(PinSelectPurpose::Generic_input, F("Button mode"), F("taskdevicepin3"), CONFIG_PIN3);

addFormCheckBox(F("Button Mode Pull mode (0=IntPullUp, 1=Input)"), F("invertbutton3"), P109_GET_BUTTON3_INVERT);
addFormPinSelect(PinSelectPurpose::Generic_output, F("Relay"), F("heatrelay"), P109_CONFIG_RELAYPIN);

addFormCheckBox(F("Invert relay-state (0=on, 1=off)"), F("invertrelay"), P109_GET_RELAY_INVERT);

{
const __FlashStringHelper *options4[] = { F("0.2"), F("0.5"), F("1") };
const int optionValues4[] = { 2, 5, 10 };
Expand Down Expand Up @@ -213,6 +215,9 @@ boolean Plugin_109(uint8_t function, struct EventStruct *event, String& string)
bitWrite(lSettings, P109_FLAG_TASKNAME_IN_TITLE, isFormItemChecked(F("ptask")));
bitWrite(lSettings, P109_FLAG_ALTERNATE_HEADER, !isFormItemChecked(F("palt"))); // Inverted
bitWrite(lSettings, P109_FLAG_RELAY_INVERT, isFormItemChecked(F("invertrelay")));
bitWrite(lSettings, P109_FLAG_BUTTON1_INVERT, isFormItemChecked(F("invertbutton1")));
bitWrite(lSettings, P109_FLAG_BUTTON2_INVERT, isFormItemChecked(F("invertbutton2")));
bitWrite(lSettings, P109_FLAG_BUTTON3_INVERT, isFormItemChecked(F("invertbutton3")));
P109_FLAGS = lSettings;

{
Expand Down
11 changes: 7 additions & 4 deletions src/src/PluginStructs/P109_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ bool P109_data_struct::plugin_init(struct EventStruct *event) {
_varIndex = event->BaseVarIndex;
_relaypin = P109_CONFIG_RELAYPIN;
_relayInverted = P109_GET_RELAY_INVERT;
_buttonInverted[0] = P109_GET_BUTTON1_INVERT;
_buttonInverted[1] = P109_GET_BUTTON2_INVERT;
_buttonInverted[2] = P109_GET_BUTTON3_INVERT;
_setpointTimeout = P109_CONFIG_SETPOINT_DELAY - P109_SETPOINT_OFFSET;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, you don't seem to have Uncrustify installed or enabled, for formatting the source code. that does a lot for readability.
Docs on how to install & enable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatted.


if (P109_CONFIG_DISPLAYTYPE == 1) {
Expand Down Expand Up @@ -120,7 +123,7 @@ bool P109_data_struct::plugin_init(struct EventStruct *event) {

for (uint8_t pin = 0; pin < 3; ++pin) {
if (validGpio(PIN(pin))) {
pinMode(PIN(pin), INPUT_PULLUP);
pinMode(PIN(pin), _buttonInverted[pin] ? INPUT : INPUT_PULLUP);
}
}

Expand Down Expand Up @@ -198,7 +201,7 @@ bool P109_data_struct::plugin_ten_per_second(struct EventStruct *event) {
if (_initialized) {
uint32_t current_time;

if (validGpio(CONFIG_PIN1) && !digitalRead(CONFIG_PIN1)) {
if (validGpio(CONFIG_PIN1) && (_buttonInverted[0] ? digitalRead(CONFIG_PIN1) : !digitalRead(CONFIG_PIN1))) {
current_time = millis();

if (_buttons[0] + P109_BUTTON_DEBOUNCE_TIME_MS < current_time) {
Expand All @@ -207,7 +210,7 @@ bool P109_data_struct::plugin_ten_per_second(struct EventStruct *event) {
}
}

if (validGpio(CONFIG_PIN2) && !digitalRead(CONFIG_PIN2)) {
if (validGpio(CONFIG_PIN2) && (_buttonInverted[1] ? digitalRead(CONFIG_PIN2) : !digitalRead(CONFIG_PIN2))) {
current_time = millis();

if (_buttons[1] + P109_BUTTON_DEBOUNCE_TIME_MS < current_time) {
Expand All @@ -216,7 +219,7 @@ bool P109_data_struct::plugin_ten_per_second(struct EventStruct *event) {
}
}

if (validGpio(CONFIG_PIN3) && !digitalRead(CONFIG_PIN3)) {
if (validGpio(CONFIG_PIN3) && (_buttonInverted[2] ? digitalRead(CONFIG_PIN3) : !digitalRead(CONFIG_PIN3))) {
current_time = millis();

if (_buttons[2] + P109_BUTTON_DEBOUNCE_TIME_MS < current_time) {
Expand Down
7 changes: 7 additions & 0 deletions src/src/PluginStructs/P109_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ const char flameimg[] PROGMEM = {
# define P109_FLAG_TASKNAME_IN_TITLE 0
# define P109_FLAG_ALTERNATE_HEADER 1
# define P109_FLAG_RELAY_INVERT 2
# define P109_FLAG_BUTTON1_INVERT 3
# define P109_FLAG_BUTTON2_INVERT 4
# define P109_FLAG_BUTTON3_INVERT 5
# define P109_GET_TASKNAME_IN_TITLE bitRead(P109_FLAGS, P109_FLAG_TASKNAME_IN_TITLE)
# define P109_GET_ALTERNATE_HEADER bitRead(P109_FLAGS, P109_FLAG_ALTERNATE_HEADER)
# define P109_GET_RELAY_INVERT bitRead(P109_FLAGS, P109_FLAG_RELAY_INVERT)
# define P109_GET_BUTTON1_INVERT bitRead(P109_FLAGS, P109_FLAG_BUTTON1_INVERT)
# define P109_GET_BUTTON2_INVERT bitRead(P109_FLAGS, P109_FLAG_BUTTON2_INVERT)
# define P109_GET_BUTTON3_INVERT bitRead(P109_FLAGS, P109_FLAG_BUTTON3_INVERT)

struct P109_data_struct : public PluginTaskData_base {
P109_data_struct();
Expand Down Expand Up @@ -100,6 +106,7 @@ struct P109_data_struct : public PluginTaskData_base {
uint8_t _setpointTimeout = 0;
int8_t _relaypin = -1;
bool _relayInverted = false;
bool _buttonInverted[3] = {false, false, false};
String _last_heater;

String _title;
Expand Down