# HG changeset patch # User sl # Date 1400742751 -7200 # Node ID 63972dc163503e6e859c510817742345862b6f4f # Parent 21033ded8f8634ff7c03770e845ba49deb2396ef Adding read functionnality to our HidDevice. Fixing some state issues upon connection. diff -r 21033ded8f86 -r 63972dc16350 inc/HidDevice.h --- a/inc/HidDevice.h Thu May 22 08:45:14 2014 +0200 +++ b/inc/HidDevice.h Thu May 22 09:12:31 2014 +0200 @@ -23,7 +23,10 @@ bool IsOpen(); // int SetNonBlocking(int aNonBlocking); - // + //Read + template + int Read(HidReport& aInputReport); + //Write template int Write(const HidReport& aOutputReport); // @@ -54,5 +57,13 @@ return hid_write(iHidDevice,aOutputReport.Buffer(),S); } +/** +*/ +template +int HidDevice::Read(HidReport& aInputReport) + { + return hid_read(iHidDevice,aInputReport.Buffer(),S); + } + #endif \ No newline at end of file diff -r 21033ded8f86 -r 63972dc16350 inc/HidReport.h --- a/inc/HidReport.h Thu May 22 08:45:14 2014 +0200 +++ b/inc/HidReport.h Thu May 22 09:12:31 2014 +0200 @@ -16,6 +16,7 @@ inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} const unsigned char* Buffer() const {return iBuffer;}; unsigned char* Buffer() {return iBuffer;}; + int Size() {return S;} protected: unsigned char iBuffer[S]; }; diff -r 21033ded8f86 -r 63972dc16350 src/test.cpp --- a/src/test.cpp Thu May 22 08:45:14 2014 +0200 +++ b/src/test.cpp Thu May 22 09:12:31 2014 +0200 @@ -90,7 +90,7 @@ connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X); disconnect_button->disable(); - rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X); + rescan_button = new FXButton(buttonVF, "Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X); new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0); connected_label = new FXLabel(vf, "Disconnected"); @@ -227,6 +227,8 @@ // iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; + SetConnectedStates(); + return 1; } @@ -271,17 +273,21 @@ disconnect_button->enable(); input_text->setText(""); // - iButtonClearDisplay->enable(); - iButtonDimming->enable(); - iButtonDisplayDataInput->enable(); - iButtonReadId->enable(); - iButtonReadFirmwareRevision->enable(); - iButtonPowerSupplyMonitor->enable(); - iTextFieldX->enable(); - iTextFieldY->enable(); - iButtonSetPixel->enable(); - iButtonResetPixel->enable(); - iButtonSetAllPixels->enable(); + if (iVfd01.IsOpen()) + { + //Those widgets are specific to our VFD + iButtonClearDisplay->enable(); + iButtonDimming->enable(); + iButtonDisplayDataInput->enable(); + iButtonReadId->enable(); + iButtonReadFirmwareRevision->enable(); + iButtonPowerSupplyMonitor->enable(); + iTextFieldX->enable(); + iTextFieldY->enable(); + iButtonSetPixel->enable(); + iButtonResetPixel->enable(); + iButtonSetAllPixels->enable(); + } } else { @@ -294,7 +300,7 @@ get_feature_button->disable(); connect_button->enable(); disconnect_button->disable(); - // + iButtonClearDisplay->disable(); iButtonDimming->disable(); iButtonDisplayDataInput->disable(); @@ -314,6 +320,8 @@ long MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr) { + //Close all our devices. + //Closing devices which are not open won't harm. hid_close(connected_device); connected_device = NULL; iVfd01.Close(); @@ -339,7 +347,7 @@ cur_dev = devices; while (cur_dev) { // Add it to the List Box only if it is a Futaba device - if (cur_dev->vendor_id == KFutabaVendorId) + //if (cur_dev->vendor_id == KFutabaVendorId) { FXString s; FXString usage_str; @@ -755,8 +763,22 @@ long MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr) { - unsigned char buf[256]; - int res = hid_read(connected_device, buf, sizeof(buf)); + FutabaVfdReport report; + unsigned char buffer[256]; + unsigned char* buf=NULL; + int res = 0; + + //Use either our display or our generic device depending which one is connected + if (connected_device) + { + res = hid_read(connected_device, buffer, sizeof(buffer)); + buf=buffer; + } + else + { + res=iVfd01.Read(report); + buf=report.Buffer(); + } if (res > 0) { FXString s; @@ -779,6 +801,7 @@ input_text->setBottomLine(INT_MAX); } + //Keep on reading getApp()->addTimeout(this, ID_TIMER, 5 * timeout_scalar /*5ms*/); return 1;