template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
class ps2::SimpleDiagnostics< Size, LastErrorSize >
A basic recorder for events coming from the PS2 keyboard class library.
It addition to recording events, it can also blink an LED when an error has been recorded. It can dump its output to any print-capable class, such as the Serial port or a USB keyboard.
Basic Usage
static Diagnostics diagnostics;
void loop() {
if ( <magic-user-gesture> ) {
diagnostics.sendReport(Serial);
diagnostics.reset();
}
Each event is recorded as a series of one or more bytes in a circular queue. The queue is meant to be read right-to-left, with the newest events at the right. Thus if an event has multiple bytes in it, the extra bytes will be pushed onto the queue first. The last byte pushed contains the event ID and a count of the number of extra bytes. The number of extra bytes is in the lower two bits and the event ID in the upper 6. If the event ID is less than 16, it is taken to be an error.
There are two bytes reserved in the structure for storing all the errors that have happened since the recorder was last reset (as a bit-field).
Subclassing
If you want to record events from other parts of your application, you can create a subclass that defines new events. The Ps2ToUsbKeyboardAdapter example demonstrates how to do that:
class Diagnostics
{
enum class UsbTranslatorAppCode : uint8_t {
sentUsbKeyDown = 0 + base::firstUnusedInfoCode,
sentUsbKeyUp = 1 + base::firstUnusedInfoCode,
};
public:
void sentUsbKeyDown(byte b) { this->
push((uint8_t)UsbTranslatorAppCode::sentUsbKeyDown, b); }
void sentUsbKeyUp(byte b) { this->
push((uint8_t)UsbTranslatorAppCode::sentUsbKeyUp, b); }
};
Note that there are a maximum of 16 error identifiers and a maximum of 48 non-error identifiers.
Author's Note
Debugging and logging are often areas where we wish we could do more, but they can be infinite pits of labor if you let them. Further, when neglected, the rest of the project becomes an infinite pit of labor... There are two things I would wish for in the future: I wish it would store more data and, in particular, record the 10 keystrokes or other events before and after any error. I would also like to see a website-based diagnostic data interpreter.
- Template Parameters
-
Size | The number of bytes to use for recording events. |