mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Fixes for Fortius USB timeout issue and new Fortius VR driver package built with Zadig
- Fortius read was timing out on some hardware - If read fails then write fails - Moved write before read to rectify - Added windows 10 x64 compatible driver inf built with Zadig
This commit is contained in:
BIN
contrib/GC_Fortius-VR_libusb-0.1_drivers.zip
Normal file
BIN
contrib/GC_Fortius-VR_libusb-0.1_drivers.zip
Normal file
Binary file not shown.
@@ -372,7 +372,19 @@ void Fortius::run()
|
|||||||
|
|
||||||
if (isDeviceOpen == true) {
|
if (isDeviceOpen == true) {
|
||||||
|
|
||||||
|
int rc = sendRunCommand(pedalSensor) ;
|
||||||
|
if (rc < 0) {
|
||||||
|
qDebug() << "usb write error " << rc;
|
||||||
|
// send failed - ouch!
|
||||||
|
closePort(); // need to release that file handle!!
|
||||||
|
quit(4);
|
||||||
|
return; // couldn't write to the device
|
||||||
|
}
|
||||||
|
|
||||||
int actualLength = readMessage();
|
int actualLength = readMessage();
|
||||||
|
if (actualLength < 0) {
|
||||||
|
qDebug() << "usb read error " << actualLength;
|
||||||
|
}
|
||||||
if (actualLength >= 24) {
|
if (actualLength >= 24) {
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
@@ -405,12 +417,15 @@ void Fortius::run()
|
|||||||
// UNUSED curDistance = buf[28] | (buf[29] << 8) | (buf[30] << 16) | (buf[31] << 24);
|
// UNUSED curDistance = buf[28] | (buf[29] << 8) | (buf[30] << 16) | (buf[31] << 24);
|
||||||
|
|
||||||
// cadence - confirmed correct
|
// cadence - confirmed correct
|
||||||
|
//qDebug() << "raw cadence " << buf[44];
|
||||||
curCadence = buf[44];
|
curCadence = buf[44];
|
||||||
|
|
||||||
// speed
|
// speed
|
||||||
|
//qDebug() << "raw speed " << buf[32];
|
||||||
curSpeed = 1.3f * (double)(qFromLittleEndian<quint16>(&buf[32])) / (3.6f * 100.00f);
|
curSpeed = 1.3f * (double)(qFromLittleEndian<quint16>(&buf[32])) / (3.6f * 100.00f);
|
||||||
|
|
||||||
// power - changed scale from 10 to 13, seems correct in erg mode, slope mode needs work
|
// power - changed scale from 10 to 13, seems correct in erg mode, slope mode needs work
|
||||||
|
//qDebug() << "raw power " << buf[38];
|
||||||
curPower = qFromLittleEndian<qint16>(&buf[38])/13;
|
curPower = qFromLittleEndian<qint16>(&buf[38])/13;
|
||||||
if (curPower < 0.0) curPower = 0.0; // brake power can be -ve when coasting.
|
if (curPower < 0.0) curPower = 0.0; // brake power can be -ve when coasting.
|
||||||
|
|
||||||
@@ -425,6 +440,7 @@ void Fortius::run()
|
|||||||
curPower *= powerScaleFactor; // apply scale factor
|
curPower *= powerScaleFactor; // apply scale factor
|
||||||
|
|
||||||
// heartrate - confirmed correct
|
// heartrate - confirmed correct
|
||||||
|
//qDebug() << "raw heartrate " << buf[12];
|
||||||
curHeartRate = buf[12];
|
curHeartRate = buf[12];
|
||||||
|
|
||||||
// update public fields
|
// update public fields
|
||||||
@@ -472,18 +488,6 @@ void Fortius::run()
|
|||||||
timer.restart();
|
timer.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
|
||||||
// KEEP THE FORTIUS CONNECTION ALIVE
|
|
||||||
//----------------------------------------------------------------
|
|
||||||
if (isDeviceOpen == true) {
|
|
||||||
|
|
||||||
if (sendRunCommand(pedalSensor) < 0) {
|
|
||||||
// send failed - ouch!
|
|
||||||
closePort(); // need to release that file handle!!
|
|
||||||
quit(4);
|
|
||||||
return; // couldn't write to the device
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The controller updates faster than the brake. Setting this to a low value (<50ms) increases the frequency of controller
|
// The controller updates faster than the brake. Setting this to a low value (<50ms) increases the frequency of controller
|
||||||
// only packages (24byte).
|
// only packages (24byte).
|
||||||
@@ -501,20 +505,26 @@ void Fortius::run()
|
|||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
int Fortius::sendOpenCommand()
|
int Fortius::sendOpenCommand()
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t open_command[] = {0x02,0x00,0x00,0x00};
|
uint8_t open_command[] = {0x02,0x00,0x00,0x00};
|
||||||
|
|
||||||
return rawWrite(open_command, 4);
|
int retCode = rawWrite(open_command, 4);
|
||||||
|
//qDebug() << "usb status " << retCode;
|
||||||
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fortius::sendCloseCommand()
|
int Fortius::sendCloseCommand()
|
||||||
{
|
{
|
||||||
uint8_t close_command[] = {0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x52,0x10,0x04};
|
uint8_t close_command[] = {0x01,0x08,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x52,0x10,0x04};
|
||||||
|
|
||||||
return rawWrite(close_command, 12);
|
int retCode = rawWrite(close_command, 12);
|
||||||
|
//qDebug() << "usb status " << retCode;
|
||||||
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fortius::sendRunCommand(int16_t pedalSensor)
|
int Fortius::sendRunCommand(int16_t pedalSensor)
|
||||||
{
|
{
|
||||||
|
int retCode = 0;
|
||||||
pvars.lock();
|
pvars.lock();
|
||||||
int mode = this->mode;
|
int mode = this->mode;
|
||||||
int16_t gradient = (int16_t)this->gradient;
|
int16_t gradient = (int16_t)this->gradient;
|
||||||
@@ -525,12 +535,14 @@ int Fortius::sendRunCommand(int16_t pedalSensor)
|
|||||||
|
|
||||||
if (mode == FT_ERGOMODE)
|
if (mode == FT_ERGOMODE)
|
||||||
{
|
{
|
||||||
|
//qDebug() << "send load " << load;
|
||||||
|
|
||||||
qToLittleEndian<int16_t>(13 * load, &ERGO_Command[4]);
|
qToLittleEndian<int16_t>(13 * load, &ERGO_Command[4]);
|
||||||
ERGO_Command[6] = pedalSensor;
|
ERGO_Command[6] = pedalSensor;
|
||||||
|
|
||||||
qToLittleEndian<int16_t>(130 * brakeCalibrationFactor + 1040, &ERGO_Command[10]);
|
qToLittleEndian<int16_t>(130 * brakeCalibrationFactor + 1040, &ERGO_Command[10]);
|
||||||
|
|
||||||
return rawWrite(ERGO_Command, 12);
|
retCode = rawWrite(ERGO_Command, 12);
|
||||||
}
|
}
|
||||||
else if (mode == FT_SSMODE)
|
else if (mode == FT_SSMODE)
|
||||||
{
|
{
|
||||||
@@ -543,11 +555,11 @@ int Fortius::sendRunCommand(int16_t pedalSensor)
|
|||||||
|
|
||||||
qToLittleEndian<int16_t>(130 * brakeCalibrationFactor + 1040, &SLOPE_Command[10]);
|
qToLittleEndian<int16_t>(130 * brakeCalibrationFactor + 1040, &SLOPE_Command[10]);
|
||||||
|
|
||||||
return rawWrite(SLOPE_Command, 12);
|
retCode = rawWrite(SLOPE_Command, 12);
|
||||||
}
|
}
|
||||||
else if (mode == FT_IDLE)
|
else if (mode == FT_IDLE)
|
||||||
{
|
{
|
||||||
return sendOpenCommand();
|
retCode = sendOpenCommand();
|
||||||
}
|
}
|
||||||
else if (mode == FT_CALIBRATE)
|
else if (mode == FT_CALIBRATE)
|
||||||
{
|
{
|
||||||
@@ -555,8 +567,9 @@ int Fortius::sendRunCommand(int16_t pedalSensor)
|
|||||||
// to be calculated by observing the brake power and speed after calibration starts (i.e. it's not returned
|
// to be calculated by observing the brake power and speed after calibration starts (i.e. it's not returned
|
||||||
// by the brake).
|
// by the brake).
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
//qDebug() << "usb status " << retCode;
|
||||||
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@@ -575,6 +588,7 @@ int Fortius::readMessage()
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = rawRead(buf, 64);
|
rc = rawRead(buf, 64);
|
||||||
|
//qDebug() << "usb status " << rc;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,23 +600,29 @@ int Fortius::closePort()
|
|||||||
|
|
||||||
bool Fortius::find()
|
bool Fortius::find()
|
||||||
{
|
{
|
||||||
return usb2->find();
|
int rc;
|
||||||
|
rc = usb2->find();
|
||||||
|
//qDebug() << "usb status " << rc;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fortius::openPort()
|
int Fortius::openPort()
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
// on windows we try on USB2 then on USB1 then fail...
|
// on windows we try on USB2 then on USB1 then fail...
|
||||||
return usb2->open();
|
rc = usb2->open();
|
||||||
|
//qDebug() << "usb status " << rc;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fortius::rawWrite(uint8_t *bytes, int size) // unix!!
|
int Fortius::rawWrite(uint8_t *bytes, int size) // unix!!
|
||||||
{
|
{
|
||||||
return usb2->write((char *)bytes, size);
|
return usb2->write((char *)bytes, size, FT_USB_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fortius::rawRead(uint8_t bytes[], int size)
|
int Fortius::rawRead(uint8_t bytes[], int size)
|
||||||
{
|
{
|
||||||
return usb2->read((char *)bytes, size);
|
return usb2->read((char *)bytes, size, FT_USB_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see of there is a port at the device specified
|
// check to see of there is a port at the device specified
|
||||||
|
|||||||
@@ -74,6 +74,8 @@
|
|||||||
#define DEFAULT_CALIBRATION 0.00
|
#define DEFAULT_CALIBRATION 0.00
|
||||||
#define DEFAULT_SCALING 1.00
|
#define DEFAULT_SCALING 1.00
|
||||||
|
|
||||||
|
#define FT_USB_TIMEOUT 500
|
||||||
|
|
||||||
class Fortius : public QThread
|
class Fortius : public QThread
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ void LibUsb::close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int LibUsb::read(char *buf, int bytes)
|
int LibUsb::read(char *buf, int bytes)
|
||||||
|
{
|
||||||
|
return this->read(buf, bytes, 125);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LibUsb::read(char *buf, int bytes, int timeout)
|
||||||
{
|
{
|
||||||
// check it isn't closed already
|
// check it isn't closed already
|
||||||
if (!device) return -1;
|
if (!device) return -1;
|
||||||
@@ -134,7 +139,7 @@ int LibUsb::read(char *buf, int bytes)
|
|||||||
readBufSize = 0;
|
readBufSize = 0;
|
||||||
readBufIndex = 0;
|
readBufIndex = 0;
|
||||||
|
|
||||||
int rc = usb_bulk_read(device, readEndpoint, readBuf, 64, 125);
|
int rc = usb_bulk_read(device, readEndpoint, readBuf, 64, timeout);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
// don't report timeouts - lots of noise so commented out
|
// don't report timeouts - lots of noise so commented out
|
||||||
@@ -162,6 +167,11 @@ int LibUsb::read(char *buf, int bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int LibUsb::write(char *buf, int bytes)
|
int LibUsb::write(char *buf, int bytes)
|
||||||
|
{
|
||||||
|
return this->write(buf, bytes, 125);
|
||||||
|
}
|
||||||
|
|
||||||
|
int LibUsb::write(char *buf, int bytes, int timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
// check it isn't closed
|
// check it isn't closed
|
||||||
@@ -174,7 +184,7 @@ int LibUsb::write(char *buf, int bytes)
|
|||||||
// we use a non-interrupted write on Linux/Mac since the interrupt
|
// we use a non-interrupted write on Linux/Mac since the interrupt
|
||||||
// write block size is incorrectly implemented in the version of
|
// write block size is incorrectly implemented in the version of
|
||||||
// libusb we build with. It is no less efficient.
|
// libusb we build with. It is no less efficient.
|
||||||
rc = usb_bulk_write(device, writeEndpoint, buf, bytes, 125);
|
rc = usb_bulk_write(device, writeEndpoint, buf, bytes, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ public:
|
|||||||
int open();
|
int open();
|
||||||
void close();
|
void close();
|
||||||
int read(char *buf, int bytes);
|
int read(char *buf, int bytes);
|
||||||
|
int read(char *buf, int bytes, int timeout);
|
||||||
int write(char *buf, int bytes);
|
int write(char *buf, int bytes);
|
||||||
|
int write(char *buf, int bytes, int timeout);
|
||||||
bool find();
|
bool find();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user