Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cujomalainey committed Aug 21, 2019
2 parents 0a1fbce + f8640e2 commit ae79087
Show file tree
Hide file tree
Showing 138 changed files with 3,261 additions and 612 deletions.
39 changes: 39 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: circleci/python:2.7

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

working_directory: ~/repo

steps:
- checkout

- run:
name: install dependencies
command: |
sudo pip install -U platformio
# other common Python testing frameworks include pytest and nose
# https://pytest.org
# https://nose.readthedocs.io
- run:
name: run tests
command: |
pio test -e native
- store_artifacts:
path: test-reports
destination: test-reports

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ src/main.cpp
.DS_Store
.tags*
tags
.pio
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ cache:
- "~/.platformio"

env:
- PLATFORMIO_CI_SRC=examples/BicycleSpeedDisplay/BicycleSpeedDisplay.ino
- PLATFORMIO_CI_SRC=examples/EnvironmentDisplay/EnvironmentDisplay.ino
- PLATFORMIO_CI_SRC=examples/HeartRateDisplay/HeartRateDisplay.ino
- PLATFORMIO_CI_SRC=examples/BicycleSpeedDisplay/BicycleSpeedDisplay.ino
- PLATFORMIO_CI_SRC=examples/HeartRateMonitor/HeartRateMonitor.ino
- PLATFORMIO_CI_SRC=examples/LEVDisplay/LEVDisplay.ino

