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

Berry counter #19558

Merged
merged 2 commits into from
Sep 20, 2023
Merged

Berry counter #19558

merged 2 commits into from
Sep 20, 2023

Conversation

s-hadinger
Copy link
Collaborator

Description:

Berry add ability to read and change Counter values:

  • if USE_COUNTER is not defined, or GPIO are not configured, all functions return nil
  • gpio.counter_read(counter:int) -> int or nil read counter value, or return nil if counter is not used
  • gpio.counter_set(counter:int, value:int) -> int or nil set the counter value, return the actual value, or return nil if counter is not used
  • gpio.counter_add(counter:int, value:int) -> int or nil add to the counter value, return the actual value, or return nil if counter is not used

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.13
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@s-hadinger s-hadinger merged commit fc513af into arendst:development Sep 20, 2023
63 checks passed
@sfromis
Copy link
Contributor

sfromis commented Sep 20, 2023

Seems to work, also for CounterType 2 giving millis.

Wondering about whether indexing should start at 0 or 1. Sure it can be "less confusing" to have same index numbers as on the Counter command etc, instead of 1 lower. OTOH set_power and get_power uses zero-based indexes. Thus there is a "consistency issue".

@s-hadinger
Copy link
Collaborator Author

Ah. Good question. For consistency it should start at 0, right?

@sfromis
Copy link
Contributor

sfromis commented Sep 21, 2023

Well, one-based would be consistent with base Tasmota, but zero-based would be more internally consistent within Berry, including with gpio.pin_used(gpio.CNTR1, 2) which returns false with two counters, but true for 2nd counter when using index 1 instead.

While using the lower level gpio module functions with Counter pins is probably not too useful, except for checking if pins are assigned as expected, it does look like the gpio module already leans toward zero-based.

I suppose that's a "yes" 😉

dilyanpalauzov pushed a commit to dilyanpalauzov/Tasmota that referenced this pull request Oct 1, 2023
* Berry read and write Counters

* rename counter
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