void MyDeviceEventFunction(I1_DeviceHandle devHndl, I1_DeviceEvent event, void *refCon);
void DeviceEventHandlerDemo();
// This function is called if an event happens
void MyDeviceEventFunction(I1_DeviceHandle devHndl, I1_DeviceEvent event, void *refCon)
{
// increase our event counter
int *eventCounter = static_cast<int*>(refCon);
*eventCounter += 1;
std::cout << "Event #" << *eventCounter;
switch(event) {
case eI1ProButtonPressed: std::cout << " 'Button pressed' 0x" << std::hex << devHndl << std::
dec << std::endl; break;
case eI1ProScanReadyToMove:std::cout << " 'Ready to move' 0x" << std::hex << devHndl << std::
dec << std::endl; break;
case eI1ProLampRestore: std::cout << " 'Lamp restore' 0x" << std::hex << devHndl << std::
dec << std::endl; break;
case eI1ProArrival: std::cout << " 'Device attached' 0x" << std::hex << devHndl << std::
dec << std::endl; break;
case eI1ProDeparture: std::cout << " 'Device removed' 0x" << std::hex << devHndl << std::
dec << std::endl; break;
}
}
// This function demonstrates the device event handler usage
void DeviceEventHandlerDemo()
{
std::cout << "\n\n------------------------------" << std::endl;
std::cout << " Device Event Handler demonstration" << std::endl;
int eventCounter = 0; // number of events
// register our event handler with eventCounter
I1_RegisterDeviceEventHandler(&MyDeviceEventFunction, &eventCounter);
// ....
// ....
// ....
// Unregister our event handler
I1_RegisterDeviceEventHandler(NULL, NULL);
}