-
Notifications
You must be signed in to change notification settings - Fork 586
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
1-wire controller and thermometer binding #793
Conversation
Should fix #172 |
Generally this looks mostly good to me, the bus enumeration and |
I could set the default to -1 instead of 64 and interpret that as don't change it from default. |
As for bus I didn't see any response to my comments/questions. Maybe you could elaborate about what it is exactly that you don't like. Is it the use of an object for bus (which I need to do operations on like scan/search etc)? Or is it the fact that I allocate bus objects in OneWireDevice.EnumerateDevices() (which could be optimized to not using EnumerateBuses()+bus.EnumerateDevices())? |
@maloo I've already responded above but seems something bugged there and doesn't display correctly. For 1st question:
For 2nd question:
|
I can't find a nice solution with bus as id during enumeration. I keep having to new up the same amount or more OneWireBus instances. I see two use cases (see 1-wire sample).
|
Or, we make bus/device structs OWBusId/OWDeviceId w/ same operations as OWBus/OWDevice. That is technically the same as string id and static operations taking id param. But then I would like to get back OWController w/ Dispose to control caching and state lifetime for future platforms with heavyweight device state. |
The code suggestions are what I meant |
src/devices/OneWire/FamilyBindings/OneWireThermometerDevice.Linux.cs
Outdated
Show resolved
Hide resolved
Yes, that far I got it :)
I believe I have listed the pros/cons with the string only solution above, and it in not the API change itself, but rather the changes it force in the other part of the API that I don't like. And the use cases listed in the sample code that get messier. |
@maloo do bus id / device id change when rebooting? If they don't then you can avoid enumerating and allocating all together if user stores ID - if it's not possible on linux it might be possible on different OSes we might support in the future. Other reason is that it follow patterns we do in other places:
also enumerating string allows users do display something sensible in the UI |
Ok, so the main reason is SerialPort/File enumeration style. IDs don't change, but devices come and go dynamically so background scans or user requested bus scans can change What devices are enumerated. My main objection to the id only solution is the user's code:
would now be:
The second one is just a bit too complex for me just to keep style with File/SerialPort ;) It is also forcing user to instantiate a OneWireBus, in the other it is not needed (internal details that can be fixed if needed). Common ground? What about supporting both? EnumerateBusNames/EnumerateDeviceNames() and EnumerateDevices() |
Looking back in the comments, maybe we have common ground. Do you want the id solution for bus only or bus+device? I first interpreted your comments to want both, but in later comments I see you only mention the bus. So OneWireDevice.EnumerateDevices() would be fine? |
@maloo IMO EnumerateDevices (assuming it's an instance method on OneWireBus) should enumerate only ids (strings) since bus id is implied by the instance. For the concern about casting, if you enumerate strings then you could potentially do: |
src/devices/OneWire/FamilyBindings/OneWireThermometerDevice.Linux.cs
Outdated
Show resolved
Hide resolved
LGTM after fixing comments |
Thank you @maloo! I'm still slightly skeptical about the IsCompatible (perhaps the name) but we can re-iterate on that if we get some issues about it |
Implementation of proposed API in #197.
Code sample to scan for devices, enumerate buses and devices and print temperature of all thermometer family devices found.