Changeset 20391
- Timestamp:
- 06/29/07 16:32:39 (1 year ago)
- Files:
-
- juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/Makefile (modified) (1 diff)
- juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/buttondevice.cpp (modified) (3 diffs)
- juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/buttondevice.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/Makefile
r19729 r20391 37 37 SRCS= buttondevice.cpp 38 38 39 include $(GADGET_BASE_DIR)/share/gadgeteer/gadget.driver.mk 39 GADGET_BASE_DIR=$(shell flagpoll gadgeteer --get-prefix) 40 GADGET_VERSION= $(shell flagpoll gadgeteer --modversion) 41 42 include $(GADGET_BASE_DIR)/share/gadgeteer-$(GADGET_VERSION)/gadget.driver.mk juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/buttondevice.cpp
r19729 r20391 28 28 29 29 #include <vector> 30 #include <boost/bind.hpp> 30 31 31 32 #include <vpr/vpr.h> … … 79 80 bool ButtonDevice::startSampling() 80 81 { 81 mRunning = true; 82 mSampleThread = new vpr::Thread(threadedSampleFunction, (void*) this); 82 mRunning = false; 83 83 84 if ( ! mSampleThread->valid() )84 try 85 85 { 86 mRunning = false; 87 return false; // thread creation failed 86 mSampleThread = 87 new vpr::Thread(boost::bind(&ButtonDevice::threadedSampleFunction, 88 this)); 89 mRunning = true; 88 90 } 89 else91 catch (vpr::Exception& ex) 90 92 { 91 return true; // thread creation success 93 std::cerr << "Failed to spawn sample thread!\n" << ex.what() 94 << std::endl; 92 95 } 96 97 return mRunning; 93 98 } 94 99 … … 140 145 // This function is declared as a static member of ButtonDevice. It simply 141 146 // calls ButtonDevice::sample() over and over. 142 void ButtonDevice::threadedSampleFunction( void* classPointer)147 void ButtonDevice::threadedSampleFunction() 143 148 { 144 ButtonDevice* this_ptr = static_cast<ButtonDevice*>( classPointer );145 146 149 // spin until someone kills "mSampleThread" 147 while ( this_ptr->mRunning )150 while ( mRunning ) 148 151 { 149 this_ptr->sample();150 vpr::System::sleep(1); //specify some time here, so you don't waste CPU cycles152 sample(); 153 vpr::System::sleep(1); //specify some time here, so you don't waste CPU cycles 151 154 } 152 155 } 153 juggler/branches/2.2/modules/gadgeteer/samples/tutorials/device.drivers/buttondevice.h
r19729 r20391 112 112 /** 113 113 * Our sampling function that is executed by the spawned sample thread. 114 * This function is declared as a static member of ButtonDevice. It simply 115 * calls ButtonDevice::sample() over and over. 114 * This function simply calls ButtonDevice::sample() over and over. 116 115 */ 117 static void threadedSampleFunction(void* classPointer);116 void threadedSampleFunction(); 118 117 119 118 vpr::Thread* mSampleThread;
