Changeset 192e299 in thomson


Ignore:
Timestamp:
Feb 3, 2012, 7:37:06 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
c2a9854
Parents:
f9263dd
Message:

Cleanup.

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

Location:
elec/CrO2/software
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/Makefile

    rf9263dd r192e299  
    1414
    1515CC              = g++
    16 CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -g -std=c++0x
    17 LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32
     16CPPFLAGS        = $(USBFLAGS) -O -Wall -I/usr/include/IUP/ -I/local/include -g -std=c++0x -mthreads
     17LIBS    = $(USBLIBS) -L/usr/lib/ -mwindows -liup -lcomctl32 -lole32 -mthreads
    1818
    1919PROJECT = CrO2
  • elec/CrO2/software/cro2.cpp

    rf9263dd r192e299  
    1919int main(int argc, char **argv)
    2020{
    21         int                 nBytes = 0;
    22 
    2321    if(argc < 2){
    2422                Gui gui(&argc, &argv);
     
    3028
    3129                if(strcmp(argv[1], "get") == 0){
     30                        int                 nBytes = 0;
    3231                        unsigned char       buffer[275];
    3332                        memset(buffer, 0, 275);
    3433                        nBytes = dev.read(buffer, sizeof(buffer));
     34                        if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
    3535                }else if(strcmp(argv[1], "put") == 0){
    3636
     
    3838                        K5 file(argv[2]);
    3939
    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);
    5341                }else{
    5442                        // TODO print usage
     
    5644                }
    5745
    58                 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
    5946                return 0;
    6047        }
  • elec/CrO2/software/device.cpp

    rf9263dd r192e299  
    88
    99#include "device.h"
     10#include "k5.h"
    1011
    1112bool Device::initOnce = false;
     
    141142}
    142143
     144
     145void 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
    143163uint8_t Device::getStatus()
    144164{
    145165        uint8_t status;
    146166        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);
    148168                // TODO handle errors (return value)
    149169        return status;
  • elec/CrO2/software/device.h

    rf9263dd r192e299  
    88
    99#include <stdint.h>
     10#include <lusb0_usb.h>
    1011
    11 #include <lusb0_usb.h>    /* this is libusb, see http://libusb.sourceforge.net/ */
     12class K5;
    1213
    1314class Device
     
    2021                int read(uint8_t* buffer, size_t max); // Fill the buffer with data from device
    2122                int write(uint8_t* buffer, size_t size, int blktype);
     23                void write(K5& file);
    2224                uint8_t getStatus();
    2325
  • elec/CrO2/software/gui.cpp

    rf9263dd r192e299  
    1414
    1515        // Start status poller "thread"
    16         int pollStatus(Ihandle* ih)
    17         {
     16int pollStatus(Ihandle* ih)
     17{
     18        try {
    1819                Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
    1920
     
    2324                else
    2425                        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
    2631        }
     32        return IUP_DEFAULT;
     33}
    2734
    2835void startPolling(Ihandle* target) {
     
    3744
    3845/* UI */
    39 
    40 int Gui::menu_exit()
    41 {
    42         return IUP_CLOSE;
    43 }
    4446
    4547Gui::Gui(int* argc, char*** argv)
     
    6668        );
    6769
    68 
    6970        // CONTROL
    7071        Ihandle* motoron = IupProgressBar();
     
    8182        IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
    8283
     84        Ihandle* playToggle = IupToggle("play", NULL);
     85        Callback<Gui, int>::create(playToggle, "ACTION", this, &Gui::setPlaying);
     86
    8387        Ihandle* tabs = IupTabs(
    8488                IupVbox(
     
    8993                        ),
    9094                        IupHbox(
    91                                 IupToggle("play",NULL),
     95                                playToggle,
    9296                                IupToggle("REC",NULL),
    9397                                NULL
     
    136140}
    137141
     142
    138143int Gui::menu_open()
    139144{
     
    147152        return IUP_DEFAULT;
    148153}
     154
     155int Gui::menu_exit()
     156{
     157        return IUP_CLOSE;
     158}
     159
     160int 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  
    2020                int menu_exit();
    2121
     22                int setPlaying(int state);
     23
    2224                K5* file;
    2325};
  • elec/CrO2/software/k5.cpp

    rf9263dd r192e299  
    2323        data = new uint8_t[length];
    2424        memcpy(data, other.data, length);
     25}
     26
     27const 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;
    2538}
    2639
  • elec/CrO2/software/k5.h

    rf9263dd r192e299  
    1717                                Block(const Block& other);
    1818                                ~Block();
     19                                const Block& operator=(const Block& other);
    1920
    2021                                int length;
    2122                                uint8_t* data;
    2223                                uint8_t type;
     24                        private:
     25                                Block();
    2326                };
    2427
     
    2730
    2831        private:
     32                K5();
    2933                std::vector<Block> blocks;
    3034};
Note: See TracChangeset for help on using the changeset viewer.