Comments (8)
Hey,
good question.
Well, I'd rather not provide an option to call non-button code in my loop()
function.
Some people don't understand the non-blocking loop concept.
This would allow people to slow down the loop, leading to issues that don't pertain to my class per se.
Can you check whether data has changed via I2C, or can you only set the pin mode and read /write?
I'd just add a simple loop function for the port expander to get the word and bitshift to the virtual pin values, I think.
Does that make sense?
from button2.
I'm not sure which way to go; I can see the efficiency of reading a whole port expander byte (or word) at once and caching that for a short time. but in some apps, it may be necessary to always ask for 'fresh' data even if you have to re-fetch a whole byte/word.
I guess to allow max flex, when you do the equiv of a digitalRead(), you could add a param that forces a refetch of data, or will allow cached data. and if you leave off that last param, it would have a reasonable default (whatever that is).
dont know if I'm overthinking it or not; but i2c bus traffic has to be managed between all the things on the bus. I have an i2c oled display that I'm trying to keep updated quickly and I also want to scan for keyboard changes and not feel sluggish on the key scan. if I do an i2c request for each keypress check, it would clutter the bus. that's why I'm trying to think of the best way to deal with port expanders and fetching a whole bunch of data even if the user only wanted one bit of it.
thinking aloud, maybe something like:
digitalRead(pin, cache_allowed=true);
I'm thinking that hiding the fetch of the byte/word and the cache timing is something I'd like to hide from the app writer and just let them call the abstract digitalRead(). if they dont have a good reason to disable it, the cache would be used and some holding time would be in a ctor, somewhere.
from button2.
oh, and there would be a 'digitalReadWholePort()' or something, for when the user really wanted a complete set of bits and is going to do their own AND and OR stuff from that. that would also have a cache_allowed flag, to match the single bit reads. while it might seem less useful to keep the cache if you are asking for all the bits, but you may want to throttle how often the port is polled and this cache thing could be one way to limit how fast the i2c port is being queried.
(this might belong more on the port-expander class, though.)
from button2.
out of curiosity which port expander are you using?
You could use the debounce time of the buttons as the expander's interval to read data.
Would pass it to either the constructor or the loop(unsigned long interval_ms)
And I'd invert the digitalRead()
parameter to digitalRead(pin, force_read=false)
if you really want live data
from button2.
I tend to use mcp23008 and pcf8574 (or 75) mostly.
from button2.
Have one of the MCPs lying around and never used it so far.
Might attach a button or two to it to see. But this might take a while for me to try this.
from button2.
I often dont have a spare gpio to allocate to the interrupt pin on the PE chip so I have to poll and compare old word to new word, etc.
usually there are not enough pins. hey, isn't that way we use PEs? lol
from button2.
I setup button2 using an MCP23008 and an ESP32. I used a timer to update the state of 8 different buttons and used a global array to store that state of each of the buttons. Inside the button2 custom state handler rather than reading from the MCP I am reading from the array in memory. The fact that button2 "reads" the state of the button from the array more frequently than the timer updates the array doesn't really matter in the end. Both are happening so frequently that it self-mitigates any delays in updating the state. I was able to accurately capture single, double and triple presses and helds accurately.
For example, if you are only updating the state of the buttons into the array every 100 ms, even if the button loop was to read at the exactly worst possible time, you're only going to get a maximum of 100ms delay.
If you did want to use the interrupt on the MCP23008, you could still do the same thing except without the timer. The fact that the button2 loop is reading a "stale" array that hasn't been updated in a long time doesn't really matter to button2.
With an ESP32, unless your sketch is huge, you are going to run through the loop and hit the button2 loop functions more frequently than you are ever going to want to poll an i2c device. So it is easier just to decouple the two of them.
from button2.
Related Issues (20)
- Suggestion to add options for Led Buttons HOT 1
- Long click retriggerable stopped working in a recent update. HOT 4
- .pio/libdeps/seeed_xiao_esp32c3/Button2/src/Button2.cpp:186:20: error: 'touchRead' was not declared in this scope HOT 2
- detection of long presses does not work properly inside of an interupt timer HOT 2
- Interrupt wdt timeout on CPU1 HOT 2
- button.isPressed(); seems to stay latched. HOT 1
- Long press is not reported in polling mode HOT 1
- Change std::functional guards from platform-based to language version-based HOT 1
- multiple ESP32CapacitiveTouch.ino HOT 1
- 2.3.0 breaks at least on RP2040 with type errors HOT 3
- 2.3.x breaks default implementation? HOT 4
- Advices for implementing a speed-sensitive button-press control HOT 1
- setStateHandler Functions HOT 1
- Multiplexed buttons support HOT 1
- Use hall sensor instead button HOT 1
- 2.3.x does not compile on Arduino Uno R4 HOT 3
- Watchdog timer triggered on both ESP32 Capacitive Touch examples HOT 1
- virtual button init callback HOT 1
- update constants in examples
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from button2.