Ps2KeyboardHost  1.0.1
Allows you to read from one or more PS2-style keyboards on an Arduino.
ps2::SimpleDiagnostics< Size, LastErrorSize > Class Template Reference

A basic recorder for events coming from the PS2 keyboard class library. More...

#include <ps2_SimpleDiagnostics.h>

Public Member Functions

template<typename Target >
void sendReport (Target &printTo)
 Dumps all event data to a print-based class. More...
 
bool anyErrors () const
 Returns true if any errors have been recorded since the last call to reset. More...
 
void reset ()
 Clears all recorded data. More...
 
template<uint8_t DiagnosticLedPin = LED_BUILTIN, DiagnosticsLedBlink LedBehavior = DiagnosticsLedBlink::blinkOnError>
void setLedIndicator ()
 Enables you to have a blinking indicator when an error happens. More...
 
void packetDidNotStartWithZero ()
 
void parityError ()
 
void packetDidNotEndWithOne ()
 
void packetIncomplete ()
 
void sendFrameError ()
 
void bufferOverflow ()
 
void incorrectResponse (KeyboardOutput scanCode, KeyboardOutput expectedScanCode)
 
void noResponse (KeyboardOutput expectedScanCode)
 
void noTranslationForKey (bool isExtended, KeyboardOutput code)
 
void startupFailure ()
 
void clockLineGlitch (uint8_t numBitsSent)
 
void sentByte (byte b)
 
void receivedByte (byte b)
 

Protected Member Functions

template<typename E >
void push (E code)
 
template<typename E1 , typename E2 >
void push (E1 code, E2 extraData1)
 
template<typename E1 , typename E2 , typename E3 >
void push (E1 code, E2 extraData1, E3 extraData2)
 

Static Protected Attributes

static const uint8_t firstUnusedFailureCode = (uint8_t)Ps2Code::_firstUnusedError
 
static const uint8_t firstUnusedInfoCode = (uint8_t)Ps2Code::_firstUnusedInfo
 

Detailed Description

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

typedef ps2::SimpleDiagnostics<32> Diagnostics;
static Diagnostics diagnostics;
static ps2::Keyboard<4,2,1,Diagnostics> ps2Keyboard(diagnostics);
void loop() {
diagnostics.setLedIndicator<LED_BUILTIN_RX, ps2::DiagnosticsLedBlink::heartbeat>();
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
: public ps2::SimpleDiagnostics<254>
{
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
SizeThe number of bytes to use for recording events.

Member Function Documentation

◆ anyErrors()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
bool ps2::SimpleDiagnostics< Size, LastErrorSize >::anyErrors ( ) const
inline

Returns true if any errors have been recorded since the last call to reset.

◆ bufferOverflow()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::bufferOverflow ( )
inline

◆ clockLineGlitch()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::clockLineGlitch ( uint8_t  numBitsSent)
inline

◆ incorrectResponse()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::incorrectResponse ( KeyboardOutput  scanCode,
KeyboardOutput  expectedScanCode 
)
inline

◆ noResponse()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::noResponse ( KeyboardOutput  expectedScanCode)
inline

◆ noTranslationForKey()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::noTranslationForKey ( bool  isExtended,
KeyboardOutput  code 
)
inline

◆ packetDidNotEndWithOne()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::packetDidNotEndWithOne ( )
inline

◆ packetDidNotStartWithZero()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::packetDidNotStartWithZero ( )
inline

◆ packetIncomplete()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::packetIncomplete ( )
inline

◆ parityError()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::parityError ( )
inline

◆ push() [1/3]

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
template<typename E >
void ps2::SimpleDiagnostics< Size, LastErrorSize >::push ( code)
inlineprotected

◆ push() [2/3]

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
template<typename E1 , typename E2 >
void ps2::SimpleDiagnostics< Size, LastErrorSize >::push ( E1  code,
E2  extraData1 
)
inlineprotected

◆ push() [3/3]

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
template<typename E1 , typename E2 , typename E3 >
void ps2::SimpleDiagnostics< Size, LastErrorSize >::push ( E1  code,
E2  extraData1,
E3  extraData2 
)
inlineprotected

◆ receivedByte()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::receivedByte ( byte  b)
inline

◆ reset()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::reset ( )
inline

Clears all recorded data.

◆ sendFrameError()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::sendFrameError ( )
inline

◆ sendReport()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
template<typename Target >
void ps2::SimpleDiagnostics< Size, LastErrorSize >::sendReport ( Target &  printTo)
inline

Dumps all event data to a print-based class.

It's a good idea to call reset after calling this.

◆ sentByte()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::sentByte ( byte  b)
inline

◆ setLedIndicator()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
template<uint8_t DiagnosticLedPin = LED_BUILTIN, DiagnosticsLedBlink LedBehavior = DiagnosticsLedBlink::blinkOnError>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::setLedIndicator ( )
inline

Enables you to have a blinking indicator when an error happens.

Template Parameters
DiagnosticLedPinThe led's pin - usually one of the built-in pins.
LedBehaviorControls what the LED does. See DiagnosticsLedBlink for the available behaviors.

◆ startupFailure()

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
void ps2::SimpleDiagnostics< Size, LastErrorSize >::startupFailure ( )
inline

Member Data Documentation

◆ firstUnusedFailureCode

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
const uint8_t ps2::SimpleDiagnostics< Size, LastErrorSize >::firstUnusedFailureCode = (uint8_t)Ps2Code::_firstUnusedError
staticprotected

◆ firstUnusedInfoCode

template<uint16_t Size = 60, uint16_t LastErrorSize = 30>
const uint8_t ps2::SimpleDiagnostics< Size, LastErrorSize >::firstUnusedInfoCode = (uint8_t)Ps2Code::_firstUnusedInfo
staticprotected

The documentation for this class was generated from the following file: