-
Notifications
You must be signed in to change notification settings - Fork 446
/
TrainSidebar.h
320 lines (255 loc) · 10.4 KB
/
TrainSidebar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
* Copyright (c) 2009 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
*/
#ifndef _GC_TrainSidebar_h
#define _GC_TrainSidebar_h 1
#include "GoldenCheetah.h"
#include "Context.h"
#include "RealtimeData.h"
#include "RealtimePlot.h"
#include "DeviceConfiguration.h"
#include "DeviceTypes.h"
#include "ErgFile.h"
#include "VideoSyncFile.h"
#include "ErgFilePlot.h"
#include "GcSideBarItem.h"
#include "RemoteControl.h"
#include "Tab.h"
// standard stuff
#include <QDir>
#include <QDialog>
#include <QtGui>
#include <QCheckBox>
#include <QLabel>
#include <QDebug>
#include <QTreeWidgetItem>
#include <QHeaderView>
#include <QFormLayout>
#include <QSqlTableModel>
#include "cmath" // for round()
#include "Units.h" // for MILES_PER_KM
// Status settings
#define RT_MODE_ERGO 0x0001 // load generation modes
#define RT_MODE_SPIN 0x0002 // spinscan like modes
#define RT_MODE_SLOPE 0x0002 // same as spinscan but not so CT specific
#define RT_MODE_CALIBRATE 0x0004 // calibrate
#define RT_RUNNING 0x0100 // is running now
#define RT_PAUSED 0x0200 // is paused
#define RT_RECORDING 0x0400 // is recording to disk
#define RT_WORKOUT 0x0800 // is running a workout
#define RT_STREAMING 0x1000 // is streaming to a remote peer
#define RT_CONNECTED 0x2000 // is connected to devices
#define RT_CALIBRATING 0x4000 // is calibrating
// msecs constants for timers
#define REFRESHRATE 200 // screen refresh in milliseconds
#define STREAMRATE 200 // rate at which we stream updates to remote peer
#define SAMPLERATE 1000 // disk update in milliseconds
#define LOADRATE 1000 // rate at which load is adjusted
// device treeview node types
#define HEAD_TYPE 6666
#define SERVER_TYPE 5555
#define WORKOUT_TYPE 4444
class RealtimeController;
class ComputrainerController;
class ANTlocalController;
class NullController;
class RealtimePlot;
class RealtimeData;
class MultiDeviceDialog;
class TrainBottom;
class TrainSidebar : public GcWindow
{
Q_OBJECT
G_OBJECT
public:
TrainSidebar(Context *context);
Context *context;
QStringList listWorkoutFiles(const QDir &) const;
QList<int> devices(); // convenience function for iterating over active devices
const QTreeWidgetItem *currentWorkout() { return workout; }
const QTreeWidgetItem *currentMedia() { return media; }
const QTreeWidgetItem *workoutItems() { return allWorkouts; }
int selectedDeviceNumber();
// set labels when ergfile selected etc
void setLabels();
// was realtimewindow,merged into tool
// update charts/dials and manage controller
void updateData(RealtimeData &); // to update telemetry by push devices
void nextDisplayMode(); // show next display mode
void setStreamController(); // based upon selected device
// this
QTabWidget *trainTabs;
void setStatusFlags(int flags); // helpers that update context etc when changing state
void clearStatusFlags(int flags);
// where to get telemetry from Device.at(x)
int bpmTelemetry; // Heartrate
int wattsTelemetry; // Power (and AltPower)
int rpmTelemetry; // Cadence
int kphTelemetry; // Speed (and Distance)
RemoteControl *remote; // remote control settings
int currentStatus() {return status;}
signals:
void deviceSelected();
void start();
void pause();
void stop();
void intensityChanged(int value);
void statusChanged(int status);
void setNotification(QString msg, int timeout);
void clearNotification(void);
private slots:
void deviceTreeWidgetSelectionChanged();
void workoutTreeWidgetSelectionChanged();
void videosyncTreeWidgetSelectionChanged();
void mediaTreeWidgetSelectionChanged();
void deviceTreeMenuPopup(const QPoint &);
void deleteDevice();
void devicePopup();
void workoutPopup();
void videosyncPopup();
void mediaPopup();
void refresh(); // when TrainDB is updated...
void selectVideo(QString fullpath);
void selectVideoSync(QString fullpath);
void selectWorkout(QString fullpath);
void removeInvalidVideoSync();
void removeInvalidWorkout();
void viewChanged(int index);
int getCalibrationIndex(void);
public slots:
void configChanged(qint32);
void deleteWorkouts(); // deletes selected workouts
void deleteVideos(); // deletes selected workouts
void deleteVideoSyncs(); // deletes selected VideoSync
void Start(); // when start button is pressed
void Pause(); // when Paude is pressed
void Stop(int status=0); // when controller wants to stop
void Connect(); // connect to train devices
void Disconnect(); // disconnect train devices
void toggleConnect();
void Calibrate(); // toggle calibration mode
void FFwd(); // jump forward when in a workout
void Rewind(); // jump backwards when in a workout
void FFwdLap(); // jump forward to next Lap marker
void Higher(); // set load/gradient higher
void Lower(); // set load/gradient higher
void newLap(); // start new Lap!
void resetLapTimer(); //reset the lap timer
void toggleCalibration();
void updateCalibration();
// Timed actions
void guiUpdate(); // refreshes the telemetry
void diskUpdate(); // writes to CSV file
void loadUpdate(); // sets Load on CT like devices
// When no config has been setup
void warnnoConfig();
// User adjusted intensity
void adjustIntensity(int value); // Intensity of workout user adjusted
// slot for receiving remote control commands
void remoteControl(uint16_t);
protected:
friend class ::MultiDeviceDialog;
// watch keyboard events.
bool eventFilter(QObject *object, QEvent *e);
GcSplitter *trainSplitter;
GcSplitterItem *deviceItem,
*workoutItem,
*videosyncItem,
*mediaItem;
QSqlTableModel *videoModel;
QSqlTableModel *videosyncModel;
QSqlTableModel *workoutModel;
QTreeWidget *deviceTree;
QTreeView *workoutTree;
QTreeView *videosyncTree;
QTreeView *mediaTree;
QSortFilterProxyModel *sortModel; // sorting workout list
QSortFilterProxyModel *vsortModel; // sorting video list
QSortFilterProxyModel *vssortModel; // sorting videosync list
QTreeWidgetItem *allWorkouts;
QTreeWidgetItem *workout;
QTreeWidgetItem *videosync;
QTreeWidgetItem *media;
int lastAppliedIntensity;// remember how we scaled last time
int FTP; // current FTP / CP
int WPRIME; // current W'
QList<DeviceConfiguration> Devices;
QList<int> activeDevices;
// updated with a RealtimeData object either from
// update() - from a push device (quarqd ANT+)
// Device->getRealtimeData() - from a pull device (Computrainer)
double displayPower, displayHeartRate, displayCadence, displaySpeed;
double displayLRBalance, displayLTE, displayRTE, displayLPS, displayRPS;
double displaySMO2, displayTHB, displayO2HB, displayHHB;
double displayDistance, displayWorkoutDistance;
long load;
double slope;
int displayLap; // user increment for Lap
int displayWorkoutLap; // which Lap in the workout are we at?
bool lapAudioEnabled;
bool lapAudioThisLap;
// for non-zero average calcs
int pwrcount, cadcount, hrcount, spdcount, lodcount, grdcount; // for NZ average calc
int status;
int displaymode;
QFile *recordFile; // where we record!
ErgFile *ergFile; // workout file
VideoSyncFile *videosyncFile; // videosync file
bool startCalibration, restartCalibration, finishCalibration;
int calibrationDeviceIndex;
uint8_t calibrationType, calibrationState;
uint16_t calibrationSpindownTime, calibrationZeroOffset, calibrationSlope;
double calibrationTargetSpeed, calibrationCurrentSpeed;
double calibrationCadence, calibrationTorque;
long total_msecs,
lap_msecs,
load_msecs;
QTime load_period;
uint session_elapsed_msec, lap_elapsed_msec;
QTime session_time, lap_time;
QTimer *gui_timer, // refresh the gui
*load_timer, // change the load on the device
*disk_timer; // write to .CSV file
bool autoConnect;
bool pendingConfigChange;
public:
int mode;
// everyone else wants this
QCheckBox *recordSelector;
QSharedPointer<QFileSystemWatcher> watcher;
bool calibrating;
double wbalr, wbal;
};
class MultiDeviceDialog : public QDialog
{
Q_OBJECT
G_OBJECT
public:
MultiDeviceDialog(Context *, TrainSidebar *);
public slots:
void applyClicked();
void cancelClicked();
private:
Context *context;
TrainSidebar *traintool;
QComboBox *bpmSelect, // heartrate
*wattsSelect, // power
*rpmSelect, // cadence
*kphSelect; // speed
QPushButton *applyButton, *cancelButton;
};
#endif // _GC_TrainSidebar_h