Closed Mee42 closed 4 years ago
Once we have this method we could replace every single print statement in our program.
The final API is condensed into a set of macros (OHS_DEBUG, OHS_INFO, OHS_WARN, OHS_ERROR). Each of these take in a lambda that takes in a Formatter reference. These macros display information at various levels of severity. Warnings and errors are displayed in red and yellow respectively on the driver station and any level can be selected as the minimum level, causing all levels below to not be displayed (Eg if the log level is warning then only warnings and errors will be printed). This is desirable in competitions where we don't want the driver station cluttered with the target setpoint etc.
Here's an example of the api: OHS_DEBUG([](auto& f){ f << "Setpoint at " << m_Setpoint << " ticks"; }); OHS_DEBUG([](auto& f){ f.Write( "Motor ID is 0b").Base(m_Setpoint, 2).Write(" ticks"; }); Make sure to note that the formatter is passed by reference.
Any API exposed by Formatter can be used inside the lambda too. https://github.com/CougarProgramming623/InfiniteRecharge/blob/8e06b94a14362b69d8cf80ec64f763908a384a65/src/main/include/ohs/Formatter.h#L36
We need to standardize how we print to the driver station. We currently have several different ways to do it.
There's two different ways to report data: as an warning or as a printout statement. The first can be done using DriverStation::reportWarning and the second a PrintCommand.
Right now we mix DebugOutF, DriverStation::reportWarning (with or without the formatter) and so on. We need to go through our code and fix up how we do debugging and standardize it.
We should first look into getting printStatement output on the driver station, because using warnings doesn't seem like the best way to do things - we aren't warning, we are printing debug info.
I'm proposing 2 different methods of printing that we can use. The first is a function that takes a function pointer, which takes in a formatter and returns nothing (void, or formater, or whatever works). Code that uses this method would look like this:
which would replace the more cumbersome
but does the same thing
The second debug method should be a macro GOT_HERE which expands to a debug printout that prints the line and file that was just ran.