Skip to content

Commit

Permalink
Add example: Hearth Rate Monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigge committed Jan 17, 2014
1 parent 3ef4f1a commit 175e1da
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,3 +1,4 @@
include README
include LICENCE
include resources/ant-usb-sticks.rules
include examples/*.py
66 changes: 66 additions & 0 deletions examples/hearth_rate_monitor.py
@@ -0,0 +1,66 @@
# ANT - Hearth Rate Monitor Example
#
# Copyright (c) 2012, Gustav Tiger <gustav@tiger.name>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from ant.easy.node import Node
from ant.easy.channel import Channel
from ant.base.message import Message

import logging
import struct
import threading
import sys

NETWORK_KEY= [0xb9, 0xa5, 0x21, 0xfb, 0xbd, 0x72, 0xc3, 0x45]

def on_data(data):
hearthrate = data[7]
string = "Hearthrate: " + str(data[7]) + " "

sys.stdout.write(string)
sys.stdout.flush()
sys.stdout.write("\b" * len(string))

def main():
#logging.basicConfig()

node = Node()
node.set_network_key(0x00, NETWORK_KEY)

channel = node.new_channel(Channel.Type.BIDIRECTIONAL_RECEIVE)

channel.on_broadcast_data = on_data
channel.on_burst_data = on_data

channel.set_period(8070)
channel.set_search_timeout(12)
channel.set_rf_freq(57)
channel.set_id(0, 120, 0)

try:
channel.open()
node.start()
finally:
node.stop()

if __name__ == "__main__":
main()

0 comments on commit 175e1da

Please sign in to comment.