Skip to content

Commit

Permalink
Make sure the libusb header is installed, use hid_read_timeout instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Feb 20, 2020
1 parent 202e2c3 commit 8d35893
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LIBS_fpp_vastfmt_so += -L/opt/fpp/src -lfpp -lusb-1.0
CXXFLAGS_src/FPPVastFM.o += -I/opt/fpp/src


%.o: %.cpp Makefile
%.o: %.cpp Makefile /usr/include/libusb-1.0/libusb.h
$(CCACHE) $(CC) $(CFLAGS) $(CXXFLAGS) $(CXXFLAGS_$@) -c $< -o $@

%.o: %.c Makefile
Expand All @@ -21,3 +21,8 @@ libfpp-vastfmt.so: $(OBJECTS_fpp_vastfmt_so) /opt/fpp/src/libfpp.so

clean:
rm -f libfpp-vastfmt.so $(OBJECTS_fpp_vastfmt_so)


/usr/include/libusb-1.0/libusb.h:
sudo apt-get -q -y update
sudo apt-get -q -y --reinstall install libusb-1.0-0-dev
24 changes: 19 additions & 5 deletions src/VASTFMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ bool VASTFMT::sendDeviceCommand(uint8_t cmd, std::vector<uint8_t> &dataOut, bool
aucBufOut[2] = cmd;

hid_write(phd, aucBufOut, 43);
int r = hid_read(phd, aucBufIn, 43);
int r = hid_read_timeout(phd, aucBufIn, 43, 250);

if (r < 2) {
LogWarn(VB_PLUGIN, "Si4713/USB: not enough data\n");
LogWarn(VB_PLUGIN, "Si4713/USB: not enough data: %d\n", r);
return false;
}
if (!ignoreFailures && aucBufIn[0] & PCRequestError) {
Expand Down Expand Up @@ -163,7 +163,11 @@ bool VASTFMT::sendSi4711Command(uint8_t cmd, const std::vector<uint8_t> &dataIn,
}

hid_write(phd, aucBufOut, 43);
int r = hid_read(phd, aucBufIn, 42);
int r = hid_read_timeout(phd, aucBufIn, 42, 250);
if (r == 0) {
LogWarn(VB_PLUGIN, "Si4711/USB: command timed out (%d): %s, returned (FALSE)\n", aucBufIn[2], Si471xStatusStr(aucBufIn[2]));
return false;
}
/*
printf("CMD: %2x Read: %d\n", cmd, r);
for (int x = 0; x < 25; x++) {
Expand Down Expand Up @@ -208,7 +212,12 @@ bool VASTFMT::setProperty(uint16_t prop, uint16_t val) {
aucBufOut[5] = val >> 8;
aucBufOut[6] = val;
hid_write(phd, aucBufOut, 43);
hid_read(phd, aucBufIn, 42);
int r = hid_read_timeout(phd, aucBufIn, 42, 250);
if (r == 0) {
LogWarn(VB_PLUGIN, "Si4711/USB: request error for property %X - timeout.\n", prop);
return false;
}


if (aucBufIn[0] & PCRequestError) {
LogWarn(VB_PLUGIN, "Si4713/USB: request error for property %X.\n", prop);
Expand Down Expand Up @@ -252,7 +261,12 @@ bool VASTFMT::getProperty(uint16_t prop, uint16_t &val) {
aucBufOut[3] = prop >> 8;
aucBufOut[4] = prop;
hid_write(phd, aucBufOut, 43);
hid_read(phd, aucBufIn, 42);
int r = hid_read_timeout(phd, aucBufIn, 42, 250);
if (r == 0) {
LogWarn(VB_PLUGIN, "Si4713/USB: request error for property %X - timeout.\n", prop);
return false;
}


if (aucBufIn[0] & PCRequestError) {
LogWarn(VB_PLUGIN, "Si4713/USB: request error for property %X.\n", prop);
Expand Down

0 comments on commit 8d35893

Please sign in to comment.