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

MQTT report setting for buttons: send action events, all events or state #1772

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Jun 11, 2019

ref #1747

@skyynet I though a bit about eventsensor for this, but it might be a bad match due to hardware limitations and noise (i think you pretty much required to have hardware filtering for the digital pin signal)

Instead, what about an option to send button pressed state instead of event, bypassing event mapping and directly giving user the button state?

edit: ...but I think this needs to be per-button instead of a global to be more flexible
done! current gcc version supports binary literals, so it is pretty easy to specify bitmask directly as int

Deprecate BUTTON_MQTT_SEND_ALL_EVENTS
New defines are BUTTON_MQTT_MASK_EVENTS and BUTTON_MQTT_MASK_PRESSED (with runtime btnMaskEvents and btnMaskPressed)

  • BUTTON_MQTT_MASK_PRESSED bitset to specify which buttons should send pressed() status to mqtt instead of events. For example with 3 buttons, it should be 0b11000000 to make BUTTON1 and BUTTON2 report to MQTT. BUTTON3 will still handle events
  • BUTTON_MQTT_MASK_EVENTS bitset to specify which buttons should ignore NONE action and still send event to mqtt. BUTTON_MQTT_MASK_PRESSED overrides it.

@mcspr mcspr changed the title BUTTON_MQTT_MODE setting MQTT report setting for buttons: send action events, all events or state Jun 11, 2019
@mcspr
Copy link
Collaborator Author

mcspr commented Jun 13, 2019

Per definitions configuration, button limit is 8 (=> uint8_t as mask makes sense)
And some useful things for container values:

  • uint8_t value{DEFINITION}; instead of uint8_t value = DEFINITION; will trigger compilation error instead of just a mere warning.
  • Based on v2 limits definition, BUTTONS_MAX is added. One wordy solution to this is to use container type as reference: std::numeric_limits<decltype(_button_mqtt_mask_events)>::digits would result in 8 for uint8_t

@davebuk
Copy link
Contributor

davebuk commented Apr 5, 2020

Is there currently any way I can use the mqtt reporting of a button state whose BUTTON_ACTION is set to NONE? I have a relay bound to switch#0 and use PRESSED as TOGGLE and also LONG CLICK for OFF. All others are set to NONE I use the LONG CLICK mqtt state 4 with openHAB to put the light into a different state using rules within openHAB.

I'd like to be able to use the DOUBLE CLICK state 3 or other states to carry out other functions in openHAB depending on the mqtt state of that same button, without operating the bound relay.

@mcspr
Copy link
Collaborator Author

mcspr commented Apr 5, 2020

Is there currently any way I can use the mqtt reporting of a button state whose BUTTON_ACTION is set to NONE?

See BUTTON_MQTT_SEND_ALL_EVENTS flag (default off)?
I have changed it a bit in the #2162 so it also checks btnMqttSendAll<button#> key (as boolean 1 or 0) to modify behaviour for a single button. After setting to 1 it should always send button event, even without any action attached.

@davebuk
Copy link
Contributor

davebuk commented Apr 6, 2020

Thanks. I thought BUTTON_MQTT_SEND_ALL_EVENTS was already default to ON. I'll test.

@davebuk
Copy link
Contributor

davebuk commented Apr 6, 2020

That all works. I did have one issue as I had set Click repeat delay in the webUI general section to 0 so accidental presses stop resets or AP mode. I've had to set it to 500ms to get the double/triple clicks to work.

Can Click repeat delay be defined per button at build to override the webUI setting?

@mcspr
Copy link
Collaborator Author

mcspr commented Apr 6, 2020

I've yet to add this to config list in the Wiki:

// TODO: compatibility proxy, fetch global key before indexed
const button_event_delays_t delays {
_buttonGetSetting("btnDebDel", index, _buttonDebounceDelay(index)),
_buttonGetSetting("btnRepDel", index, _buttonRepeatDelay(index)),
_buttonGetSetting("btnLclkDel", index, _buttonLongClickDelay(index)),
_buttonGetSetting("btnLLclkDel", index, _buttonLongLongClickDelay(index)),
};
const button_actions_t actions {
getSetting({"btnPress", index}, _buttonPress(index)),
getSetting({"btnClick", index}, _buttonClick(index)),
getSetting({"btnDclk", index}, _buttonDoubleClick(index)),
getSetting({"btnLclk", index}, _buttonLongClick(index)),
getSetting({"btnLLclk", index}, _buttonLongLongClick(index)),
getSetting({"btnTclk", index}, _buttonTripleClick(index))
};

btnRepDel<#index> key can be used for specific button. It will cancel out what WebUI sets, which is global default value.

@mcspr
Copy link
Collaborator Author

mcspr commented Apr 6, 2020

I was mistaken about the order above. To actually do that:

diff --git a/code/espurna/button.ino b/code/espurna/button.ino
index ff311352..7f5b7796 100644
--- a/code/espurna/button.ino
+++ b/code/espurna/button.ino
@@ -490,7 +490,7 @@ void _buttonConfigure() {
 // TODO: compatibility proxy, fetch global key before indexed
 template<typename T>
 unsigned long _buttonGetSetting(const char* key, unsigned char index, T default_value) {
-    return getSetting(key, getSetting({key, index}, default_value));
+    return getSetting({key, index}, getSetting(key, default_value));
 }

Without the patch btnRepDel overrides every btnRepDel0, btnRepDel1 etc., btnRepDel0 read second, then hard-coded value.
With the patch btnRepDel0 is read first, then btnRepDel, then hard-coded value.

mcspr added a commit that referenced this pull request Apr 7, 2020
#1772 (comment)
> Without the patch btnRepDel overrides every btnRepDel0, btnRepDel1 etc., btnRepDel0 read second, then hard-coded value.
With the patch btnRepDel0 is read first, then btnRepDel, then hard-coded value.

Indexed key can only be set via settings upload or in terminal, WebUI can change only the global override setting. Allow more 'specific' key to override global setting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants