Specifications
64 Chapter 5 - Software Interface
PACKET.C - Interface-Independent Driver Code
The following code implements high-level functions querycommand() and
setcommand(). The protocol for querying commands, setting commands, and
receiving acknowledgements is described in Chapter 5. Touch packets are sent
automatically (a query is not necessary). The gettouch() function accepts these
packets, and returns the coordinates and status byte. See page 102 for the
structure of the Touch packet.
Functions getpacket() and sendpacket() are implemented in SERIAL.C or BUS.C.
typedef int boolean;
typedef unsigned char byte;
#define FALSE 0
#define TRUE !FALSE
typedef byte packettype[8];
void initcontroller(void);
void disablecontroller(void);
boolean getpacket(packettype packet, byte p);
boolean sendpacket(packettype packet);
boolean querycommand(packettype packet)
/* packet[0] must be in lower case. Issues query command, receives queried
packet, receives acknowledgement. Returns queried packet.
Note: Use querycommand() with query AND set Diagnostic command. */
{
packettype ack;
return(sendpacket(packet) &&
getpacket(packet,(byte)_toupper((int)*packet)) && /* command byte returned
in upcase */
getpacket(ack,'A') && (ack[2] == '0')); /* any errors in
acknowledgememt? */
}
boolean setcommand(packettype packet)
/* packet[0] must be in upper case. Issues set command, receives
acknowledgement. Returns nothing.
Note: Hard Reset and Quiet all commands do not return an Acknowledgement packet.
*/
{
packettype ack;
return(sendpacket(packet) &&
getpacket(ack,'A') && (ack[2] == '0')); /* any errors in
acknowledgememt? */
}
boolean gettouch(int *x, int *y, int *z, int *flags)
/* Poll controller for touch data. Returns TRUE if available or FALSE if timeout.
*/
{
packettype touch;
if (getpacket(touch,'T')) {
*x = touch[2] + (touch[3] << 8);
*y = touch[4] + (touch[5] << 8);
*z = touch[6] + (touch[7] << 8);
*flags = touch[1];
return(TRUE);
}
else
return(FALSE);
}
#define OK 0
#define NOCONTROLLER 1
#define SHORTED 2
#define CANTSEND 4
#define NORESPONSE 5
#define WRONGRESPONSE 6
void checkdiags(void)
{
packettype diags;
diags[0] = 'd'; querycommand(diags);