Changeset 13 in Thomson
- Timestamp:
- 29/01/2012 18:20:30 (16 months ago)
- Location:
- elec/CrO2/software
- Files:
-
- 2 added
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/Makefile
r12 r13 14 14 15 15 CC = g++ 16 CPPFLAGS = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ 16 CPPFLAGS = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -g 17 17 LIBS = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32 18 18 … … 23 23 all: $(PROGRAM) 24 24 25 $(PROGRAM): $(PROJECT).o device.o poller.o25 $(PROGRAM): $(PROJECT).o device.o gui.o k5.o 26 26 $(CC) -o $(PROGRAM) $^ $(LIBS) 27 27 -
elec/CrO2/software/cro2.cpp
r12 r13 12 12 #include <unistd.h> 13 13 14 #include <iup.h>15 #include <iupcontrols.h>16 14 17 15 #include "device.h" 18 #include "poller.h" 19 20 /* UI */ 21 int menu_open(Ihandle* that) 22 { 23 IupPopup(IupFileDlg(), IUP_CENTER, IUP_CENTER); 24 return IUP_DEFAULT; 25 } 26 27 int menu_exit(Ihandle* that) 28 { 29 return IUP_CLOSE; 30 } 31 32 33 Ihandle* motoron; 34 void GUI_open(int* argc, char*** argv) 35 { 36 IupOpen(argc, argv); 37 // IupControlsOpen(); 38 39 IupSetFunction("OPEN", menu_open); 40 IupSetFunction("EXIT", menu_exit); 41 42 Ihandle* menu = IupMenu( 43 IupSubmenu("File", 44 IupMenu( 45 IupItem("Open", "OPEN"), 46 IupItem("Exit", "EXIT"), 47 NULL 48 ) 49 ), 50 NULL 51 ); 52 53 // CONTROL 54 motoron = IupProgressBar(); 55 IupSetAttribute(motoron, "RASTERSIZE", "16x16"); 56 57 // EXPLORE 58 Ihandle* platformlist = IupList(NULL); 59 IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL"); 60 IupSetAttribute(platformlist, "DROPDOWN", "YES"); 61 IupSetAttribute(platformlist, "1", "MO5"); 62 IupSetAttribute(platformlist, "VALUE", "1"); 63 64 Ihandle* blocklist = IupTree(); 65 IupSetAttribute(blocklist, "EXPAND", "VERTICAL"); 66 67 Ihandle* tabs = IupTabs( 68 IupVbox( 69 IupHbox( 70 IupLabel("Motor"), 71 motoron, 72 NULL 73 ), 74 IupHbox( 75 IupToggle("play",NULL), 76 IupToggle("REC",NULL), 77 NULL 78 ), 79 NULL 80 ), 81 IupVbox( 82 IupHbox( 83 IupLabel("Format:"), 84 platformlist, 85 NULL 86 ), 87 IupHbox( 88 blocklist, 89 IupVbox( 90 // IupMatrix(NULL), 91 IupLabel("Checksum:"), 92 NULL 93 ), 94 NULL 95 ) 96 ), 97 NULL 98 ); 99 100 IupSetAttribute(tabs,"TABTITLE0", "Control"); 101 IupSetAttribute(tabs,"TABTITLE1", "Explore"); 102 103 Ihandle* dialog = IupDialog(tabs); 104 IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator"); 105 IupSetAttributeHandle(dialog, "MENU", menu); 106 IupShow(dialog); 107 108 // Run the timer 109 startPolling(); 110 111 IupMainLoop(); 112 113 IupClose(); 114 } 115 16 #include "k5.h" 17 #include "gui.h" 116 18 117 19 int main(int argc, char **argv) 118 20 { 119 //usb_dev_handle *handle = NULL;120 unsigned char buffer[275];121 21 int nBytes = 0; 122 22 123 23 if(argc < 2){ 124 G UI_open(&argc, &argv);24 Gui gui(&argc, &argv); 125 25 exit(0); 126 26 } … … 130 30 131 31 if(strcmp(argv[1], "get") == 0){ 32 unsigned char buffer[275]; 132 33 memset(buffer, 0, 275); 133 34 nBytes = dev.read(buffer, sizeof(buffer)); 134 35 }else if(strcmp(argv[1], "put") == 0){ 135 36 136 // wait for motor on 137 while (dev.getStatus() & 8) 138 usleep(1000000); 37 // load file 38 K5 file(argv[2]); 139 39 140 // load file141 FILE* fptr = fopen(argv[2], "rb");142 int blockid;143 uint8_t blktype, blksize;144 sscanf(argv[3], "%d", &blockid);40 for (int k = 0; k < file.getBlockCount(); k++) 41 { 42 // wait for motor on 43 while (dev.getStatus() & 8) 44 Sleep(1000); 145 45 146 // fast-forward to requested block 147 do 148 { 149 do 150 { 151 fread(&blktype, 1, 1, fptr); 152 if (feof(fptr)) 153 { 154 fprintf(stderr, "end of file.\n"); 155 fclose(fptr); 156 exit(0); 157 } 158 } 159 while(blktype != 0x5A); // skip sync header 46 K5::Block block = file.getBlock(k); 160 47 161 fread(&blktype, 1, 1, fptr); 162 fread(&blksize, 1, 1, fptr); 163 blksize -= 2; 164 fread(buffer, 1, blksize + 1, fptr); 165 if (blktype == 0) 166 { 167 // new file 168 printf("%.11s\n",buffer); 169 } 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); 170 52 } 171 while (blockid --);172 173 fclose(fptr);174 175 nBytes = dev.write(buffer, blksize, blktype);176 53 }else{ 177 54 // TODO print usage … … 186 63 std::cerr << error << std::endl; 187 64 } 65 66 exit(0); 188 67 } 189 68 -
elec/CrO2/software/gui.cpp
r12 r13 1 #include "poller.h" 1 /* CrO2 datassette emulator 2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 3 * 4 * Distributed under the terms of the MIT licence. 5 */ 6 7 #include "gui.h" 2 8 3 9 #include "device.h" 10 #include "k5.h" 4 11 5 12 #include <stdint.h> 6 13 #include <iup.h> 14 #include <iupcontrols.h> 15 16 /////////////////////////////////////////////////////////////////////////////// 17 // Super awesome extended powerful ultimate deluxe C++ IUP callback system ;) 18 19 typedef int (Gui::*Callee)(); 20 21 class Callback 22 { 23 public: 24 static int call(Ihandle* that); 25 static int destroy(Ihandle* that); 26 static void create(Ihandle* handle, const char* name, Gui* self, Callee what); 27 28 private: 29 Callback(Gui* self, Callee what); 30 Callback(); // do not use 31 32 Gui* self; 33 Callee what; 34 }; 35 36 void Callback::create(Ihandle* handle,const char* name, Gui* self, Callee what) 37 { 38 Callback* cb = new Callback(self, what); 39 IupSetAttribute(handle, "LCALLBACK", (char*)cb); 40 IupSetCallback(handle, name, Callback::call); 41 IupSetCallback(handle, "LDESTROY_CB", Callback::destroy); 42 } 43 44 Callback::Callback(Gui* self, Callee what) 45 { 46 this->self = self; 47 this->what = what; 48 } 49 50 int Callback::call(Ihandle* that) 51 { 52 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK"); 53 return ((call->self)->*(call->what))(); 54 } 55 56 int Callback::destroy(Ihandle* that) 57 { 58 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK"); 59 delete call; 60 return IUP_DEFAULT; 61 } 62 63 /////////////////////////////////////////////////////////////////////////////// 7 64 8 65 // Start status poller "thread" 9 66 int pollStatus(Ihandle* ih) 10 67 { 68 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target"); 69 11 70 uint8_t status = Device::getDevice().getStatus(); 12 71 if (status & 8) … … 17 76 } 18 77 19 void startPolling( ) {78 void startPolling(Ihandle* target) { 20 79 Ihandle* timer = IupTimer(); 80 81 IupSetAttribute(timer, "target", (const char*)target); 82 21 83 IupSetAttribute(timer, "TIME", "300"); 22 84 IupSetCallback(timer, "ACTION_CB", pollStatus); 23 85 IupSetAttribute(timer, "RUN", "YES"); 24 86 } 87 88 /* UI */ 89 90 int menu_exit(Ihandle* that) 91 { 92 return IUP_CLOSE; 93 } 94 95 96 97 Gui::Gui(int* argc, char*** argv) 98 { 99 file = NULL; 100 101 IupOpen(argc, argv); 102 // IupControlsOpen(); 103 104 IupSetFunction("EXIT", menu_exit); 105 106 Ihandle* menu_open = IupItem("Open", NULL); 107 Callback::create(menu_open, "ACTION", this, &Gui::menu_open); 108 109 Ihandle* menu = IupMenu( 110 IupSubmenu("File", 111 IupMenu( 112 menu_open, 113 IupItem("Exit", "EXIT"), 114 NULL 115 ) 116 ), 117 NULL 118 ); 119 120 121 // CONTROL 122 Ihandle* motoron = IupProgressBar(); 123 IupSetAttribute(motoron, "RASTERSIZE", "16x16"); 124 125 // EXPLORE 126 Ihandle* platformlist = IupList(NULL); 127 IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL"); 128 IupSetAttribute(platformlist, "DROPDOWN", "YES"); 129 IupSetAttribute(platformlist, "1", "MO5"); 130 IupSetAttribute(platformlist, "VALUE", "1"); 131 132 Ihandle* blocklist = IupTree(); 133 IupSetAttribute(blocklist, "EXPAND", "VERTICAL"); 134 135 Ihandle* tabs = IupTabs( 136 IupVbox( 137 IupHbox( 138 IupLabel("Motor"), 139 motoron, 140 NULL 141 ), 142 IupHbox( 143 IupToggle("play",NULL), 144 IupToggle("REC",NULL), 145 NULL 146 ), 147 NULL 148 ), 149 IupVbox( 150 IupHbox( 151 IupLabel("Format:"), 152 platformlist, 153 NULL 154 ), 155 IupHbox( 156 blocklist, 157 IupVbox( 158 // IupMatrix(NULL), 159 IupLabel("Checksum:"), 160 NULL 161 ), 162 NULL 163 ) 164 ), 165 NULL 166 ); 167 168 IupSetAttribute(tabs,"TABTITLE0", "Control"); 169 IupSetAttribute(tabs,"TABTITLE1", "Explore"); 170 171 Ihandle* dialog = IupDialog(tabs); 172 IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator"); 173 IupSetAttributeHandle(dialog, "MENU", menu); 174 IupShow(dialog); 175 176 // Run the timer 177 startPolling(motoron); 178 179 IupMainLoop(); 180 181 IupClose(); 182 } 183 184 185 Gui::~Gui() 186 { 187 delete file; 188 } 189 190 int Gui::menu_open() 191 { 192 char name[65536]; 193 name[0] = 0; 194 if (IupGetFile(name) == 0) 195 { 196 // Load file 197 file = new K5(name); 198 } 199 return IUP_DEFAULT; 200 } -
elec/CrO2/software/gui.h
r12 r13 1 /* CrO2 datassette emulator 2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 3 * 4 * Distributed under the terms of the MIT licence. 5 */ 6 1 7 #include <iup.h> 2 8 3 void startPolling();9 class K5; 4 10 5 extern Ihandle* motoron; 11 class Gui { 12 public: 13 Gui(int* argc, char*** argv); 14 ~Gui(); 15 16 private: 17 int menu_open(); 18 19 K5* file; 20 };
Note: See TracChangeset
for help on using the changeset viewer.
