openframeworks Phidgets addon

C, C++, and Visual C++
giovannibedetti
Fresh meat
Posts: 1
Joined: Mon Dec 15, 2014 7:59 am
Contact:

openframeworks Phidgets addon

Postby giovannibedetti » Mon Dec 15, 2014 8:15 am

Hello, I'm trying to write a phidgets addon for openframeworks.
I forked an existing repository.

I'm trying to implement the Manager and RFID part of the API.
What I'm trying to do is call an app function when the RFID handler function executes.
the RFID callback that handles a new Tag is:

Code: Select all

static int CCONV TagHandler(CPhidgetRFIDHandle RFID, void *usrptr, char *TagVal, CPhidgetRFID_Protocol proto);

I am creating a new RFID object like this:

Code: Select all

ofxPhidgetsRFID currRFID;
currRFID.init();

The init function is like the one found in the C/C++ example:

Code: Select all

void ofxPhidgetsRFID::init() {
   
   int result;
   const char *err;

   currentTagValue = 0;

   //init newTagRead - no Tags at beginning
   //newTagRead = false;

   //Declare an RFID handle
   CPhidgetRFIDHandle rfid = 0;

   //create the RFID object
   CPhidgetRFID_create(&rfid);

   //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.
   CPhidget_set_OnAttach_Handler((CPhidgetHandle)rfid, AttachHandler, ofAppPtr);
   CPhidget_set_OnDetach_Handler((CPhidgetHandle)rfid, DetachHandler, ofAppPtr);
   CPhidget_set_OnError_Handler((CPhidgetHandle)rfid, ErrorHandler, ofAppPtr);

   //Registers a callback that will run if an output changes.
   //Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
   CPhidgetRFID_set_OnOutputChange_Handler(rfid, OutputChangeHandler, ofAppPtr);

   //Registers a callback that will run when a Tag is read.
   //Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
   CPhidgetRFID_set_OnTag2_Handler(rfid, TagHandler, ofAppPtr);

   //Registers a callback that will run when a Tag is lost (removed from antenna read range).
   //Requires the handle for the PhidgetRFID, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
   CPhidgetRFID_set_OnTagLost2_Handler(rfid, TagLostHandler, ofAppPtr);

   //open the RFID for device connections
   CPhidget_open((CPhidgetHandle)rfid, -1);
   
   //get the program to wait for an RFID device to be attached
   printf("\n1 - Waiting for RFID to be attached....\n");
   if((result = CPhidget_waitForAttachment((CPhidgetHandle)rfid, 100000)))
   {
      CPhidget_getErrorDescription(result, &err);
      printf("\n2 - Problem waiting for attachment:  %s\n", err);
      //return 0;
   }
   
   //Display the properties of the attached RFID device
   display_properties(rfid);

   CPhidgetRFID_setAntennaOn(rfid, 1);

   //read RFID event data
   printf("\n3 - Reading.....\n");

   currRFID = rfid;

   initialized = true;
}


I'm trying to pass the app reference pointer so that I can call an app function when the TagHandler gets a new Tag.
How to do this?

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: openframeworks Phidgets addon

Postby frodegill » Mon Dec 15, 2014 8:43 am

You can search for "OnPhidgetTagHandler" in https://github.com/frodegill/WtPhidgetManager/blob/master/phidgets/phidgets_rfid.cpp

Short story:
Make a C function and use user_ptr to send a pointer to your app


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest