Skip to content

Commit

Permalink
Merge branch 'develop' for 1.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
cujomalainey committed Feb 7, 2022
2 parents 7dd75b6 + c9d3080 commit c198052
Show file tree
Hide file tree
Showing 377 changed files with 7,794 additions and 2,994 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ jobs:
strategy:
matrix:
example: [
examples/BicyclePowerDisplay/BicyclePowerDisplay.ino,
examples/BicyclePowerSensor/BicyclePowerSensor.ino,
examples/BicycleSpeedDisplay/BicycleSpeedDisplay.ino,
examples/DeviceSearch/DeviceSearch.ino,
examples/DynamicProfiles/DynamicProfiles.ino,
examples/EnvironmentDisplay/EnvironmentDisplay.ino,
examples/FecBikeTrainerDisplay/FecBikeTrainerDisplay.ino,
examples/HeartRateDisplay/HeartRateDisplay.ino,
examples/HeartRateMonitor/HeartRateMonitor.ino,
examples/LEVDisplay/LEVDisplay.ino]
examples/LEVDisplay/LEVDisplay.ino,
examples/MuscleOxygenMonitor/MuscleOxygenMonitor.ino,
examples/ShiftingShifter/ShiftingShifter.ino]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -83,6 +88,9 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Install platform
run: pio platform install native

- name: Install library dependencies
run: pio lib -g install ANT

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
.piolibdeps
.ycm*
*.swp
*.DS_Store

# used for testing
src/main.cpp

.DS_Store
.tags*
tags
.pio
*-e
281 changes: 281 additions & 0 deletions examples/BicyclePowerDisplay/BicyclePowerDisplay.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
/***********************************
* AntPlus Bicycle Power Display example
*
* Finds a nearby Bike Power Sensor, pairs
* to it and then reads the information
* out via the serial port.
*
* Example built for ESP32
* Note: HardwareSerial required for this controller
*
* Author Andrew Hillier
* based on the work of Curtis Malainey
************************************/
#include <Arduino.h>
#include "ANT.h"
#include "ANTPLUS.h"
#include <HardwareSerial.h>

#define BAUD_RATE 9600
#define CHANNEL_0 0
#define antSerial Serial2

const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; // get this from thisisant.com

// *************************************
// Specific to test ANT+ chip and ESP32 setup
const int RTS_PIN = 23;
const int SUSPEND_PIN = 22;
const int SLEEP_PIN = 19;
const int RESET_PIN = 2;

// *************************************

ArduinoSerialAntWithCallbacks ant;
AntPlusRouter router;
ProfileBicyclePowerDisplay bikePower;

void bicyclePowerBaseDataPageHandler(AntRxDataResponse& msg, uintptr_t data);
void batteryStatusDataPageHandler(BatteryStatus& msg, uintptr_t data);
void manufacturerIDDataPageHandler(ManufacturersInformation& msg, uintptr_t data);
void productIDDataPageHandler(ProductInformation& msg, uintptr_t data);
void powerOnlyDataPageHandler(BicyclePowerStandardPowerOnly& msg, uintptr_t data);
void crankTorqueDataPageHandler(BicyclePowerStandardCrankTorque& msg, uintptr_t data);
void wheelTorqueDataPageHandler(BicyclePowerStandardWheelTorque& msg, uintptr_t data);
void pedalSmoothnessDataPageHandler(BicyclePowerTorqueEffectivenessAndPedalSmoothness& msg, uintptr_t data);
void crankTorqueFrequencyDataPageHandler(BicyclePowerCrankTorqueFrequency& msg, uintptr_t data);

void bicyclePowerBatteryStatus(uint8_t flags);
void printStatus(uint8_t status);

