Skip to content

Commit b051972

Browse files
committed
LEV profile for display and example added
1 parent fad45f8 commit b051972

20 files changed

+720
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,15 @@ src/main.cpp
88
.DS_Store
99
.tags*
1010
tags
11+
examples/LEVDisplay/__vm/.LEVDisplay.vsarduino.h
12+
examples/LEVDisplay/__vm/Compile.vmps.xml
13+
examples/LEVDisplay/__vm/Configuration.Release.vmps.xml
14+
*.vcxproj
15+
*.filters
16+
*.user
17+
examples/LEVDisplay/__vm/Upload.vmps.xml
18+
*.d
19+
*.o
20+
*.buildinfo
21+
*.elf
22+
*.hex

examples/LEVDisplay/LEVDisplay.ino

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/**********************************************
2+
* AntPlus LEV Display example
3+
*
4+
* Finds a nearby LEV Sensor, pairs
5+
* to it and then reads the information
6+
* out via the serial port.
7+
*
8+
* Author Bernd Woköck
9+
* based on the work of Curtis Malainey
10+
**********************************************/
11+
#include <Arduino.h>
12+
#include "ANT.h"
13+
#include "ANTPLUS.h"
14+
15+
#define BAUD_RATE 9600
16+
#define CHANNEL_0 0
17+
#define CHANNEL_1 1
18+
19+
const uint8_t NETWORK_KEY[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
20+
21+
AntWithCallbacks ant = AntWithCallbacks();
22+
AntPlusRouter router = AntPlusRouter();
23+
ProfileLevDisplay lev = ProfileLevDisplay();
24+
25+
void levBaseDataPageHandler(AntRxDataResponse& msg, uintptr_t data);
26+
void levSpeedSysinfo1Handler(LevSpeedSysinfo1& msg, uintptr_t data);
27+
void levSpeedDist1Handler(LevSpeedDist1& msg, uintptr_t data);
28+
void levSpeedDist2Handler(LevSpeedDist2& msg, uintptr_t data);
29+
void levSpeedSysinfo2Handler(LevSpeedSysinfo2& msg, uintptr_t data);
30+
void levBatteryInfo(LevBatteryInfo& msg, uintptr_t data);
31+
void levAntChannelEvent(ChannelEventResponse& msg, uintptr_t data);
32+
33+
void manufacturersInformationDataPageHandler(ManufacturersInformation& msg, uintptr_t data);
34+
void productInformationDataPageHandler(ProductInformation& msg, uintptr_t data);
35+
36+
void printStatus(uint8_t status);
37+
38+
void setup() {
39+
Serial2.begin(BAUD_RATE);
40+
ant.setSerial(Serial2);
41+
delay(1000);
42+
43+
router.setDriver(&ant); // never touch ant again
44+
router.setAntPlusNetworkKey(NETWORK_KEY);
45+
router.setProfile(CHANNEL_0, &lev);
46+
47+
Serial.begin(BAUD_RATE);
48+
Serial.println("Running");
49+
50+
// setup lev display
51+
lev.onDataPage(levBaseDataPageHandler);
52+
lev.onLevSpeedSysinfo1(levSpeedSysinfo1Handler);
53+
lev.onLevSpeedDist1(levSpeedDist1Handler);
54+
lev.onLevSpeedDist2(levSpeedDist2Handler);
55+
lev.onLevSpeedSysinfo2(levSpeedSysinfo2Handler);
56+
lev.onLevBatteryInfo(levBatteryInfo);
57+
lev.onLevCaps(levCaps);
58+
lev.onManufacturersInformation(manufacturersInformationDataPageHandler);
59+
lev.onProductInformation(productInformationDataPageHandler);
60+
lev.onChannelEvent(levAntChannelEvent);
61+
lev.begin();
62+
delay(100); // wait for module initialization
63+
64+
// wait for pair to complete
65+
uint8_t status = lev.waitForPair();
66+
67+
// print channel status
68+
Serial.println("===========================");
69+
printStatus(status);
70+
Serial.print("Device Number: ");
71+
Serial.println(lev.getDeviceNumber());
72+
Serial.print("Transmisison Type: ");
73+
Serial.println(lev.getTransmissionType());
74+
}
75+
76+
void loop() {
77+
router.loop();
78+
}
79+
80+
void levAntChannelEvent(ChannelEventResponse& msg, uintptr_t data) {
81+
if (msg.getCode() == STATUS_EVENT_CHANNEL_CLOSED)
82+
{
83+
Serial.println("channel closed - reconnect");
84+
lev.begin();
85+
}
86+
}
87+
88+
void levBaseDataPageHandler(AntRxDataResponse& msg, uintptr_t data) {
89+
LevBaseMainDataPage dp = LevBaseMainDataPage(msg);
90+
Serial.println("===========================");
91+
Serial.print("DataPage: ");
92+
Serial.println(dp.getDataPageNumber());
93+
94+
// debug
95+
int l = msg.getDataLength();
96+
uint8_t * buf = msg.getData();
97+
for (int i = 0; i < l; i++)
98+
{
99+
Serial.print(buf[i], HEX); Serial.print(" ");
100+
}
101+
Serial.println("");
102+
}
103+
104+
void levSpeedSysinfo1Handler(LevSpeedSysinfo1& msg, uintptr_t data) {
105+
Serial.print("Temp state: ");
106+
Serial.println(msg.getTempState());
107+
Serial.print("Travel mode state: ");
108+
Serial.println(msg.getTravelModeState());
109+
Serial.print("System state: ");
110+
Serial.println(msg.getSystemState());
111+
Serial.print("Gear state: ");
112+
Serial.println(msg.getGearState());
113+
Serial.print("Gear error: ");
114+
Serial.println(msg.getError());
115+
Serial.print("Speed: ");
116+
Serial.print(msg.getSpeed()/10);
117+
Serial.print(".");
118+
Serial.println(msg.getSpeed() % 10);
119+
}
120+
121+
void levSpeedDist1Handler(LevSpeedDist1& msg, uintptr_t data) {
122+
Serial.print("Total dist: ");
123+
Serial.println((float)msg.getTotalDist() / 100);
124+
Serial.print("Remaining range: ");
125+
Serial.println(msg.getRemainingRange());
126+
Serial.print("Speed: ");
127+
Serial.print(msg.getSpeed() / 10);
128+
Serial.print(".");
129+
Serial.println(msg.getSpeed() % 10);
130+
}
131+
132+
void levSpeedDist2Handler(LevSpeedDist2& msg, uintptr_t data) {
133+
Serial.print("Total dist: ");
134+
Serial.println((float)msg.getTotalDist() / 100);
135+
Serial.print("Fuel consumption: ");
136+
Serial.println(msg.getFuelConsumption());
137+
Serial.print("Speed: ");
138+
Serial.print(msg.getSpeed() / 10);
139+
Serial.print(".");
140+
Serial.println(msg.getSpeed() % 10);
141+
}
142+
143+
void levSpeedSysinfo2Handler(LevSpeedSysinfo2& msg, uintptr_t data) {
144+
Serial.print("Battery SOC: ");
145+
Serial.println(msg.getBatterySOC());
146+
Serial.print("Travel mode state: ");
147+
Serial.println(msg.getTravelModeState());
148+
Serial.print("System state: ");
149+
Serial.println(msg.getSystemState());
150+
Serial.print("Gear state: ");
151+
Serial.println(msg.getGearState());
152+
Serial.print("Percent Assist: ");
153+
Serial.println(msg.getPercentAssist());
154+
Serial.print("Speed: ");
155+
Serial.print(msg.getSpeed() / 10);
156+
Serial.print(".");
157+
Serial.println(msg.getSpeed() % 10);
158+
}
159+
160+
void levBatteryInfo(LevBatteryInfo& msg, uintptr_t data) {
161+
Serial.print("Charging Cycle Count: ");
162+
Serial.println(msg.getChargingCycleCount());
163+
Serial.print("Fuel consumption: ");
164+
Serial.println(msg.getFuelConsumption());
165+
Serial.print("Battery voltage: ");
166+
Serial.println(msg.getBatteryVoltage());
167+
Serial.print("Distance on current charge: ");
168+
Serial.println(msg.getDistanceOnCurrentCharge());
169+
}
170+
171+
void levCaps(LevCaps& msg, uintptr_t data) {
172+
Serial.print("Travel modes supported: ");
173+
Serial.println(msg.getTravelModesSupported());
174+
Serial.print("Wheel circumference: ");
175+
Serial.println(msg.getWheelCircumference());
176+
}
177+
178+
void manufacturersInformationDataPageHandler(ManufacturersInformation& msg, uintptr_t data) {
179+
Serial.print("DataPage: ");
180+
Serial.println(msg.getDataPageNumber());
181+
Serial.print("HW Revision: ");
182+
Serial.println(msg.getHWRevision());
183+
Serial.print("ManufacturerID: ");
184+
Serial.println(msg.getManufacturerID());
185+
Serial.print("Model Number: ");
186+
Serial.println(msg.getModelNumber());
187+
}
188+
189+
void productInformationDataPageHandler(ProductInformation& msg, uintptr_t data) {
190+
Serial.print("DataPage: ");
191+
Serial.println(msg.getDataPageNumber());
192+
Serial.print("SW Revision Supplemental: ");
193+
Serial.println(msg.getSWRevisionSupplemental());
194+
Serial.print("SW Revision Main: ");
195+
Serial.println(msg.getSWRevisionMain());
196+
Serial.print("Serial Number: ");
197+
Serial.println(msg.getSerialNumber());
198+
}
199+
200+
void printStatus(uint8_t status) {
201+
Serial.print("Channel Status: ");
202+
switch (status) {
203+
case CHANNEL_STATUS_UNASSIGNED:
204+
Serial.println("Unassigned");
205+
break;
206+
case CHANNEL_STATUS_ASSIGNED:
207+
Serial.println("Assigned");
208+
break;
209+
case CHANNEL_STATUS_SEARCHING:
210+
Serial.println("Searching");
211+
break;
212+
case CHANNEL_STATUS_TRACKING:
213+
Serial.println("Tracking");
214+
break;
215+
}
216+
}
217+

src/Profiles/ANTPLUS_Profiles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
#include <Profiles/BicycleSpeed/ANTPLUS_BicycleSpeedProfile.h>
55
#include <Profiles/HeartRate/ANTPLUS_HeartRateProfile.h>
66
#include <Profiles/Environment/ANTPLUS_EnvironmentProfile.h>
7+
#include <Profiles/Lev/ANTPLUS_LevProfile.h>
78

89
#endif // ANTPLUS_ANTROUTER_h
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef ANTPLUS_LEVPROFILEPRIVATEDEFINES_h
2+
#define ANTPLUS_LEVPROFILEPRIVATEDEFINES_h
3+
4+
/* Channel Config */
5+
#define ANTPLUS_LEV_CHANNELTYPE CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE
6+
#define ANTPLUS_LEV_DEVICETYPE 20
7+
#define ANTPLUS_LEV_CHANNELPERIOD 8192
8+
// 30 / 2.5 = 12
9+
#define ANTPLUS_LEV_SEARCHTIMEOUT 12
10+
11+
/* Pages */
12+
#define ANTPLUS_LEV_DATAPAGE_SPEEDSYSINFO1_NUMBER 1
13+
#define ANTPLUS_LEV_DATAPAGE_SPEEDDIST1_NUMBER 2
14+
#define ANTPLUS_LEV_DATAPAGE_SPEEDDIST2_NUMBER 34
15+
#define ANTPLUS_LEV_DATAPAGE_SPEEDSYSINFO2_NUMBER 3
16+
#define ANTPLUS_LEV_DATAPAGE_BATTERYINFO_NUMBER 4
17+
#define ANTPLUS_LEV_DATAPAGE_CAPS_NUMBER 5
18+
19+
20+
// Base page */
21+
#define ANTPLUS_LEV_DATAPAGEBASE_DATAPAGE_MASK 0x7F
22+
#define ANTPLUS_LEV_DATAPAGEBASE_DATAPAGE_BYTE 0x00
23+
24+
25+
#endif // ANTPLUS_BICYCLESPEEDPROFILEPRIVATEDEFINES_h
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef ANTPLUS_LEVPROFILE_h
2+
#define ANTPLUS_LEVPROFILE_h
3+
4+
// General Definitions
5+
// todo
6+
7+
// Datapages
8+
#include <Profiles/Lev/DataPages/ANTPLUS_ProfileLevDataPages.h>
9+
10+
// Profile Classes
11+
#include <Profiles/Lev/Display/ANTPLUS_ProfileLevDisplay.h>
12+
13+
#endif // ANTPLUS_LEVPROFILE_h
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef ANTPLUS_PROFILELEVDATAPAGES_h
2+
#define ANTPLUS_PROFILELEVDATAPAGES_h
3+
4+
/* RX */
5+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevSpeedSysinfo1.h>
6+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevSpeedDist.h>
7+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevSpeedSysinfo2.h>
8+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevBatteryInfo.h>
9+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevCaps.h>
10+
11+
/* TX */
12+
13+
#endif // ANTPLUS_PROFILELEVDATAPAGES_h
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <Profiles/Lev/DataPages/Base/ANTPLUS_LevBaseMainDataPage.h>
2+
#include <Profiles/Lev/ANTPLUS_LevPrivateDefines.h>
3+
4+
LevBaseMainDataPage::LevBaseMainDataPage(AntRxDataResponse& dp) : BaseDataPage<BroadcastData>(dp) {
5+
6+
}
7+
8+
uint8_t LevBaseMainDataPage::getDataPageNumber() {
9+
return getData(ANTPLUS_LEV_DATAPAGEBASE_DATAPAGE_BYTE) & ANTPLUS_LEV_DATAPAGEBASE_DATAPAGE_MASK;
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef ANTPLUS_LEVBASEMAINDATAPAGE_h
2+
#define ANTPLUS_LEVBASEMAINDATAPAGE_h
3+
4+
#include <BaseClasses/ANTPLUS_BaseDataPage.h>
5+
6+
#include "ANT.h"
7+
8+
class LevBaseMainDataPage : public BaseDataPage<BroadcastData> {
9+
public:
10+
LevBaseMainDataPage(AntRxDataResponse& dp);
11+
uint8_t getDataPageNumber();
12+
};
13+
14+
#endif // ANTPLUS_LEVBASEMAINDATAPAGE_h
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <Profiles/Lev/DataPages/RX/ANTPLUS_LevBatteryInfo.h>
2+
#include <Profiles/Lev/ANTPLUS_LevPrivateDefines.h>
3+
4+
LevBatteryInfo::LevBatteryInfo(AntRxDataResponse& dp) : LevBaseMainDataPage(dp) {
5+
return;
6+
}
7+
8+
uint16_t LevBatteryInfo::getChargingCycleCount()
9+
{
10+
return (uint16_t)getData(2) + (((uint16_t)getData(3) & 0x0F) << 8);
11+
}
12+
13+
uint16_t LevBatteryInfo::getFuelConsumption()
14+
{
15+
uint16_t c = (uint16_t)getData(3) + (((uint16_t)getData(4) & 0x0F) << 8);
16+
return c >> 4;
17+
}
18+
19+
uint8_t LevBatteryInfo::getBatteryVoltage()
20+
{
21+
return getData(5);
22+
}
23+
24+
uint16_t LevBatteryInfo::getDistanceOnCurrentCharge()
25+
{
26+
return (uint16_t)getData(6) + (((uint16_t)getData(7) & 0x0F) << 8);
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef ANTPLUS_LEVBATTERYINFO_h
2+
#define ANTPLUS_LEVBATTERYINFO_h
3+
4+
#include <Profiles/Lev/DataPages/Base/ANTPLUS_LevBaseMainDataPage.h>
5+
6+
class LevBatteryInfo : public LevBaseMainDataPage {
7+
public:
8+
LevBatteryInfo(AntRxDataResponse& dp);
9+
uint16_t getChargingCycleCount();
10+
uint16_t getFuelConsumption();
11+
uint8_t getBatteryVoltage();
12+
uint16_t getDistanceOnCurrentCharge();
13+
};
14+
15+
#endif // ANTPLUS_LEVBATTERYINFO_h

0 commit comments

Comments
 (0)