ker-on.c
changeset 44 1983a3cc0647
parent 37 d05ba048cb2d
equal deleted inserted replaced
43:7330bec02cfc 44:1983a3cc0647
     9 // view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
     9 // view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
    10 
    10 
    11 #include <stdio.h>
    11 #include <stdio.h>
    12 #include <phidget21.h>
    12 #include <phidget21.h>
    13 
    13 
    14 int CCONV AttachHandler(CPhidgetHandle IFK, void *userptr)
    14 int  AttachHandler(CPhidgetHandle IFK, void *userptr)
    15 {
    15 {
    16 	int serialNo;
    16 	int serialNo;
    17 	const char *name;
    17 	const char *name;
    18 
    18 
    19 	CPhidget_getDeviceName(IFK, &name);
    19 	CPhidget_getDeviceName(IFK, &name);
    22 	printf("%s %10d attached!\n", name, serialNo);
    22 	printf("%s %10d attached!\n", name, serialNo);
    23 
    23 
    24 	return 0;
    24 	return 0;
    25 }
    25 }
    26 
    26 
    27 int CCONV DetachHandler(CPhidgetHandle IFK, void *userptr)
    27 int  DetachHandler(CPhidgetHandle IFK, void *userptr)
    28 {
    28 {
    29 	int serialNo;
    29 	int serialNo;
    30 	const char *name;
    30 	const char *name;
    31 
    31 
    32 	CPhidget_getDeviceName (IFK, &name);
    32 	CPhidget_getDeviceName (IFK, &name);
    35 	printf("%s %10d detached!\n", name, serialNo);
    35 	printf("%s %10d detached!\n", name, serialNo);
    36 
    36 
    37 	return 0;
    37 	return 0;
    38 }
    38 }
    39 
    39 
    40 int CCONV ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
    40 int  ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
    41 {
    41 {
    42 	printf("Error handled. %d - %s", ErrorCode, unknown);
    42 	printf("Error handled. %d - %s", ErrorCode, unknown);
    43 	return 0;
    43 	return 0;
    44 }
    44 }
    45 
    45 
    46 //callback that will run if an input changes.
    46 //callback that will run if an input changes.
    47 //Index - Index of the input that generated the event, State - boolean (0 or 1) representing the input state (on or off)
    47 //Index - Index of the input that generated the event, State - boolean (0 or 1) representing the input state (on or off)
    48 int CCONV InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
    48 int  InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
    49 {
    49 {
    50 	printf("Digital Input: %d > State: %d\n", Index, State);
    50 	printf("Digital Input: %d > State: %d\n", Index, State);
    51 	return 0;
    51 	return 0;
    52 }
    52 }
    53 
    53 
    54 //callback that will run if an output changes.
    54 //callback that will run if an output changes.
    55 //Index - Index of the output that generated the event, State - boolean (0 or 1) representing the output state (on or off)
    55 //Index - Index of the output that generated the event, State - boolean (0 or 1) representing the output state (on or off)
    56 int CCONV OutputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
    56 int  OutputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
    57 {
    57 {
    58 	printf("Digital Output: %d > State: %d\n", Index, State);
    58 	printf("Digital Output: %d > State: %d\n", Index, State);
    59 	return 0;
    59 	return 0;
    60 }
    60 }
    61 
    61 
    62 //callback that will run if the sensor value changes by more than the OnSensorChange trigger.
    62 //callback that will run if the sensor value changes by more than the OnSensorChange trigger.
    63 //Index - Index of the sensor that generated the event, Value - the sensor read value
    63 //Index - Index of the sensor that generated the event, Value - the sensor read value
    64 int CCONV SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
    64 int  SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
    65 {
    65 {
    66 	printf("Sensor: %d > Value: %d\n", Index, Value);
    66 	printf("Sensor: %d > Value: %d\n", Index, Value);
    67 	return 0;
    67 	return 0;
    68 }
    68 }
    69 
    69