if (!sensorDevice->SetOperationModes(sensorDevice,
DetectionMode | SignalsMode | LedLevelsMode | DetectionHidMode | GesturesMode,
DetectionMode))
{
/* This function will return a message of Type OperationModesMessageType which will be handled in the coming for() loop */
printf("SetOperationModes error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
/* Here starts the loop that handles the messages to be sent/received to/from the sensor */
for (;;)
{
// Wait for the answer to arrive, timeout after 1 second (1000ms).
#define DEQUEUETIMEOUT 1000
Message * message = MyConnection->DeviceQueue->Dequeue (MyConnection->DeviceQueue, DEQUEUETIMEOUT);
if (NULL != message)
{
DumpMessage (message);
switch (message->MessageType)
{
/* 1. Change TAA size*/
case OperationModesMessageType:
/* this function will return a message of Type TouchActiveAreaMessageType which will be handled in the coming switch case */
if (!sensorDevice->SetTouchActiveArea(sensorDevice, 36, 2500, true, 0, 2080, true))
{
printf("SetTouchActiveArea error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
else {
printf("SetTouchActiveArea set");
}
break;
/* 2. Revert TAA */
case TouchActiveAreaMessageType:
/* this function will return a message of Type ReverseTouchActiveAreaMessageType which will be handled in the coming switch case */
if (!sensorDevice->SetReverseTouchActiveArea(sensorDevice, false, false))
{
printf("SetReverseTouchActiveArea error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
else {
printf("SetReverseTouchActiveArea set");
}
break;
/* 3. Set number of tracked objects */
case ReverseTouchActiveAreaMessageType:
/* this function will return a message of Type NumberOfTrackedObjectsMessageType which will be handled in the coming switch case */
if (!sensorDevice->SetNumberOfTrackedObjects(sensorDevice, 5))
{
printf("SetNumberOfTrackedObjects error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
printf("case SetNumberOfTrackedObjects set");
break;
/* 4. Get number of tracked objects */
case NumberOfTrackedObjectsMessageType:
/* this function will return a message of Type EnableMessageType which will be handled in the coming switch case */
if (!sensorDevice->SetEnable(sensorDevice, true, 0))
{
printf("SetEnable error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
else {
printf("EnableMessageType set");
}
break;
/* 5. Get platform ID if needed */
case EnableMessageType:
/* Put the next command here to execute on the sensor and continue in thius manner */
if (!platformDevice->GetMcuUniqueIdentifier(platformDevice))
{
printf("GetMcuUniqueIdentifier error (%d) %s.\n", zForceErrno, ErrorString(zForceErrno));
Destroy();
exit(-1);
}
break;
/* 6. Do whatever you need here */
case McuUniqueIdentifierMessageType:
/* Put the next command here to execute on the sensor and continue in this manner*/
break;
default:
/* Do nothing */
break;
}
message->Destructor (message);
}
connectionMessage = MyConnection->ConnectionQueue->Dequeue (MyConnection->ConnectionQueue, 0);
if (NULL != connectionMessage)
{
switch (connectionMessage->ConnectionStatus)
{
case Connected:
/* Should only be received upon connect. */
printf ("Connection status: Connected\n");
/* Do nothing */
break;
case Disconnected:
/* Should only be received if the program calls MyConnection->Disconnect(MyConnection); */
printf ("Connection status: Disconnected\n");
Destroy ();
exit (0);
break;
case ConnectionFault:
/* This should only happen if the sensor is physically disconnected or no longer
recognised by the system (i.e driver crash or similar). */
printf ("Connection status: (%d) %s\n", connectionMessage->ErrorCode,
ErrorString (connectionMessage->ErrorCode));
Destroy ();
exit (-1);
break;
default:
/* Do nothing */
break;
}
connectionMessage->Destructor(connectionMessage);
}
} |