Adding read functionnality to our HidDevice.
Fixing some state issues upon connection.
1.1 --- a/inc/HidDevice.h Thu May 22 08:45:14 2014 +0200
1.2 +++ b/inc/HidDevice.h Thu May 22 09:12:31 2014 +0200
1.3 @@ -23,7 +23,10 @@
1.4 bool IsOpen();
1.5 //
1.6 int SetNonBlocking(int aNonBlocking);
1.7 - //
1.8 + //Read
1.9 + template<int S>
1.10 + int Read(HidReport<S>& aInputReport);
1.11 + //Write
1.12 template<int S>
1.13 int Write(const HidReport<S>& aOutputReport);
1.14 //
1.15 @@ -54,5 +57,13 @@
1.16 return hid_write(iHidDevice,aOutputReport.Buffer(),S);
1.17 }
1.18
1.19 +/**
1.20 +*/
1.21 +template<int S>
1.22 +int HidDevice::Read(HidReport<S>& aInputReport)
1.23 + {
1.24 + return hid_read(iHidDevice,aInputReport.Buffer(),S);
1.25 + }
1.26 +
1.27
1.28 #endif
1.29 \ No newline at end of file
2.1 --- a/inc/HidReport.h Thu May 22 08:45:14 2014 +0200
2.2 +++ b/inc/HidReport.h Thu May 22 09:12:31 2014 +0200
2.3 @@ -16,6 +16,7 @@
2.4 inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
2.5 const unsigned char* Buffer() const {return iBuffer;};
2.6 unsigned char* Buffer() {return iBuffer;};
2.7 + int Size() {return S;}
2.8 protected:
2.9 unsigned char iBuffer[S];
2.10 };
3.1 --- a/src/test.cpp Thu May 22 08:45:14 2014 +0200
3.2 +++ b/src/test.cpp Thu May 22 09:12:31 2014 +0200
3.3 @@ -90,7 +90,7 @@
3.4 connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
3.5 disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
3.6 disconnect_button->disable();
3.7 - rescan_button = new FXButton(buttonVF, "Re-Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
3.8 + rescan_button = new FXButton(buttonVF, "Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
3.9 new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
3.10
3.11 connected_label = new FXLabel(vf, "Disconnected");
3.12 @@ -227,6 +227,8 @@
3.13 //
3.14 iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize];
3.15
3.16 + SetConnectedStates();
3.17 +
3.18 return 1;
3.19 }
3.20
3.21 @@ -271,17 +273,21 @@
3.22 disconnect_button->enable();
3.23 input_text->setText("");
3.24 //
3.25 - iButtonClearDisplay->enable();
3.26 - iButtonDimming->enable();
3.27 - iButtonDisplayDataInput->enable();
3.28 - iButtonReadId->enable();
3.29 - iButtonReadFirmwareRevision->enable();
3.30 - iButtonPowerSupplyMonitor->enable();
3.31 - iTextFieldX->enable();
3.32 - iTextFieldY->enable();
3.33 - iButtonSetPixel->enable();
3.34 - iButtonResetPixel->enable();
3.35 - iButtonSetAllPixels->enable();
3.36 + if (iVfd01.IsOpen())
3.37 + {
3.38 + //Those widgets are specific to our VFD
3.39 + iButtonClearDisplay->enable();
3.40 + iButtonDimming->enable();
3.41 + iButtonDisplayDataInput->enable();
3.42 + iButtonReadId->enable();
3.43 + iButtonReadFirmwareRevision->enable();
3.44 + iButtonPowerSupplyMonitor->enable();
3.45 + iTextFieldX->enable();
3.46 + iTextFieldY->enable();
3.47 + iButtonSetPixel->enable();
3.48 + iButtonResetPixel->enable();
3.49 + iButtonSetAllPixels->enable();
3.50 + }
3.51 }
3.52 else
3.53 {
3.54 @@ -294,7 +300,7 @@
3.55 get_feature_button->disable();
3.56 connect_button->enable();
3.57 disconnect_button->disable();
3.58 - //
3.59 +
3.60 iButtonClearDisplay->disable();
3.61 iButtonDimming->disable();
3.62 iButtonDisplayDataInput->disable();
3.63 @@ -314,6 +320,8 @@
3.64 long
3.65 MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
3.66 {
3.67 + //Close all our devices.
3.68 + //Closing devices which are not open won't harm.
3.69 hid_close(connected_device);
3.70 connected_device = NULL;
3.71 iVfd01.Close();
3.72 @@ -339,7 +347,7 @@
3.73 cur_dev = devices;
3.74 while (cur_dev) {
3.75 // Add it to the List Box only if it is a Futaba device
3.76 - if (cur_dev->vendor_id == KFutabaVendorId)
3.77 + //if (cur_dev->vendor_id == KFutabaVendorId)
3.78 {
3.79 FXString s;
3.80 FXString usage_str;
3.81 @@ -755,8 +763,22 @@
3.82 long
3.83 MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
3.84 {
3.85 - unsigned char buf[256];
3.86 - int res = hid_read(connected_device, buf, sizeof(buf));
3.87 + FutabaVfdReport report;
3.88 + unsigned char buffer[256];
3.89 + unsigned char* buf=NULL;
3.90 + int res = 0;
3.91 +
3.92 + //Use either our display or our generic device depending which one is connected
3.93 + if (connected_device)
3.94 + {
3.95 + res = hid_read(connected_device, buffer, sizeof(buffer));
3.96 + buf=buffer;
3.97 + }
3.98 + else
3.99 + {
3.100 + res=iVfd01.Read(report);
3.101 + buf=report.Buffer();
3.102 + }
3.103
3.104 if (res > 0) {
3.105 FXString s;
3.106 @@ -779,6 +801,7 @@
3.107 input_text->setBottomLine(INT_MAX);
3.108 }
3.109
3.110 + //Keep on reading
3.111 getApp()->addTimeout(this, ID_TIMER,
3.112 5 * timeout_scalar /*5ms*/);
3.113 return 1;