[Libphidget-cvs-commits] CVS: libphidget/src/examples servo_example.cc,1.3,1.4
Status: Alpha
Brought to you by:
jstrohm
From: Jack S. <js...@us...> - 2002-09-12 03:19:51
|
Update of /cvsroot/libphidget/libphidget/src/examples In directory usw-pr-cvs1:/tmp/cvs-serv14596 Modified Files: servo_example.cc Log Message: One more example Index: servo_example.cc =================================================================== RCS file: /cvsroot/libphidget/libphidget/src/examples/servo_example.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** servo_example.cc 12 Sep 2002 03:02:22 -0000 1.3 --- servo_example.cc 12 Sep 2002 03:19:48 -0000 1.4 *************** *** 88,91 **** --- 88,133 ---- } + /** + * A derived class that is a servo + */ + void example3() + { + class CMyServo : public CServo + { + public: + CMyServo(const CUID &uid) : + CServo(uid) + { + printf(" CMyServo: constructed\n"); + } + ~CMyServo() + { + printf(" CMyServo: destructor\n"); + } + void position(float f) + { + CServo::position(f); + printf(" CMyServo: position(%f)\n",f); + } + }; + + printf("example 3 - Bit more complex, construct our own derived servo\n"); + + // We have this brace to make sure all the stack objects get destroyed before we call cleanup, + // cleanup will throw an exception when it is called and objects are still out in the "world" + { + printf(" Request servo #0 from the servo controller\n"); + CMyServo servo(CUID(servoPhidgetID.serial(),0)); + + printf(" Center it.\n"); + servo.position(.5); + + printf(" Wait for it to move before we destroy the servo object (and thus by default disable the servo).\n"); + sleep(1); + } + + cleanup(); + }; + /** *************** *** 109,112 **** --- 151,155 ---- example1(); example2(); + example3(); } catch(const exception &e) |