-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathstrydrunpowersensor.h
More file actions
119 lines (95 loc) · 3.73 KB
/
Copy pathstrydrunpowersensor.h
File metadata and controls
119 lines (95 loc) · 3.73 KB
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
#ifndef STRYDRUNPOWERSENSOR_H
#define STRYDRUNPOWERSENSOR_H
#include <QBluetoothDeviceDiscoveryAgent>
#include <QtBluetooth/qlowenergyadvertisingdata.h>
#include <QtBluetooth/qlowenergyadvertisingparameters.h>
#include <QtBluetooth/qlowenergycharacteristic.h>
#include <QtBluetooth/qlowenergycharacteristicdata.h>
#include <QtBluetooth/qlowenergycontroller.h>
#include <QtBluetooth/qlowenergydescriptordata.h>
#include <QtBluetooth/qlowenergyservice.h>
#include <QtBluetooth/qlowenergyservicedata.h>
#include <QtCore/qbytearray.h>
#ifndef Q_OS_ANDROID
#include <QtCore/qcoreapplication.h>
#else
#include <QtGui/qguiapplication.h>
#endif
#include <QtCore/qlist.h>
#include <QtCore/qmutex.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qtimer.h>
#include <QDateTime>
#include <QObject>
#include <QString>
#include "treadmill.h"
#ifdef Q_OS_IOS
#include "ios/lockscreen.h"
#endif
class strydrunpowersensor : public treadmill {
Q_OBJECT
public:
strydrunpowersensor(bool noWriteResistance, bool noHeartService, bool noVirtualDevice);
bool connected() override;
private:
void writeCharacteristic(uint8_t *data, uint8_t data_len, QString info, bool disable_log = false,
bool wait_for_response = false);
void startDiscover();
uint16_t watts();
QTimer *refresh;
QList<QLowEnergyService *> gattCommunicationChannelService;
// QLowEnergyCharacteristic gattNotify1Characteristic;
uint8_t sec1Update = 0;
QByteArray lastPacket;
QDateTime lastRefreshCadenceChanged = QDateTime::currentDateTime();
QDateTime lastRefreshPowerChanged = QDateTime::currentDateTime();
QDateTime lastGoodCadence = QDateTime::currentDateTime();
uint8_t firstStateChanged = 0;
bool charNotified = false;
bool readMethod = false;
uint8_t battery_level = 0;
QLowEnergyService *cadenceService = nullptr;
QLowEnergyCharacteristic cadenceChar;
bool initDone = false;
bool initRequest = false;
bool noWriteResistance = false;
bool noHeartService = false;
bool noVirtualDevice = false;
uint16_t oldLastCrankEventTime = 0;
uint16_t oldCrankRevs = 0;
uint16_t LastCrankEventTime = 0;
double CrankRevs = 0;
bool powerReceived = false;
bool FORERUNNER = false;
QLowEnergyService *strydIndoorModeService = nullptr;
QLowEnergyCharacteristic strydIndoorModeChar;
bool strydIndoorModeRequested = false;
bool strydIndoorModeConfirmed = false;
uint8_t strydIndoorModeRetries = 0;
QDateTime strydIndoorModeRequestedAt;
void requestStrydIndoorMode();
#ifdef Q_OS_IOS
lockscreen *h = 0;
#endif
signals:
void disconnected();
void debug(QString string);
void onHeartRate(uint8_t heart);
public slots:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
private slots:
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue);
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
void descriptorRead(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue);
void stateChanged(QLowEnergyService::ServiceState state);
void controllerStateChanged(QLowEnergyController::ControllerState state);
void serviceDiscovered(const QBluetoothUuid &gatt);
void serviceScanDone(void);
void update();
void error(QLowEnergyController::Error err);
void errorService(QLowEnergyService::ServiceError);
void changeInclinationRequested(double grade, double percentage);
};
#endif // STRYDRUNPOWERSENSOR_H