Changeset 192e299 in thomson
- Timestamp:
- Feb 3, 2012, 7:37:06 PM (12 years ago)
- Branches:
- main
- Children:
- c2a9854
- Parents:
- f9263dd
- Location:
- elec/CrO2/software
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/Makefile
rf9263dd r192e299 14 14 15 15 CC = g++ 16 CPPFLAGS = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ - g -std=c++0x17 LIBS = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32 16 CPPFLAGS = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -I/local/include -g -std=c++0x -mthreads 17 LIBS = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32 -mthreads 18 18 19 19 PROJECT = CrO2 -
elec/CrO2/software/cro2.cpp
rf9263dd r192e299 19 19 int main(int argc, char **argv) 20 20 { 21 int nBytes = 0;22 23 21 if(argc < 2){ 24 22 Gui gui(&argc, &argv); … … 30 28 31 29 if(strcmp(argv[1], "get") == 0){ 30 int nBytes = 0; 32 31 unsigned char buffer[275]; 33 32 memset(buffer, 0, 275); 34 33 nBytes = dev.read(buffer, sizeof(buffer)); 34 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror()); 35 35 }else if(strcmp(argv[1], "put") == 0){ 36 36 … … 38 38 K5 file(argv[2]); 39 39 40 for (int k = 0; k < file.getBlockCount(); k++) 41 { 42 // wait for motor on 43 while (dev.getStatus() & 8) 44 Sleep(1000); 45 46 K5::Block block = file.getBlock(k); 47 48 nBytes = dev.write(block.data, block.length - 1, block.type); 49 50 // TODO wait for correct time (read status from usb OR compute from size+type) 51 Sleep(1400); 52 } 40 dev.write(file); 53 41 }else{ 54 42 // TODO print usage … … 56 44 } 57 45 58 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());59 46 return 0; 60 47 } -
elec/CrO2/software/device.cpp
rf9263dd r192e299 8 8 9 9 #include "device.h" 10 #include "k5.h" 10 11 11 12 bool Device::initOnce = false; … … 141 142 } 142 143 144 145 void Device::write(K5& file) 146 { 147 for (int k = 0; k < file.getBlockCount(); k++) 148 { 149 // wait for motor on 150 while (getStatus() & 8) 151 Sleep(1000); 152 153 K5::Block block = file.getBlock(k); 154 155 int nBytes = write(block.data, block.length - 1, block.type); 156 // TODO error handling 157 158 // TODO wait for correct time (read status from usb OR compute from size+type) 159 Sleep(1400); 160 } 161 } 162 143 163 uint8_t Device::getStatus() 144 164 { 145 165 uint8_t status; 146 166 usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, 147 PSCMD_STATUS, 0,0, (char*)&status, 1, 5000);167 PSCMD_STATUS, 0,0, (char*)&status, 1, 5000); 148 168 // TODO handle errors (return value) 149 169 return status; -
elec/CrO2/software/device.h
rf9263dd r192e299 8 8 9 9 #include <stdint.h> 10 #include <lusb0_usb.h> 10 11 11 #include <lusb0_usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */ 12 class K5; 12 13 13 14 class Device … … 20 21 int read(uint8_t* buffer, size_t max); // Fill the buffer with data from device 21 22 int write(uint8_t* buffer, size_t size, int blktype); 23 void write(K5& file); 22 24 uint8_t getStatus(); 23 25 -
elec/CrO2/software/gui.cpp
rf9263dd r192e299 14 14 15 15 // Start status poller "thread" 16 int pollStatus(Ihandle* ih) 17 { 16 int pollStatus(Ihandle* ih) 17 { 18 try { 18 19 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target"); 19 20 … … 23 24 else 24 25 IupSetAttribute(motoron, "VALUE", "1"); // motor ON 25 return IUP_DEFAULT; 26 } catch(const char*) { 27 // Silently ignore exception if device is not available - not a good 28 // idea to handle it from a timer... 29 // Keep the timer running so it starts working when the device is 30 // plugged 26 31 } 32 return IUP_DEFAULT; 33 } 27 34 28 35 void startPolling(Ihandle* target) { … … 37 44 38 45 /* UI */ 39 40 int Gui::menu_exit()41 {42 return IUP_CLOSE;43 }44 46 45 47 Gui::Gui(int* argc, char*** argv) … … 66 68 ); 67 69 68 69 70 // CONTROL 70 71 Ihandle* motoron = IupProgressBar(); … … 81 82 IupSetAttribute(blocklist, "EXPAND", "VERTICAL"); 82 83 84 Ihandle* playToggle = IupToggle("play", NULL); 85 Callback<Gui, int>::create(playToggle, "ACTION", this, &Gui::setPlaying); 86 83 87 Ihandle* tabs = IupTabs( 84 88 IupVbox( … … 89 93 ), 90 94 IupHbox( 91 IupToggle("play",NULL),95 playToggle, 92 96 IupToggle("REC",NULL), 93 97 NULL … … 136 140 } 137 141 142 138 143 int Gui::menu_open() 139 144 { … … 147 152 return IUP_DEFAULT; 148 153 } 154 155 int Gui::menu_exit() 156 { 157 return IUP_CLOSE; 158 } 159 160 int Gui::setPlaying(int state) 161 { 162 if (state == 0) 163 { 164 // pause 165 } else { 166 // play 167 Device::getDevice().write(*file); 168 } 169 170 return IUP_DEFAULT; 171 } -
elec/CrO2/software/gui.h
rf9263dd r192e299 20 20 int menu_exit(); 21 21 22 int setPlaying(int state); 23 22 24 K5* file; 23 25 }; -
elec/CrO2/software/k5.cpp
rf9263dd r192e299 23 23 data = new uint8_t[length]; 24 24 memcpy(data, other.data, length); 25 } 26 27 const K5::Block& K5::Block::operator=(const Block& other) 28 { 29 delete[] data; 30 // May not be null ? 31 32 length = other.length; 33 type = other.type; 34 data = new uint8_t[length]; 35 memcpy(data, other.data, length); 36 37 return *this; 25 38 } 26 39 -
elec/CrO2/software/k5.h
rf9263dd r192e299 17 17 Block(const Block& other); 18 18 ~Block(); 19 const Block& operator=(const Block& other); 19 20 20 21 int length; 21 22 uint8_t* data; 22 23 uint8_t type; 24 private: 25 Block(); 23 26 }; 24 27 … … 27 30 28 31 private: 32 K5(); 29 33 std::vector<Block> blocks; 30 34 };
Note:
See TracChangeset
for help on using the changeset viewer.