Hardware Reference
In-Depth Information
he main function is quite simple: It opens the serial port and then gets one point of data,
plots it and wipes the screen. his primes the last coordinate positions so that the drawing
starts at the current point. hen there is a simple ininite loop that checks for any quit or
keyboard inputs, and then gets another pair of points and plots them. he getData() func-
tion simply reads four bytes from the serial port, and the checkInput() function is called
as part of an if statement. his returns true or false depending whether the input bytes
have the correct tag bits on them. If they are okay, the bytes are unpacked into a reading
variable; if not then a message is printed out, and bytes are read in one at a time in an attempt
to resynchronise the data stream.
Drawing the data on the screen is quite simple and handled by the drawData() function. A line
is drawn between this new pair of points and the last set. Now at this point you might expect to
update the screen. However, when I tried this it took too long, and the data backed up in the buf-
fer leading it to overlow and thus fail. So I came up with the compromise that the actual screen
would only be updated every 0.2 of a second. his is done by using the timer module to see if it is
time to update the screen. his results in a slightly jerky drawing, but it is not too disturbing to
look at. As a result, in normal circumstances, the bufer is nearly always empty. However, when
the operating system times out the program, the bufer is big enough to cope, and the display is
not disturbed. You can see the display very rapidly catch up when the program returns.
he other main part of the program is the checkForQuit() function. his checks for the
Esc key or the window close click as normal, but it also checks to see if any keyboard key has
been pressed. hese are used for various functions, as summarised in Table 16-2.
Table 16-2 Keyboar d Functions
Key
Function
R
Plot in red
G
Plot in green
B
Plot in blue
C
Plot in cyan
Y
Plot in yellow
M
Plot in magenta
W
Plot in white
K
Plot in black
Spacebar
Wipe the screen
S
See the number of bytes waiting in the bufer
H
Halt the sending of data from the Arduino
continued
Search WWH ::




Custom Search