Changeset 6bd7144 in thomson
- Timestamp:
- Jan 22, 2013, 6:25:57 PM (11 years ago)
- Branches:
- main
- Children:
- 65a4aad
- Parents:
- e017851
- Location:
- elec/CrO2/software
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/device_bekit.cpp
re017851 r6bd7144 13 13 #include <USBKit.h> 14 14 15 class DeviceScanner: public BUSBRoster 16 { 17 public: 18 DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product); 19 20 // BUSBRoster 21 status_t DeviceAdded(BUSBDevice* device); 22 void DeviceRemoved(BUSBDevice* device); 23 24 BUSBDevice* handle; 25 private: 26 uint32_t vid, pid; 27 const char* vendor, *product; 28 }; 15 29 16 30 // Gets the device instance. Throws an error message if something bad happens. … … 18 32 { 19 33 if (instance == NULL) { 20 instance = new HaikuDevice(); 34 DeviceScanner* scanner = new DeviceScanner(vid, pid, vendor, product); 35 36 while(scanner->handle == NULL); // FIXME don't hog CPU, and timeout 37 //throw "Device not found. Is the USB cable plugged correctly?"; 38 39 // We have our device, don't need the roster anymore. 40 delete scanner; 41 42 instance = new HaikuDevice(scanner->handle); 21 43 } 22 44 … … 25 47 26 48 27 HaikuDevice::HaikuDevice( ) throw(const char*)49 HaikuDevice::HaikuDevice(BUSBDevice* handle) throw(const char*) 28 50 { 29 // At this point, either we have found a device and handle is pointing to it, 30 // or we failed and handle is NULL. 31 if (!handle) 32 throw "Device not found. Is the USB cable plugged correctly?"; 51 this->handle = handle; 33 52 } 34 53 … … 67 86 68 87 69 status_t HaikuDevice::DeviceAdded(BUSBDevice* device) 88 DeviceScanner::DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product) 89 : vid(vid) 90 , pid(pid) 91 , vendor(vendor) 92 , product(product) 93 { 94 } 95 96 97 status_t DeviceScanner::DeviceAdded(BUSBDevice* device) 70 98 { 71 99 if (handle != NULL) { … … 94 122 95 123 96 void HaikuDevice::DeviceRemoved(BUSBDevice* device)124 void DeviceScanner::DeviceRemoved(BUSBDevice* device) 97 125 { 98 126 // This is only called for devices we accepted in DeviceAdded. We accept -
elec/CrO2/software/device_bekit.h
re017851 r6bd7144 14 14 class Tape; 15 15 16 class HaikuDevice: public Device , BUSBRoster16 class HaikuDevice: public Device 17 17 { 18 18 public: … … 25 25 uint8_t getStatus(); 26 26 27 // BUSBRoster28 status_t DeviceAdded(BUSBDevice* device);29 void DeviceRemoved(BUSBDevice* device);30 27 private: 31 HaikuDevice( ) throw(const char*);28 HaikuDevice(BUSBDevice* handle) throw(const char*); 32 29 // Open device and set it up for communication 33 30 HaikuDevice(const Device& other); -
elec/CrO2/software/gui.cpp
re017851 r6bd7144 20 20 int pollStatus(Ihandle* ih) 21 21 { 22 uint8_t status; 22 23 try { 23 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target"); 24 25 uint8_t status = Device::getDevice().getStatus(); 26 if (status & 8) 27 IupSetAttribute(motoron, "VALUE", "0"); // motor OFF 28 else 29 IupSetAttribute(motoron, "VALUE", "1"); // motor ON 30 } catch(const char*) { 24 Device& dev = Device::getDevice(); 25 status = dev.getStatus(); 26 } catch(const char* ex) { 31 27 // Silently ignore exception if device is not available - not a good 32 28 // idea to handle it from a timer... 33 29 // Keep the timer running so it starts working when the device is 34 30 // plugged 35 } 31 return IUP_DEFAULT; 32 } 33 34 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target"); 35 if (status & 8) 36 IupSetAttribute(motoron, "VALUE", "0"); // motor OFF 37 else 38 IupSetAttribute(motoron, "VALUE", "1"); // motor ON 36 39 return IUP_DEFAULT; 37 40 } 41 38 42 39 43 void startPolling(Ihandle* target) {
Note:
See TracChangeset
for help on using the changeset viewer.