Changeset 5e633b6 in thomson


Ignore:
Timestamp:
Jan 24, 2012, 9:01:07 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
96bc8fa
Parents:
197a1cc
Message:

WIP GUI

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

Location:
elec/CrO2/software
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Makefile

    r197a1cc r5e633b6  
    1313endif
    1414
    15 CC              = gcc
    16 CFLAGS  = $(USBFLAGS) -O -Wall -std=c99
    17 LIBS    = $(USBLIBS)
     15CC              = g++
     16CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/
     17LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32
    1818
    1919PROJECT = CrO2
     
    2222
    2323all: $(PROGRAM)
    24 
    25 .c.o:
    26         $(CC) $(CFLAGS) -c $<
    2724
    2825$(PROGRAM): $(PROJECT).o
  • elec/CrO2/software/cro2.cpp

    r197a1cc r5e633b6  
    2323#include <unistd.h>
    2424
     25#include <iup.h>
     26#include <iupcontrols.h>
     27
    2528#include <lusb0_usb.h>    /* this is libusb, see http://libusb.sourceforge.net/ */
    2629
     
    3134 */
    3235
    33 #define VENDORSTRING "pulkomandy.ath.cx"
     36#define VENDORSTRING (char*)"pulkomandy.ath.cx"
    3437#define PRODUCTSTRING "CrO2"
    3538
     
    3942#define PSCMD_PUT   2
    4043#define PSCMD_STATUS   3
    41 
    42 static void usage(char *name)
    43 {
    44     fprintf(stderr, "usage:\n");
    45     fprintf(stderr, "  %s status\n", name);
    46     fprintf(stderr, "  %s on <port> [<duration>]\n", name);
    47     fprintf(stderr, "  %s off <port> [<duration>]\n", name);
    48     fprintf(stderr, "  %s test\n\n", name);
    49     fprintf(stderr, "Ports are single digits in the range 0...7\n");
    50     fprintf(stderr, "The pulse duration for switching temporarily is given in seconds.\n");
    51 }
    52 
    5344
    5445static int  usbGetStringAscii(usb_dev_handle *dev, int index, int langid, char *buf, int buflen)
     
    156147}
    157148
     149
     150int menu_open(Ihandle* that)
     151{
     152        IupPopup(IupFileDlg(), IUP_CENTER, IUP_CENTER);
     153        return IUP_DEFAULT;
     154}
     155
     156
     157void GUI_open(int* argc, char*** argv)
     158{
     159        IupOpen(argc, argv);
     160//      IupControlsOpen();
     161
     162        IupSetFunction("OPEN", menu_open);
     163
     164        Ihandle* menu = IupMenu(
     165                IupSubmenu("File",
     166                        IupMenu(
     167                                IupItem("Open", "OPEN"),               
     168                                IupItem("Exit", "IUP_CLOSE"),
     169                                NULL
     170                        )
     171                ),
     172                NULL
     173        );
     174
     175        Ihandle* platformlist = IupList(NULL);
     176        IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL");
     177        IupSetAttribute(platformlist, "DROPDOWN", "YES");
     178        IupSetAttribute(platformlist, "1", "MO5");
     179        IupSetAttribute(platformlist, "VALUE", "1");
     180
     181        Ihandle* blocklist = IupTree();
     182        IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
     183
     184        Ihandle* tabs = IupTabs(
     185                IupVbox(
     186                        IupLabel("Hello World"),
     187                        NULL
     188                ),
     189                IupVbox(
     190                        IupHbox(
     191                                IupLabel("Format:"),
     192                                platformlist,
     193                                NULL
     194                        ),
     195                        IupHbox(
     196                                blocklist,
     197                                IupVbox(
     198//                                      IupMatrix(NULL),
     199                                        IupLabel("Checksum:"),
     200                                        NULL
     201                                ),
     202                                NULL
     203                        )
     204                ),
     205                NULL
     206        );
     207
     208        IupSetAttribute(tabs,"TABTITLE0", "Control");
     209        IupSetAttribute(tabs,"TABTITLE1", "Explore");
     210
     211        Ihandle* dialog = IupDialog(tabs);
     212        IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator");
     213        IupSetAttributeHandle(dialog, "MENU", menu);
     214        IupShow(dialog);
     215
     216        IupMainLoop();
     217
     218        IupClose();
     219}
     220
     221
    158222int main(int argc, char **argv)
    159223{
    160 usb_dev_handle      *handle = NULL;
    161 unsigned char       buffer[275];
    162 int                 nBytes;
     224        usb_dev_handle      *handle = NULL;
     225        unsigned char       buffer[275];
     226        int                 nBytes = 0;
    163227
    164228    if(argc < 2){
    165         usage(argv[0]);
    166         exit(1);
     229                GUI_open(&argc, &argv);
     230                exit(0);
    167231    }
    168232    usb_init();
    169     if(usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, VENDORSTRING, USBDEV_SHARED_PRODUCT, PRODUCTSTRING) != 0){
     233    if(usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, VENDORSTRING, USBDEV_SHARED_PRODUCT, (char*)PRODUCTSTRING) != 0){
    170234        fprintf(stderr, "Could not find USB device \""PRODUCTSTRING"\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
    171235        exit(1);
     
    227291                nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | rqtype, PSCMD_PUT, blktype,0 /*checksum*/, (char*)buffer, blksize, 5000);
    228292    }else{
    229                 fprintf(stderr,"Unknown command: %s.\n", argv[1]);
    230                 usage(argv[0]);
    231                 nBytes = 0;
    232                 // TODO manage return code
     293                GUI_open(&argc, &argv);
    233294    }
    234295
Note: See TracChangeset for help on using the changeset viewer.