[Libphidget-cvs-commits] CVS: libphidget/src/examples ik2lcd.cc,NONE,1.1
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2002-12-17 03:09:33
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory sc8-pr-cvs1:/tmp/cvs-serv29347/examples Added Files: ik2lcd.cc Log Message: This is a new example to show how to use 2 phidgets together. It requires an interface kit with 8 digital inputs and a TextLCD When running, it will accept digital input on phidget and send to the text lcd information about which inputs and what values are changing. --- NEW FILE: ik2lcd.cc --- #include <CPhidgetManager.h> #include <CInterfaceKit.h> #include <CDigitalIn.h> #include <CDigitalOut.h> #include <CAnalogIn.h> #include <CTextLCD.h> #include <unistd.h> static const char *revision="$Revision: 1.1 $"; CUID ikId; CUID textLCDId; /** * Find the first servo controller we can */ void findUsablePhidgets() { { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_INTERFACE_KIT_488); if (temp.size()<1) throw runtime_error("This application can't run without a phidget interface kit (see http://www.phidgets.com).\n"); ikId=temp[0]; printf("Interface Kit Controller found: %s\n",ikId.asString().c_str()); } { // Look for a servo that we can use for all the examples vector<CUID> temp=CPhidgetManager::getInstance()->query(LP_TEXT_LCD); if (temp.size()<1) throw runtime_error("This application can't run without a phidget text lcd kit (see http://www.phidgets.com).\n"); textLCDId=temp[0]; printf("Text LCD found: %s\n",textLCDId.asString().c_str()); } } // this shows how to overload a digital input to catch change value events class CMyDigitalIn : public CDigitalIn { public: CTextLCD &_lcd; CMyDigitalIn ( const CUID &uid, CTextLCD &lcd) : CDigitalIn(uid), _lcd(lcd) { } void onChange() { char temp[12]; _lcd.sendText(" ",0,0); _lcd.sendText(" ",1,0); sprintf(temp,"Input %d\n",cardinal()); _lcd.sendText(temp,0,0); if (value()) _lcd.sendText("Value:On ",1,0); else _lcd.sendText("Value:Off",1,0); } }; main() { try { char adjusted_version[64]; memcpy(adjusted_version,revision+11,strlen(revision)-11-2); adjusted_version[strlen(revision)-11-2]=0; // What we are printf("ik_example: code examples of how to communicate with interface kits\n"); // Get the version number printf("Version %s\n",adjusted_version); findUsablePhidgets(); CInterfaceKit kit(ikId); CTextLCD lcd(textLCDId); CMyDigitalIn *din[8]; lcd.on(); for (int t=0;t<8;t++) din[t]=new CMyDigitalIn(CUID(ikId.serial(),t+4),lcd); while (1) kit.update(); // won't get here for (int t=0;t<8;t++) delete din[t]; } catch(const exception &e) { printf("exception:%s\n",e.what()); } } |