#include "stdafx.h"
#include "phidget21.h"
#include <time.h>
//callback that will run if the acceleration changes by more than the Acceleration trigger.
//Index - Index of the axis that is generating the event, Value - the value read by the accelerometer axis
int __stdcall accel_AccelChangeHandler(CPhidgetAccelerometerHandle WGT, void *userptr, int Index, double Value)
{
clock_t clock();
printf("Time: %i Axis: %i Accel: %6f\n",clock()/CLOCKS_PER_SEC, Index, Value);
return 0;
}
//main entry point to the program
int _tmain(int argc, _TCHAR* argv[])
{
int result;
const char *err;
//Declare an accelerometer handle
CPhidgetAccelerometerHandle accel = 0;
//create the accelerometer object
CPhidgetAccelerometer_create(&accel);
//Impostando -1 apre il primo dispositivo disponibile
CPhidget_open((CPhidgetHandle)accel, -1);
//get the program to wait for an accelerometer device to be attached
printf("Waiting for accelerometer to be attached.... \n\n");
//Aspetta 10 secondi che venga connesso il dispositivo
if((result = CPhidget_waitForAttachment((CPhidgetHandle)accel, 10000)))
{ CPhidget_getErrorDescription(result, &err);
printf("Problem waiting for attachment: %s\n", err);
//Interruzione, spingere invio per continuare
getchar();
return 0;}
//Imposta la sensibilità
CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 0, 0.500);
CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 1, 0.500);
CPhidgetAccelerometer_setAccelerationChangeTrigger(accel, 2, 0.500);
//Registra un evento se l'accelerazione cambia oltre una certa soglia.
CPhidgetAccelerometer_set_OnAccelerationChange_Handler(accel, accel_AccelChangeHandler, NULL);
//Interruzione
getchar();
//Chiude il dispositivo e l'oggetto
printf("Closing...\n");
CPhidget_close((CPhidgetHandle)accel);
CPhidget_delete((CPhidgetHandle)accel);
//Interruzione
getchar();
return 0;
}