Changeset c7b4218 in thomson


Ignore:
Timestamp:
Jan 29, 2012, 6:20:30 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
f9263dd
Parents:
32c7682
Message:
  • Move GUI in its own class
  • Design C++ callbacksystem for IUP
  • Load file from menu

git-svn-id: svn://localhost/thomson@13 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

Location:
elec/CrO2/software
Files:
4 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Makefile

    r32c7682 rc7b4218  
    1414
    1515CC              = g++
    16 CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/
     16CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -g
    1717LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32
    1818
     
    2323all: $(PROGRAM)
    2424
    25 $(PROGRAM): $(PROJECT).o device.o poller.o
     25$(PROGRAM): $(PROJECT).o device.o gui.o k5.o
    2626        $(CC) -o $(PROGRAM) $^ $(LIBS)
    2727
  • elec/CrO2/software/cro2.cpp

    r32c7682 rc7b4218  
    1212#include <unistd.h>
    1313
    14 #include <iup.h>
    15 #include <iupcontrols.h>
    1614
    1715#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"
    11618
    11719int main(int argc, char **argv)
    11820{
    119         //usb_dev_handle      *handle = NULL;
    120         unsigned char       buffer[275];
    12121        int                 nBytes = 0;
    12222
    12323    if(argc < 2){
    124                 GUI_open(&argc, &argv);
     24                Gui gui(&argc, &argv);
    12525                exit(0);
    12626    }
     
    13030
    13131                if(strcmp(argv[1], "get") == 0){
     32                        unsigned char       buffer[275];
    13233                        memset(buffer, 0, 275);
    13334                        nBytes = dev.read(buffer, sizeof(buffer));
    13435                }else if(strcmp(argv[1], "put") == 0){
    13536
    136                         // wait for motor on
    137                         while (dev.getStatus() & 8)
    138                                 usleep(1000000);
     37                        // load file
     38                        K5 file(argv[2]);
    13939
    140                         // load file
    141                         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);
    14545
    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);
    16047
    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);
    17052                        }
    171                         while (blockid --);
    172 
    173                         fclose(fptr);
    174 
    175                         nBytes = dev.write(buffer, blksize, blktype);
    17653                }else{
    17754                        // TODO print usage
     
    18663                std::cerr << error << std::endl;
    18764        }
     65
     66        exit(0);
    18867}
    18968
Note: See TracChangeset for help on using the changeset viewer.