Hardware Reference
In-Depth Information
The TVout project ( https://code.google.com/p/arduino-tvout ) uses two resistors and a piece of wire to
control a 128 x 96 pixel display on a standard TV set. It only supports black and white rendering, but has been used for
small games, as well as more traditional applications. The processing overhead of generating the image is, naturally,
high so the control logic needs to be fairly tight but it is still very possible to make useful reporting apps.
Joysticks for Input
Joysticks, particularly old ones, make wonderful input devices because they interface with the parallel port on most
standard sound cards and are physically rugged. This enables the buttons to be reused, particularly as foot pedals,
to control software. Indeed, this provides a very cheap way of adding a dictation module to your machine, without
the need for an Arduino providing the input. In addition to triggering individual events on a Linux machine, such
as requesting a weather report or the state of the machine, it can also feed messages to other applications. mplayer ,
for example, can operate in slave mode, allowing commands to be fed to it from the standard input or a named pipe.
Similarly, the X Window TV-viewing software, xawtv , comes with xawtv-remote to change channel and volume
(as per most remote controls), giving you capture on/off and screenshot facilities. This makes it possible to freeze
frame magic shows to see how they do it!
You can read the joystick directly from /dev/js0 , but it is usually better to use an abstraction, like the Simple
DirectMedia Layer (SDL). This allows you to port the code elsewhere if necessary, avoid the vagaries that come with
a reliance on the device hierarchy, and make it easier for others to add and adapt your code.
The code to read and process the joystick is a very simple loop of C code:
#include <SDL/SDL.h>
int main() {
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick *pJoystick = SDL_JoystickOpen(0);
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_JOYBUTTONDOWN:
// Use event.jbutton.which, event.jbutton.button, event.jbutton.state
break;
}
}
SDL_JoystickClose(pJoystick);
return 0;
}
The button presses can naturally trigger software internally or make use of the Minerva Minx system I mentioned
earlier to execute separate external scripts (Minerva is covered fully in Chapter 7).
Some joysticks can also be used as output devices, through an technique known as force feedback , available
under Linux with libff . This functionality is provided through one of two drivers, HID driver ( hid-lg2ff ) or
I-Force driver ( iforce.ko ), which cover a number of the force feedback devices on the market. Alas, not all of them
Search WWH ::




Custom Search