-
Notifications
You must be signed in to change notification settings - Fork 487
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
patch: add error code handling of temperatures #238
base: master
Are you sure you want to change the base?
patch: add error code handling of temperatures #238
Conversation
12d7a6b
to
6817948
Compare
tentative patch for handling issue milesburton#236 - adds unit types to force handling of different units with respect to each other - implicit conversions to floats only for result types from existing functions - basic error codes added as an enum, edit as needed
6817948
to
ba2faf1
Compare
Some example usage: bool address_ok = sensors.getAddress(deviceAddress, 0);
if (!address_ok)
return;
DallasTemperature::request_t request = sensors.requestTemperatures();
DallasTemperature::celsius_result_t temp_reading= sensors.getTempC(deviceAddress);
// consider utility functions for testing for specific error flags / codes
if (temp_reading.error_code & DallasTemperature::device_error_code::device_fault_open) {
//display error for shorted ground
}
if (temp_reading.error_code & DallasTemperature::device_error_code::device_fault_shortgnd) {
//display error for shorted ground
}
if (temp_reading.error_code & DallasTemperature::device_error_code::device_fault_shortvdd) {
//display error for shorted vdd
}
// etc...for other errors
if (temp_reading.error_code != DallasTemperature::device_error_code::device_connected) {
return;
}
float f = temp_reading.value.celcius; // do something with the temperature
//float f = temp_reading; // for backwards compatibility |
If I understand this correctly, applying this patch would require refactoring existing usage of the library. I don't think that's acceptable as that would require firmware changes to every project that uses this library. --edit I see how it works now. I'm testing this in a project that needs error reporting. will report back results |
You may want to add the other edit for simplifying the flags, should in theory cut the number of jumps in the resulting code. Not sure if I made a patch for that in my own fork. |
Hello @Andersama I am trying your example code. I get an error compiling at the line Compiler error
I am attaching a zip of my sketch which produced this error on an Arduino Due Full Example PleaseCould you provide a fully functional example which compiles? Thanks. |
@ForrestErickson well glad you decided to test it first. That error's saying that the type doesn't contain a member called "celsius" which, on second viewing, is true. Badly written example on my part try |
@LokiMetaSmith yeah, from what I remember there was a discussion about magic numbers somewhere, so this was my suggestion instead. I kept the original magic values in the commit so this should be backwards compatible. I was aiming though to remove the nested if/else if chain. |
Like you @Andersama I don't have an Arduino to hand so I'm hesitant to merge. @RobTillaart any thoughts? |
Had a quick look and besides error codes it introduces a few new types. I understand that this allows compile time checking, which is good. However what worries me is that it might make existing projects more complex for the average Arduino user. Furthermore does this extra type checking help the novice Arduino user? I know arguments for both sides. So I need to review the details in more depth and check what happens with existing code too. I do not have time to dive into these tests on short term. |
@milesburton |
Annoyingly that doesn't appear to be as straight forward as I'd like. Let me pull the change and push a dummy commit. Hopefully that'll persuade github to rerun the jobs |
Well whatever exactly I was thinking at the time's a bit lost to me at this point, it's been a year, but I do remember trying to make it compatible abi wise as possible. |
FYI, |
tentative patch for handling issue #236
Please test that this compiles on hardware before commiting* I don't have an arduino laying around anymore.
Just looked back at the underlying code for the basic errors I added, the originals all appear to be from a bitmask, could be considerably faster to just pass along the error state from what was read. EG: take
and turn it into something like: