diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-04-14 12:56:48 +0100 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-04-14 12:56:48 +0100 |
commit | 0b624384cd52be20e61284551d832b499d7b7707 (patch) | |
tree | 6f95a4bbef47abc9720b96c0722e8f632aef228a /examples/manager.c | |
download | libphidget21-0b624384cd52be20e61284551d832b499d7b7707.tar.gz |
Imported Upstream version 2.1.8.20120216upstream/2.1.8.20120216
Diffstat (limited to '')
-rw-r--r-- | examples/manager.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/examples/manager.c b/examples/manager.c new file mode 100644 index 0000000..412b7de --- /dev/null +++ b/examples/manager.c @@ -0,0 +1,73 @@ +/* +* manager.cpp +* +* Patrick McNeil - July 19, 2005 +* +* Simple program to list all Phidgets that are added and removed from the system +*/ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "phidget21.h" +#include <signal.h> + +int something; +static int exitMan = 0; + +void sighandler (int n) +{ + printf ("got a signal. exiting.\n"); + exitMan = 1; +} + +int gotAttach(CPhidgetHandle phid, void *ptr) { + const char *id, *label; + int serial, version; + + //print out some info + CPhidget_getDeviceLabel(phid, &label); + CPhidget_getSerialNumber(phid, &serial); + CPhidget_getDeviceVersion(phid, &version); + CPhidget_getDeviceType(phid, &id); + printf("Device Added: %s, Serial: %d, Version: %d Label: %s\n",id,serial,version,label); + + return 0; +} + +int gotDetach(CPhidgetHandle phid, void *ptr) { + char *id; + int serial, version; + + //print out some info + CPhidget_getSerialNumber(phid, &serial); + CPhidget_getDeviceVersion(phid, &version); + CPhidget_getDeviceType((CPhidgetHandle)phid,(const char **)&id); + printf("Device Removed: %s, Serial: %d, Version: %d\n",id,serial,version); + + return 0; +} + + +int main() +{ + CPhidgetManagerHandle phidm; + + //CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL); + + CPhidgetManager_create(&phidm); + CPhidgetManager_set_OnAttach_Handler(phidm, gotAttach, NULL); + CPhidgetManager_set_OnDetach_Handler(phidm, gotDetach, NULL); + CPhidgetManager_open(phidm); + + signal (SIGTERM, sighandler); + signal (SIGINT, sighandler); + +while(!exitMan) + sleep(5); + + printf ("Removing resources.\n"); + CPhidgetManager_close(phidm); + CPhidgetManager_delete(phidm); + return 0; +} |