install:
- pip install -U platformio
Expand Down
Empty file modified COPYING
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ An Implementation of the Ant+ Network on top of [ant-arduino](https://github.com
## Status

[![Build Status](https://travis-ci.org/cujomalainey/antplus-arduino.svg?branch=master)](https://travis-ci.org/cujomalainey/antplus-arduino)
[![Test Status](https://img.shields.io/circleci/build/github/cujomalainey/antplus-arduino?label=test)](https://circleci.com/gh/cujomalainey/antplus-arduino)
[![BCH compliance](https://bettercodehub.com/edge/badge/cujomalainey/antplus-arduino?branch=master)](https://bettercodehub.com/)

## News
Expand Down
76 changes: 76 additions & 0 deletions examples/DeviceSearch/DeviceSearch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/***********************************
* AntPlus DeviceSearch example
*
* The example demonstrates the device
* search functionality of the router.
*
* Author Curtis Malainey
************************************/
#include <Arduino.h>
#include "ANT.h"
#include "ANTPLUS.h"

#define BAUD_RATE 9600
// 30s
#define SEARCH_RUNTIME 30*1000

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

AntWithCallbacks ant = AntWithCallbacks();
AntPlusRouter router = AntPlusRouter();

void searchCallback(uint16_t deviceNumber, uint8_t deviceType, uint8_t transmissionType, uint8_t rssi);
void flipSearch();

void setup() {
Serial.begin(BAUD_RATE);
Serial.println("Running");
Serial1.begin(BAUD_RATE);
ant.setSerial(Serial1);
// Delay after initial setup to wait for user to connect on serial

router.setDriver(&ant); // never touch ant again
router.setAntPlusNetworkKey(NETWORK_KEY);
flipSearch();
}

void loop() {
router.loop();

if (millis() - timeLastSwitch > SEARCH_RUNTIME) {
timeLastSwitch = millis();
flipSearch();
}
}

void flipSearch() {
Serial.println("===========================");
if (isSearching) {
// starting a search will stop all profiles and will need to be
// restarted after the search is stopped
router.startRxSearch(searchCallback);
} else {
router.stopRxSearch();
}
isSearching = !isSearching;
}

void searchCallback(uint16_t deviceNumber, uint8_t deviceType, uint8_t transmissionType, uint8_t rssi) {
Serial.print("Device Number: ");
Serial.print(deviceNumber);
Serial.print(" Device Type: ");
switch (deviceType) {
case ANTPLUS_HEARTRATE_DEVICETYPE:
Serial.println("Heart Rate");
break;
default:
Serial.println("Unknown");
break;
}
Serial.print(" Transmission Type: ");
Serial.print(transmissionType);
Serial.print(" RSSI: ");
Serial.println(rssi);
}
144 changes: 144 additions & 0 deletions examples/HeartRateMonitor/HeartRateMonitor.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/***********************************
* AntPlus HRMonitor example
*
* Implements a HR Monitor sensor with
* mocked data to it and then reports
* all events through the serial port
*
* This is a minimum viable example
* all additional datapages are optional
* and are enabled through flags passed
* into the profile
*
* It is highly recommended you read the documenation at
* https://github.com/cujomalainey/antplus-arduino/wiki/HeartRate-Monitor-Profile
*
* Author Curtis Malainey
************************************/
#include <Arduino.h>
#include "ANT.h"
#include "ANTPLUS.h"

#define BAUD_RATE 9600
#define CHANNEL_0 0

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

uint32_t flags = 0;
AntWithCallbacks ant;
AntPlusRouter router;
ProfileHeartRateMonitor hr(123, 0, flags);

// void batteryStatusDataPageHandler(HeartRateBatteryStatusMsg& msg, uintptr_t data);
// void capabilitiesDataPageHandler(HeartRateCapabilitiesMsg& msg, uintptr_t data);
// void cumulativeOperatingTimeDataPageHandler(HeartRateCumulativeOperatingTimeMsg& msg, uintptr_t data);
void defaultDataPageHandler(HeartRateDefaultMsg& msg, uintptr_t data);
void manufacturerInformationDataPageHandler(HeartRateManufacturerInformationMsg& msg, uintptr_t data);
// void previousHeartBeatDataPageHandler(HeartRatePreviousHeartBeatMsg& msg, uintptr_t data);
void productInformationDataPageHandler(HeartRateProductInformationMsg& msg, uintptr_t data);
// void swimIntervalSummary(HeartRateSwimIntervalSummaryMsg& msg, uintptr_t data);

void populateBaseHeartRate(HeartRateBaseMainDataPageMsg& msg);

void setup() {
Serial1.begin(BAUD_RATE);
ant.setSerial(Serial1);
delay(15000);
Serial.begin(BAUD_RATE);
Serial.println("Running");

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

// hr.createHeartRateBatteryStatusMsg(batteryStatusDataPageHandler);
// hr.createHeartRateCapabilitiesMsg(capabilitiesDataPageHandler);
// hr.createHeartRateCumulativeOperatingTimeMsg(cumulativeOperatingTimeDataPageHandler);
hr.createHeartRateDefaultMsg(defaultDataPageHandler);
hr.createHeartRateManufacturerInformationMsg(manufacturerInformationDataPageHandler);
// hr.createHeartRatePreviousHeartBeatMsg(previousHeartBeatDataPageHandler);
hr.createHeartRateProductInformationMsg(productInformationDataPageHandler);
// hr.createHeartRateSwimIntervalSummaryMsg(swimIntervalSummary);
Serial.println("===========================");
hr.begin();
}

void loop() {
// Call this very frequently
router.loop();
}

void printDpMsg(int dp, const char* s) {
Serial.print("Sending DataPage: ");
Serial.print(dp);
Serial.print(" - ");
Serial.println(s);
}

/* Optional */
// void batteryStatusDataPageHandler(HeartRateBatteryStatusMsg& msg, uintptr_t data) {
// printDpMsg(7, "Battery Status");
// populateBaseHeartRate(msg);
// }

/* Optional */
// void capabilitiesDataPageHandler(HeartRateCapabilitiesMsg& msg, uintptr_t data) {
// printDpMsg(6, "Capabilities");
// populateBaseHeartRate(msg);
// }

/* Optional */
// void cumulativeOperatingTimeDataPageHandler(HeartRateCumulativeOperatingTimeMsg& msg, uintptr_t data) {
// printDpMsg(1, "Cumulative Operating Time");
// populateBaseHeartRate(msg);
// }

void defaultDataPageHandler(HeartRateDefaultMsg& msg, uintptr_t data) {
// All fields are reserved
printDpMsg(0, "Default");
populateBaseHeartRate(msg);
}

void manufacturerInformationDataPageHandler(HeartRateManufacturerInformationMsg& msg, uintptr_t data) {
printDpMsg(2, "Manufacturer Information");
populateBaseHeartRate(msg);
msg.setManufacturerIdLsb(78);
msg.setSerialNumber(0xabcd);
}

/* Optional */
// void previousHeartBeatDataPageHandler(HeartRatePreviousHeartBeatMsg& msg, uintptr_t data) {
// printDpMsg(4, "Previous Heart Beat");
// populateBaseHeartRate(msg);
// }

void productInformationDataPageHandler(HeartRateProductInformationMsg& msg, uintptr_t data) {
printDpMsg(3, "Product Information");
populateBaseHeartRate(msg);
msg.setHardwareVersion(1);
msg.setSoftwareVersion(2);
msg.setModelNumber(3);
}

/* Optional */
// void swimIntervalSummary(HeartRateSwimIntervalSummaryMsg& msg, uintptr_t data) {
// printDpMsg(5, "Swim Interval");
// populateBaseHeartRate(msg);
// }

void populateBaseHeartRate(HeartRateBaseMainDataPageMsg& msg) {
static uint8_t toggle = 0;
static uint8_t hr = 0;
static uint16_t eventTime = 0;
static uint8_t count = 0;
msg.setPageChangeToggle(toggle++ < 4);
msg.setComputedHeartRate(20*sin(hr++) + 120);
msg.setHeartBeatEventTime(eventTime);
msg.setHeartBeatCount(count++);

if (toggle >= 8) {
toggle = 0;
}
eventTime += 120;
}
Loading

0 comments on commit ae79087

Please sign in to comment.