So, when I learned C, I (Learned it the hard way
). One of the coolest functions he made were (Zed's Awesome Debug Macros
), which are a fantastic way to simultaniously handle error checking and debugging in your program.
Well, now that I've gotten back into programing the Arduino, I decided to port this and make it much better. Check out my library (and all updated releases) here:Github Repository
// ### Intended Use:
// There are many times where you want to do error checking and simultaniously provide debugging.
// This library helps significantly. Errors are automatically printed if DEBUG is defined.
// This library offers two ways to deal with errors, documented below:
// return checks -- these do all your logging for you and set derr. (the global error variable).
// They then return R.
// these are intended for "simple use" cases, where you do not need to
// do any error handling (like send special error messages, close ports,
// goto error checks -- these do your logging, etc and then "goto error;" where you can do error
// handling like closing ports, etc.
If you load up the sketch and run the example, you will get output like this:
(note that I am imputing 5 and then a character ('k' I think).
:: DBG: (0 errorhandling_ex1.ino:28)| 35 1
:: DBG: (0 errorhandling_ex1.ino:30)| outint:5
:: DBG: (0 errorhandling_ex1.ino:28)| 61 0
:: [ERR](50 errorhandling_ex1.ino:16)| (50:TypeErr)97
:: DBG: (50 errorhandling_ex1.ino:30)| outint:-1
:: [ERR](50 errorhandling_ex1.ino:31)| (253:NoNew)
:: [ERR](50 errorhandling_ex1.ino:40)| (253:NoNew)
:: DBG: (50 errorhandling_ex1.ino:45)| Caught Error
:: [ERR](252 errorhandling_ex1.ino:46)| (252:Cleared Error)
If I comment out "#define DEBUG":
Doing dbg test
As you can see, it shows the type of log, whether there is an error (first number), the file name : line number, and then the errno and the corresponding string for it (defined by this function). Finally, some of them print an output as well.
Error checking and helpful debugging messages given by a line of code as small as "assert_return(isint(c), -1);
"! Yes please! Current Issues
You must include SoftwareSerial.h -- I can't figure out why my inclusion in the .h file is not sufficient, can someone help me with this?