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

buttons: resistor ladder / analog buttons support #2357

Merged
merged 11 commits into from
Sep 24, 2020

Conversation

mcspr
Copy link
Collaborator

@mcspr mcspr commented Sep 18, 2020

  • Buttons events source as button property instead of a global one
  • Rename events source -> provider for all settings, consistent with the other things like relay and light providers
  • AnalogPin to read between a certain analogRead() range
    Trying to follow defaults here - analog 'press' is digital LOW, default value is HIGH, so no additional cfg entries are needed besides pin, level and changing evt source
  • (debug) Refactor gpio command, add adc to show analogRead(pin)
  • (debug) Add button command

https://gitter.im/tinkerman-cat/espurna?at=5f5d44c8df4af236f902e25d - analog buttons
https://gitter.im/tinkerman-cat/espurna?at=5f60e7f1f969413294e95370 - per-button events source

@alextircovnicu can you check this out?

New config is:

Flag Description
BUTTON_PROVIDER_ANALOG_SUPPORT Default 0, enable general support for the feature
BUTTON#_PIN In case of analog buttons, must be set to 17 (or to A0, Arduino Core macro for the first ADC channel)
BUTTON#_PROVIDER Default is BUTTON_PROVIDER_GENERIC, for the analog support - BUTTON_PROVIDER_ANALOG
BUTTON#_ANALOG_LEVEL Default is 0, the expected value from analogRead() when the button is pressed

(or, at runtime via btnGPIO0 => 17, btnProv0 => 2 and btnLevel0 => 500 respectively)

To discover button values, terminal adc / adc 17 will show the analogRead(A0) result.
button will show button objects that were created.

I only tested with 'Circuit 3' from https://github.com/bxparks/AceButton/tree/develop/docs/resistor_ladder as 1k <-> 220, 1k and 4.7k:

Resistor adc AnalogPin range
220 882 (724, 952)
1k 566 (415, 724)
4.7k 264 (0, 415)

- Buttons events source as button property instead of a global one
- AnalogPin to read between a certain `analogRead()` range
- Refactor `gpio` command, add `gpio 17` to show `analogRead()`
@luebbe
Copy link

luebbe commented Sep 18, 2020

Resistor gpio 17 AnalogPin range
220 882 (724, 952)
1k 566 (415, 724)
4.7k 264 (0, 415)

How do you handle the interval borders? In your example: Where do 415 and 724 go? They are in two intervals right now?

Copy link
Contributor

@alextircovnicu alextircovnicu left a comment

Choose a reason for hiding this comment

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

No comments about the code - it is above my current development level

I tested with WemosD1 Circuit 2: Series Resistor Ladder and also with the actual GOSUND P1 power strip.
Everything works as expected.

I will work next week a Wiki page for Gosund P1 and SP111.

Thank you for this!

@alextircovnicu
Copy link
Contributor

Resistor gpio 17 AnalogPin range
220 882 (724, 952)
1k 566 (415, 724)
4.7k 264 (0, 415)

How do you handle the interval borders? In your example: Where do 415 and 724 go? They are in two intervals right now?

Have look at adjustPinRanges method.

First the buttons are sorted in ascending order. Then interval borders are computer as average between two "neighbors" values.

@mcspr
Copy link
Collaborator Author

mcspr commented Sep 24, 2020

BTW, note of the changes to the config EVENTS_SOURCE -> PROVIDER
(both shorter and more consistent with the other config options)

@mcspr mcspr merged commit c7a95bf into xoseperez:dev Sep 24, 2020
@mcspr mcspr deleted the btn/ladders branch September 24, 2020 04:51
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.

None yet

3 participants