-
Notifications
You must be signed in to change notification settings - Fork 572
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
[Proposal] Add ReadBool and WriteBool to GpioController #121
Comments
I'm not sure how valuable these methods would be, since in reality you could still have the above code written in one line like: BitArray bitArray = new BitArray(new byte[] { 0x1A });
foreach (bool bitValue in bitArray)
{
_controller.Write(1, (bitValue) ? PinValue.High : PinValue.Low);
// Other logic...
} Granted it is not as readable as an overload, but I'm just not convinced that we should add extra methods for this. Also, if we were to add them, I would much rather just have an overload of Write that takes in a bool instead of a PinValue than having different method names. |
Yeah, I originally wanted the Write/Read, but since you couldn't have a Read for returning both PinValue or a bool is why I added the Bool at end. I agree, just use the logic above will be fine. Closing. |
I believe that this experience should be better now that PinValue is a struct right? You should now be able to use either int or bool on the write method by just casting. @krwq do you agree that after this change we don't need these extra Apis any longer? |
I think I'm fine with this as us after @JeremyKuhne's changes. @shaggygi? (closing this assuming you agree) |
This proposal is an addition to the
GpioController
class that include helper methods for working with the different pin values and their respective boolean value.Rationale and Usage
There are many times you need to determine the bit value and must perform conversions of setting/clearing the bit. Pins sometimes represent bits within a value. The proposal would help from having to write redundant code in apps and device bindings. For example, reading pin values while clocking data to/from a device.
Example
The following writes the different bits to a pin.
The proposed changes would allow the code to be written as:
Proposed Changes
The proposed changes are to add the following helper methods within
GpioController
class.Open Questions
I'm not sure the proposed method names are the best. I used WriteBool/ReadBool as you can't overload Read to return PinValue or bool. What would be the best names?
Should there be an option as a bool? where null represents closed pin or high-impedance state? I don't think so as that makes things a little more complex. Low (false) and High (true) should be good enough.
The text was updated successfully, but these errors were encountered: