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
MCP23017 with DCS BIOS #99
Comments
See my code vars:
Setup:
procedures:
Example of use:
|
awesome! Thanks. Missed the possibility of using sendDcsBiosMessage(). Your "example of use" is meant to be in the loop()? Not like the regular statements with the dcsbios namespace right? That's how I got it working. You left out the part to init the lastState array in case someone is reading this. Why do you have double arg for your switches. I see you are not using it, was/is there a feature you were/are planning for? |
I have send You only important parts of my code, lastState array i have definied: int lastState[3][16]; Yes, my example of use must be in loop. Inputs i must have in loop(), but outputs before, example:
I'm not remember for what is the first arg in Switch2Pos. I got this from somebody |
No problem. I got it working anyway but decided it would be useful to note that for anyone else who reads this. Would be useful if this method was documented in the official documents or implemented as an official method as well. Thanks a lot for your help. |
So far, there is no built-in support for any kind of I/O expander. Getting this right requires careful planning (keeping in mind that whatever I implement into the "official" library, I'll have to support in the future). The current version of the Arduino library is optimized for ease of use first, efficiency second. Once we add I/O expanders into the mix, it will become easier to reach the resource limits (especially the 2K RAM) on the ATMega328, so making efficient use of memory will become more important. As an example, a DcsBios::Switch2Pos needs seven bytes of RAM plus the space to store the message string, which is another 10 to 20 bytes. (Replacing that string with a two- or four-byte numerical identifier is on the road map for DCS-BIOS 2.0.) Assuming 25 bytes per switch, adding five 16-Bit I/O expanders would allow you to exceed the amount of available RAM with two-position switches, at which point the compiler would refuse to build the sketch. The problem is what happens before that: when you get close to the limit but do not exceed it, the sketch will still compile, but the 2K RAM on the microcontroller won't be enough to hold all that data plus the call stack, so the call stack will overwrite part of the heap memory, at which point you get undefined behavior (i.e. very hard to debug problems). Unfortunately, it is not easy to determine exactly how large the stack will get in advance, either. The most memory-efficient implementation I can think of would only need a single bit of RAM to store the last state (so you could pack the state for 8 Switch2Pos into one byte of memory). I could write some library code for that, but using it would require a working knowledge of C++. The challenge is to find a middle ground where we have code that is reasonably efficient but still allows us to use C++ language features to hide the complexity, so copy-and-paste from the reference docs continues to be a thing. |
I see. Understand regarding needing to keep memory use down. I guess since not everyone will be using GPIO expanders then it would be better to keep it a separate item. I'm quite fine coding it separately for now. Maybe this current method could be documented/linked to from the official docs for people to know how to manually use GPIO expanders. |
Is there support for the MCP23017 and DCS BIOS? Been trying to figure out how to interface the Adafruit library with DCS BIOS.
The text was updated successfully, but these errors were encountered: