Files
GoldenCheetah/src/FortiusController.cpp
Mark Liversedge abfcf078fc Tacx Fortius Support
Initial support for Tacx Fortius devices.

Note this requires libusb support to be present and will
work on Linux, Mac and Windows.

The handlebar buttons up/down will increase/decrease the
load/intensity in a similar fashion to the +/- keys on
the Computrainer controller.

The cancel button will stop a workout and the enter key
is used to mark a lap.

Slope and Ergo modes are supported, but we do not set the
brake at all if the speed is below 10kph, this is to
ensure it does not get burnt out when users 'grind'.

SPECIAL NOTE:

   The Fortius handlebar controller is a Ez-Usb device
   and requires firmware to be loaded when it is connected.
   Since this is copyrighted by Tacx BV we do not distribute
   it, instead, when the user sets up a Fortius device they
   must also provide the file. Full instructions on how this
   should be done are given when configuring the device.

Additionally, for Linux users udev rules should be added to
ensure that the USB devices are accessible to non-root users.

Fixes #538.
2011-12-12 17:26:59 +00:00

148 lines
3.4 KiB
C++

/*
* Copyright (c) 2011 Mark Liversedge (liversedge@gmail.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "FortiusController.h"
#include "Fortius.h"
#include "RealtimeData.h"
FortiusController::FortiusController(TrainTool *parent, DeviceConfiguration *dc) : RealtimeController(parent, dc)
{
myFortius = new Fortius (parent, dc->portSpec);
}
int
FortiusController::start()
{
return myFortius->start();
}
int
FortiusController::restart()
{
return myFortius->restart();
}
int
FortiusController::pause()
{
return myFortius->pause();
}
int
FortiusController::stop()
{
return myFortius->stop();
}
bool
FortiusController::discover(DeviceConfiguration *) {return false; } // NOT IMPLEMENTED YET
bool FortiusController::doesPush() { return false; }
bool FortiusController::doesPull() { return true; }
bool FortiusController::doesLoad() { return true; }
/*
* gets called from the GUI to get updated telemetry.
* so whilst we are at it we check button status too and
* act accordingly.
*
*/
void
FortiusController::getRealtimeData(RealtimeData &rtData)
{
int Buttons, Status;
double Power, HeartRate, Cadence, Speed, Load;
if(!myFortius->isRunning())
{
QMessageBox msgBox;
msgBox.setText("Cannot Connect to Fortius");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
parent->Stop(1);
return;
}
// get latest telemetry
myFortius->getTelemetry(Power, HeartRate, Cadence, Speed, Buttons, Status);
//
// PASS BACK TELEMETRY
//
rtData.setWatts(Power);
rtData.setHr(HeartRate);
rtData.setCadence(Cadence);
rtData.setSpeed(Speed);
// get current load
Load = myFortius->getLoad();
// post processing, probably not used
// since its used to compute power for
// non-power devices, but we may add other
// calculations later that might apply
// means we could calculate power based
// upon speed even for a Fortius!
processRealtimeData(rtData);
//
// BUTTONS
//
// ignore other buttons if calibrating
if (parent->calibrating) return;
// ADJUST LOAD
if ((Buttons&FT_PLUS)) parent->Higher();
if ((Buttons&FT_MINUS)) parent->Lower();
// LAP/INTERVAL
if (Buttons&FT_ENTER) parent->newLap();
// CANCEL
if (Buttons&FT_CANCEL) parent->Stop(0);
rtData.setLoad(Load);
}
void FortiusController::pushRealtimeData(RealtimeData &) { } // update realtime data with current values
void
FortiusController::setLoad(double load)
{
myFortius->setLoad(load);
}
void
FortiusController::setGradient(double grade)
{
myFortius->setGradient(grade);
}
void
FortiusController::setMode(int mode)
{
if (mode == RT_MODE_ERGO) mode = FT_ERGOMODE;
if (mode == RT_MODE_SPIN) mode = FT_SSMODE;
myFortius->setMode(mode);
}