void setup() {

// Powering on the ANT+ chip
// *************************************

pinMode(SUSPEND_PIN, OUTPUT);
pinMode(SLEEP_PIN, OUTPUT);
pinMode(RESET_PIN, OUTPUT);
pinMode(RTS_PIN, INPUT);

digitalWrite(RESET_PIN, HIGH);
digitalWrite(SUSPEND_PIN, HIGH);
digitalWrite(SLEEP_PIN, LOW);


// *************************************

antSerial.begin(BAUD_RATE);
ant.setSerial(antSerial);
delay(5000);

router.setDriver(&ant); // never touch ant again
router.setAntPlusNetworkKey(NETWORK_KEY);
router.setProfile(CHANNEL_0, &bikePower);
// Delay after initial setup to wait for user to connect on serial

Serial.begin(BAUD_RATE);
Serial.println("Running");
bikePower.onDataPage(bicyclePowerBaseDataPageHandler);
bikePower.onBatteryStatus(batteryStatusDataPageHandler);
bikePower.onManufacturersInformation(manufacturerIDDataPageHandler);
bikePower.onProductInformation(productIDDataPageHandler);
bikePower.onBicyclePowerStandardPowerOnly(powerOnlyDataPageHandler);
bikePower.onBicyclePowerStandardCrankTorque(crankTorqueDataPageHandler);
bikePower.onBicyclePowerStandardWheelTorque(wheelTorqueDataPageHandler);
bikePower.onBicyclePowerTorqueEffectivenessAndPedalSmoothness(pedalSmoothnessDataPageHandler);
bikePower.onBicyclePowerCrankTorqueFrequency(crankTorqueFrequencyDataPageHandler);
bikePower.begin();
// wait for pair to complete
uint8_t status = bikePower.waitForPair();
// print channel status
Serial.println("===========================");
printStatus(status);
Serial.print("Device Number: ");
Serial.println(bikePower.getDeviceNumber());
Serial.print("Transmisison Type: ");
Serial.println(bikePower.getTransmissionType());
}

void loop() {
router.loop();
}

void printOrInvalid(uint8_t value, uint8_t invalidValue) {
if (value == invalidValue) {
Serial.println("Invalid");
} else {
Serial.println(value);
}
}

void crankTorqueFrequencyDataPageHandler(BicyclePowerCrankTorqueFrequency& msg, uintptr_t data) {
Serial.print("Slope: ");
Serial.println(msg.getSlope());
Serial.print("Timestamp: ");
Serial.println(msg.getTimeStamp());
Serial.print("Torque Ticks Stamp: ");
Serial.println(msg.getTorqueTicksStamp());
}

void batteryStatusDataPageHandler(BatteryStatus& msg, uintptr_t data) {
Serial.print("Number of Batteries: ");
Serial.println(msg.getNumberOfBatteries());
Serial.print("Battery Identifier: ");
Serial.println(msg.getBatteryIdentifier());
Serial.print("Cumulative Operating Time: ");
Serial.println(msg.getCumulativeOperatingTime());
Serial.print("Fractional Battery Voltage: ");
Serial.println(msg.getFractionalBatteryVoltage());
Serial.print("Coarse Battery Voltage: ");
Serial.println(msg.getCoarseBatteryVoltage());
Serial.print("Battery Status: ");
bicyclePowerBatteryStatus(msg.getBatteryStatus());
Serial.print("Cumulative Operating Time Resolution: ");
Serial.println(msg.getCumulativeOperatingTimeResolution());
}

void manufacturerIDDataPageHandler(ManufacturersInformation& msg, uintptr_t data) {
Serial.print("Hardware ID: ");
Serial.println(msg.getHWRevision());
Serial.print("Manufacturer ID: ");
Serial.println(msg.getManufacturerID());
Serial.print("Model Number: ");
Serial.println(msg.getModelNumber());
}

void productIDDataPageHandler(ProductInformation& msg, uintptr_t data) {
Serial.print("Software Version Supplemental: ");
Serial.println(msg.getSWRevisionSupplemental());
Serial.print("Software Version: ");
Serial.println(msg.getSWRevisionMain());
Serial.print("Serial Number: ");
Serial.println(msg.getSerialNumber());
}

void bicyclePowerBaseDataPageHandler(AntRxDataResponse& msg, uintptr_t data) {
BicyclePowerBaseMainDataPage dp = BicyclePowerBaseMainDataPage(msg);
Serial.println("===========================");
Serial.print("DataPage: ");
Serial.println(dp.getDataPageNumber());
if (dp.getDataPageNumber() >= ANTPLUS_COMMON_DATAPAGE_REQUESTDATAPAGE_NUMBER) {
return;
}
Serial.print("Update Event Count: ");
Serial.println(dp.getUpdateEventCount());
}

