Skip to content

Commit 81d21fe

Browse files
committed
Remove channel config magic numbers
1 parent 4634a4b commit 81d21fe

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/Profiles/HeartRate/ANTPLUS_HeartRatePrivateDefines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#ifndef ANTPLUS_HEARTRATEPROFILEPRIVATEDEFINES_h
22
#define ANTPLUS_HEARTRATEPROFILEPRIVATEDEFINES_h
33

4+
/* Channel Config */
5+
#define ANTPLUS_HEARTRATE_CHANNELTYPE CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE
6+
#define ANTPLUS_HEARTRATE_DEVICETYPE 120
7+
#define ANTPLUS_HEARTRATE_CHANNELPERIOD 8070
8+
// 30 / 2.5 = 12
9+
#define ANTPLUS_HEARTRATE_SEARCHTIMEOUT 12
10+
411
/* Base DataPage */
512
#define ANTPLUS_HEARTRATE_DATAPAGEBASE_DATAPAGE_BYTE 0
613
#define ANTPLUS_HEARTRATE_DATAPAGEBASE_TOGGLE_BYTE 0

src/Profiles/HeartRate/Monitor/ANTPLUS_ProfileHeartRateMonitor.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,15 @@
44
#include <CommonDataPages/ANTPLUS_CommonDataPageDefines.h>
55

66
ProfileHeartRateMonitor::ProfileHeartRateMonitor() : BaseSlaveProfile() {
7-
// TODO remove magic numbers
8-
setDeviceNumber(0);
9-
setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE);
10-
setDeviceType(120);
11-
setTransmissionType(0);
12-
setChannelPeriod(8070);
13-
// 30 / 2.5 = 12
14-
setSearchTimeout(12);
7+
setChannelConfig();
158
}
169

1710
ProfileHeartRateMonitor::ProfileHeartRateMonitor(uint16_t deviceNumber) : BaseSlaveProfile(deviceNumber) {
18-
// TODO remove magic numbers
19-
setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE);
20-
setDeviceType(120);
21-
setTransmissionType(0);
22-
setChannelPeriod(8070);
23-
// 30 / 2.5 = 12
24-
setSearchTimeout(12);
11+
setChannelConfig();
12+
}
13+
14+
ProfileHeartRateMonitor::ProfileHeartRateMonitor(uint16_t deviceNumber, uint8_t transmissionType) : BaseSlaveProfile(deviceNumber, transmissionType) {
15+
setChannelConfig();
2516
}
2617

2718
void ProfileHeartRateMonitor::onBroadcastData(BroadcastData& msg) {
@@ -75,6 +66,13 @@ void ProfileHeartRateMonitor::stop() {
7566
closeChannel();
7667
}
7768

69+
void ProfileHeartRateMonitor::setChannelConfig() {
70+
setChannelType(ANTPLUS_HEARTRATE_CHANNELTYPE);
71+
setDeviceType(ANTPLUS_HEARTRATE_DEVICETYPE);
72+
setChannelPeriod(ANTPLUS_HEARTRATE_CHANNELPERIOD);
73+
setSearchTimeout(ANTPLUS_HEARTRATE_SEARCHTIMEOUT);
74+
}
75+
7876
bool ProfileHeartRateMonitor::handleBatteryStatus(HeartRateBaseMainDataPage& dataPage) {
7977
HeartRateBatteryStatus dp = HeartRateBatteryStatus(dataPage);
8078
return _onHeartRateBatteryStatus.call(dp);

src/Profiles/HeartRate/Monitor/ANTPLUS_ProfileHeartRateMonitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ProfileHeartRateMonitor : public BaseSlaveProfile {
3131
void onBroadcastData(BroadcastData& msg);
3232

3333
private:
34+
void setChannelConfig();
3435
bool handleBatteryStatus(HeartRateBaseMainDataPage& dataPage);
3536
bool handleCapabilities(HeartRateBaseMainDataPage& dataPage);
3637
bool handleCumulativeOperatingTime(HeartRateBaseMainDataPage& dataPage);

0 commit comments

Comments
 (0)