1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <phidget21.h>
#include "phidgetmanager.h"
//using namespace phidget;
using namespace std;
PhidgetManager::PhidgetManager() {
// Default constructor
hManager = 0;
// Set debugging data on
CPhidget_enableLogging(PHIDGET_LOG_VERBOSE, NULL);
//create the Manager object
CPhidgetManager_create(&hManager);
//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
CPhidgetManager_set_OnAttach_Handler(hManager, PhidgetManager::attachHandler, hManager);
CPhidgetManager_set_OnDetach_Handler(hManager, PhidgetManager::detachHandler, hManager);
CPhidgetManager_set_OnError_Handler(hManager, PhidgetManager::errorHandler, NULL);
}
PhidgetManager::PhidgetManager(const PhidgetManager& orig) {
}
PhidgetManager::~PhidgetManager() {
/*^*^*^*^^*^*^*^*^*^*^*^*^^*^*^*^*^*^*^*^*^*^^*^*
* Clean up on close - empty the phidgetModule map
**^*^*^^*^*^*^*^*^*^*^*^*^*^^*^*^*^*^*^*^*^*^^*^*^*/
}
int PhidgetManager::attachHandler(CPhidgetHandle phid, void* userPtr){
int serialNo,returnCode;
int* serialNumPtr = &serialNo;
int* const sptr = &serialNo;
const char *name;
CPhidget_DeviceID id;
CPhidget_DeviceClass cls;
phidgetModulesMap mehtodscope_ph;
//PhidgetModuleHandlesStruct hndPhids;
Interface_PhidgetModule* a;
Interface_PhidgetModule* const ptrConstA = a;
a = new PhidgetAccelerometer(phid);
a->createHandle();
returnCode = a->getSerialNumber(serialNumPtr);
// Insert the new Interface_PhidgetModule into phidgetModules container
if (returnCode == 0){
//PhidgetManager::phidgetModules.insert(pair<int,Interface_PhidgetModule*>(serialNo,ptrConstA));
PhidgetManager::ph[ serialNo ] = ptrConstA; //<== this causes problems, Class scope ph
methodscope_ph[serialNo] = ptrConstA; //<=======This works, method scope
}
|