Page 188 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 188
PDA 08 5/27/03 8:47 AM Page 164
PDA Robotics
The callback(IrConnect *con, IrCallBackParms *parms) function is
called whenever an infrared event happens, for example, when PDA
Robot sends us some data, this function is automatically called with
the event and data embedded in the parms parameter.
static void callback(IrConnect *con, IrCallBackParms *parms)
{
char* event;
char out= 0;
FormType *frm; // = FrmGetActiveForm();
switch (parms->event)
{
case LEVENT_DISCOVERY_CNF:
//
// This event was triggered by PDA Robot when
// we broadcast a discovery to ALL IrDA compliant
// devices. StoreDiscovery throws away all devices
// except PDA Robot. My HP printer always responds to
// the discovery request.
//
event = "DISCOVERY_CNF";
StoreDiscovery(parms->deviceList); break;
case LEVENT_PACKET_HANDLED:
packet_in_use = false;
event = "PACKET_HANDLED"; break;
case LEVENT_DATA_IND:
//
// PDA Robot has sent some data because we requested it.
// Let's copy the data to a global variable so it can be used
// elsewhere.
//
event = "DATA_IND";
MemMove(&received_data, parms->rxBuff, parms->rxLen);
MemMove(&out, &received_data[1], 1);
frm = FrmGetActiveForm ();
FrmDrawForm(frm);
StrPrintF((char *) range_data, "%u", out);//value);
current_range = out;
//
164