Skip to content

Device Driver Class

Doug edited this page Dec 23, 2021 · 1 revision

DeviceDef class:

This is a base class for any class that can receive a message from the switchboard. Such a class must inherit the DeviceDef class, and implement an instance of callBack.

TASK_NAME

The Switchboard only knows a limited number of pre-defined TASK_NAME (i.e.: device types), and it assumes one 'driver' for each type. These are defined in the 'Messages.h' file as members of the TASK_NAME class enumeration. Currently they consist of:

  • WAVEFILE This is assigned to the task or driver that actually reads the sound file (originally it was a .wav, currently we read .mp3 files).
  • EYES This destination controls the overall intensity of each eye.
  • JAW This controls the position of the JAW.
  • NOD This controls the vertical orientation (nodding) of the skeleton.
  • ROTATE This controls the direction (left to right) the skull is facing.
  • TEST Used for internal testing only
  • LAST MUST BE THE LAST ENTRY - this is used to set the size of some internal arrays.

On startup, the Device Driver registers itself with the SwitchBoard as the handler for a specific TASK_NAME (defined in Messages). When it is time to deliver a message to the driver, the driver's callBack member is called.

callBack member

The callback member has one argument - a const pointer to the message (which should not be modified or free'd).

This member function is called in the context of the Sequencer, so the callback routine should run as quickly as possible - the sequencer is tied up until it returns.

Typically, the guts of the driver run in its own task. The callback simply queues an action or otherwise notifies its driver of the needed action, and returns immediately.

Note that you must copy any needed information from the message before returning - the Sequencer deletes the message as soon as the callBack returns.

ACTIONS

The driver callback is allowed to send messages, but must use the 'SwitchBoard::sndFromCB()' routine to avoid locking issues. (Outside the context of the callback, all code must use 'SwitchBoard::snd()' to send a message.

The event numbers from 0 thru 10 are reserved for system control purposes. These are defined in messages.h. The currently defined events are:

  • EVENT_ACTION_NONE: This event should be ignored.
  • EVENT_ACTION_REGISTERED: This notifies the driver that it is registered.
  • EVENT_ACTION_SHUTDOWN: This notifies the driver that it should close any files or devices and shut down._ (TODO: Is this really needed?) _
  • EVENT_ACTION_SETVALUE: Most drivers simply require a new value to set their device - for example, a value indicating how bright the eyes should be, or how wide the jaw should be open.

The driver may use event numbers above 10 to define its own actions. These are unique to each driver, so need not be coordinated between drivers.

Clone this wiki locally