void powerOnlyDataPageHandler(BicyclePowerStandardPowerOnly& msg, uintptr_t data) {
Serial.print("Pedal Power: ");
if (msg.getPedalPower() == ANTPLUS_BICYCLEPOWER_DATAPAGES_STANDARDPOWERONLY_PEDALPOWER_NOTUSED &&
msg.getPedalDifferentiation()) {
Serial.println("Not Used");
} else {
Serial.println(msg.getPedalPower());
Serial.print(" From Pedal: ");
if (msg.getPedalDifferentiation() == ANTPLUS_BICYCLEPOWER_DATAPAGES_STANDARDPOWERONLY_PEDALDIFFERENTIATION_RIGHT) {
Serial.println("Right");
} else {
Serial.println("Unknown");
}
}
Serial.print("Instantaneous Cadence: ");
if (msg.getInstantaneousCadence() == ANTPLUS_BICYCLEPOWER_DATAPAGES_STANDARDPOWERONLY_INSTANTANEOUSCADENCE_INVALID) {
Serial.println("Invalid");
} else {
Serial.println(msg.getInstantaneousCadence());
}
Serial.print("Accumulated Power: ");
Serial.println(msg.getAccumulatedPower());
Serial.print("Instantaneous Power: ");
Serial.println(msg.getInstantaneousPower());
}

void crankTorqueDataPageHandler(BicyclePowerStandardCrankTorque& msg, uintptr_t data) {
Serial.print("Crank Ticks: ");
Serial.println(msg.getCrankTicks());
Serial.print("Instantaneous Cadence: ");
printOrInvalid(msg.getInstantaneousCadence(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_STANDARDCRANKTORQUE_INSTANTANEOUSCADENCE_INVALID);
Serial.print("Crank Period: ");
Serial.println(msg.getCrankPeriod());
Serial.print("Accumulated Torque: ");
Serial.println(msg.getAccumulatedTorque());
}

void wheelTorqueDataPageHandler(BicyclePowerStandardWheelTorque& msg, uintptr_t data) {
Serial.print("Wheel Ticks: ");
Serial.println(msg.getWheelTicks());
Serial.print("Instantaneous Cadence: ");
printOrInvalid(msg.getInstantaneousCadence(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_STANDARDWHEELTORQUE_INSTANTANEOUSCADENCE_INVALID);
Serial.print("Wheel Period: ");
Serial.println(msg.getWheelPeriod());
Serial.print("Accumulated Torque: ");
Serial.println(msg.getAccumulatedTorque());
}

void pedalSmoothnessDataPageHandler(BicyclePowerTorqueEffectivenessAndPedalSmoothness& msg, uintptr_t data) {
Serial.print("Left Torque Effectiveness: ");
printOrInvalid(msg.getLeftTorqueEffectiveness(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_TORQUEEFFECTIVENESS_INVALID);
Serial.print("Right Torque Effectiveness: ");
printOrInvalid(msg.getRightTorqueEffectiveness(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_TORQUEEFFECTIVENESS_INVALID);
if (msg.getRightPedalSmoothness() == ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_RIGHTPEDALSMOOTHNESS_COMBINED) {
Serial.print("Combined Pedal Smoothness: ");
printOrInvalid(msg.getLeftPedalSmoothness(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_PEDALSMOOTHNESS_INVALID);
} else {
Serial.print("Left Pedal Smoothness: ");
printOrInvalid(msg.getLeftPedalSmoothness(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_PEDALSMOOTHNESS_INVALID);
Serial.print("Right Pedal Smoothness: ");
printOrInvalid(msg.getRightPedalSmoothness(),
ANTPLUS_BICYCLEPOWER_DATAPAGES_TORQUEEFFECTIVENESSANDPEDALSMOOTHNESS_PEDALSMOOTHNESS_INVALID);
}
}

void printStatus(uint8_t status) {
Serial.print("Channel Status: ");
switch (status) {
case CHANNEL_STATUS_UNASSIGNED:
Serial.println("Unassigned");
break;
case CHANNEL_STATUS_ASSIGNED:
Serial.println("Assigned");
break;
case CHANNEL_STATUS_SEARCHING:
Serial.println("Searching");
break;
case CHANNEL_STATUS_TRACKING:
Serial.println("Tracking");
break;
}
}

void bicyclePowerBatteryStatus(uint8_t flags) {
switch (flags) {
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_NEW:
Serial.println("New");
break;
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_GOOD:
Serial.println("Good");
break;
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_OK:
Serial.println("Ok");
break;
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_LOW:
Serial.println("Low");
break;
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_CRITICAL:
Serial.println("Critical");
break;
case ANTPLUS_COMMON_DATAPAGE_BATTERYSTATUS_BATTERYSTATUS_INVALID:
Serial.println("Invalid");
break;
default:
Serial.println("Reserved/Unknown");
break;
}
}
Loading

0 comments on commit c198052

Please sign in to comment.