Changeset 6bd7144 in thomson


Ignore:
Timestamp:
Jan 22, 2013, 6:25:57 PM (11 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
65a4aad
Parents:
e017851
Message:

More work on Haiku port

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

Location:
elec/CrO2/software
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/device_bekit.cpp

    re017851 r6bd7144  
    1313#include <USBKit.h>
    1414
     15class DeviceScanner: public BUSBRoster
     16{
     17        public:
     18                DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product);
     19
     20                // BUSBRoster
     21                status_t DeviceAdded(BUSBDevice* device);
     22                void DeviceRemoved(BUSBDevice* device);
     23
     24                BUSBDevice* handle;
     25        private:
     26                uint32_t vid, pid;
     27                const char* vendor, *product;
     28};
    1529
    1630// Gets the device instance. Throws an error message if something bad happens.
     
    1832{
    1933        if (instance == NULL) {
    20                 instance = new HaikuDevice();
     34                DeviceScanner* scanner = new DeviceScanner(vid, pid, vendor, product);
     35
     36                while(scanner->handle == NULL); // FIXME don't hog CPU, and timeout
     37                //throw "Device not found. Is the USB cable plugged correctly?";
     38
     39                // We have our device, don't need the roster anymore.
     40                delete scanner;
     41
     42                instance = new HaikuDevice(scanner->handle);
    2143        }
    2244
     
    2547
    2648
    27 HaikuDevice::HaikuDevice() throw(const char*)
     49HaikuDevice::HaikuDevice(BUSBDevice* handle) throw(const char*)
    2850{
    29         // At this point, either we have found a device and handle is pointing to it,
    30         // or we failed and handle is NULL.
    31         if (!handle)
    32                 throw "Device not found. Is the USB cable plugged correctly?";
     51        this->handle = handle;
    3352}
    3453
     
    6786
    6887
    69 status_t HaikuDevice::DeviceAdded(BUSBDevice* device)
     88DeviceScanner::DeviceScanner(uint32_t vid, uint32_t pid, const char* vendor, const char* product)
     89        : vid(vid)
     90        , pid(pid)
     91        , vendor(vendor)
     92        , product(product)
     93{
     94}
     95
     96
     97status_t DeviceScanner::DeviceAdded(BUSBDevice* device)
    7098{
    7199        if (handle != NULL) {
     
    94122
    95123
    96 void HaikuDevice::DeviceRemoved(BUSBDevice* device)
     124void DeviceScanner::DeviceRemoved(BUSBDevice* device)
    97125{
    98126        // This is only called for devices we accepted in DeviceAdded. We accept
  • elec/CrO2/software/device_bekit.h

    re017851 r6bd7144  
    1414class Tape;
    1515
    16 class HaikuDevice: public Device, BUSBRoster
     16class HaikuDevice: public Device
    1717{
    1818        public:
     
    2525                uint8_t getStatus();
    2626
    27                 // BUSBRoster
    28                 status_t DeviceAdded(BUSBDevice* device);
    29                 void DeviceRemoved(BUSBDevice* device);
    3027        private:
    31                 HaikuDevice() throw(const char*);
     28                HaikuDevice(BUSBDevice* handle) throw(const char*);
    3229                        // Open device and set it up for communication
    3330                HaikuDevice(const Device& other);
  • elec/CrO2/software/gui.cpp

    re017851 r6bd7144  
    2020int pollStatus(Ihandle* ih)
    2121{
     22        uint8_t status;
    2223        try {
    23                 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
    24 
    25                 uint8_t status = Device::getDevice().getStatus();
    26                 if (status & 8)
    27                         IupSetAttribute(motoron, "VALUE", "0"); // motor OFF
    28                 else
    29                         IupSetAttribute(motoron, "VALUE", "1"); // motor ON
    30         } catch(const char*) {
     24                Device& dev = Device::getDevice();
     25                status = dev.getStatus();
     26        } catch(const char* ex) {
    3127                // Silently ignore exception if device is not available - not a good
    3228                // idea to handle it from a timer...
    3329                // Keep the timer running so it starts working when the device is
    3430                // plugged
    35         }
     31                return IUP_DEFAULT;
     32        }
     33
     34        Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
     35        if (status & 8)
     36                IupSetAttribute(motoron, "VALUE", "0"); // motor OFF
     37        else
     38                IupSetAttribute(motoron, "VALUE", "1"); // motor ON
    3639        return IUP_DEFAULT;
    3740}
     41
    3842
    3943void startPolling(Ihandle* target) {
Note: See TracChangeset for help on using the changeset viewer.