Exemple #1
0
    def __init__(self, search_timeout_sec=120):
        """
        Create Ant+ node, network, and initialize all attributes
        """
        self.search_timeout_sec = search_timeout_sec
        self.device = driver.USB2Driver()
        self.antnode = Node(self.device)
        self.network = Network(key=NETWORK_KEY_ANT_PLUS, name='N:ANT+')

        # Start search for sensors and register callbacks:
        self.device_power_meter = BicyclePower(self.antnode,
                                               self.network,
                                               callbacks={
                                                   'onDevicePaired':
                                                   self._on_device_found,
                                                   'onPowerData':
                                                   self._on_power_data,
                                                   'onChannelClosed':
                                                   self._on_channel_closed,
                                                   'onSearchTimeout':
                                                   self._on_search_timeout
                                               })
        self._power_meter_status = AntSensors.SensorStatus(fresh_time_s=2)
        self.device_heart_rate = HeartRate(self.antnode,
                                           self.network,
                                           callbacks={
                                               'onDevicePaired':
                                               self._on_device_found,
                                               'onHeartRateData':
                                               self._on_heartrate_data,
                                               'onChannelClosed':
                                               self._on_channel_closed,
                                               'onSearchTimeout':
                                               self._on_search_timeout
                                           })
        self._heart_rate_status = AntSensors.SensorStatus(fresh_time_s=2)
        self._reconnect = True
        # Heartrate fields
        self._heartrate_bpm = None
        self._rr_interval_ms = None
        self._hr_event_time_ms = None
        # Power meter fields
        self._instantaneous_power_watts = None
        self._cadence_rpm = None
        self._accumulated_power_watts = None
        self._power_event_count = None
Exemple #2
0
                 cadence, power):
    print("Speed Km/h {} Cadence {} Power {}".format(str(kmSpeed),
                                                     str(cadence), str(power)))
    print("#########################################################")


#-------------------------------------------------#
#  Initialization                                 #
#-------------------------------------------------#

try:
    reset_USB_Device()
except Exception as ex:
    print(ex)

antnode = Node(driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=0x1008))
try:
    antnode.start()
    network = Network(key=NETWORK_KEY_ANT_PLUS, name='N:ANT+')
    antnode.setNetworkKey(NETWORK_NUMBER_PUBLIC, network)
    myTrainer = bikeTrainer(
        antnode, network, {
            'onDevicePaired': device_paired,
            'onSearchTimeout': search_timed_out,
            'onChannelClosed': channel_closed,
            'onBikeTrainer': bike_Trainer
        })
    # Unpaired, search:
    myTrainer.open()
    print('ANT started. Connecting to devices...')
except ANTException as err:
Exemple #3
0
 def __init__(self):
     os.system("usbreset 0fcf:1008")
     self.node = Node(driver.USB2Driver())
     self.network = Network(key=NETWORK_KEY_ANT_PLUS, name='N:ANT+')
Exemple #4
0
# -*- coding: utf-8 -*-
"""Demonstrate the use of the ANT+ Heart Rate Device Profile

"""

import time

from ant.core import driver
from ant.core.node import Node, Network, ChannelID
from ant.core.constants import NETWORK_KEY_ANT_PLUS, NETWORK_NUMBER_PUBLIC
from ant.plus.heartrate import *

from config import *

device = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=0x1009)
antnode = Node(device)
antnode.start()
network = Network(key=NETWORK_KEY_ANT_PLUS, name='N:ANT+')
antnode.setNetworkKey(NETWORK_NUMBER_PUBLIC, network)


def device_found(self, device_number, transmission_type):
    print("Detect monitor device number: %d, transmission type: %d" %
          (device_number, transmission_type))


def heartrate_data(self, computed_heartrate, event_time_ms, rr_interval_ms):
    if rr_interval_ms is not None:
        print("Heart rate: %d, event time(ms): %d, rr interval (ms): %d" %
              (computed_heartrate, event_time_ms, rr_interval_ms))
    else:
Exemple #5
0
def main():
    global mainloop
    idProduct = prepare_usb("ANTUSB")

    device = driver.USB2Driver(log=LOG, debug=DEBUG, idProduct=idProduct)
    antnode = Node(device)
    antnode.start()
    network = Network(key=NETWORK_KEY_ANT_PLUS, name='N:ANT+')
    antnode.setNetworkKey(NETWORK_NUMBER_PUBLIC, network)

    POWER_SENSOR_ID = id_from_serial(1)
    #POWER_SENSOR_ID = 12345
    print("Start power meter ID %d" % POWER_SENSOR_ID)
    pm = PowerMeterTx(antnode, network, POWER_SENSOR_ID)

    def device_found(self, channelID):
        print("Detect %s" % str(channelID))

    def updatePower(self, cadence, accPower, power):
        pm.update(cadence, accPower, power)

    def heartrate_data(computed_heartrate, event_time_ms, rr_interval_ms):
        if HR_DEBUG:
            if rr_interval_ms is not None:
                print(
                    "Heart rate: %d, event time(ms): %d, rr interval (ms): %d"
                    % (computed_heartrate, event_time_ms, rr_interval_ms))
            else:
                print("Heart rate: %d" % (computed_heartrate, ))
        ble_hrm_update_hr(computed_heartrate)

    hr = HeartRate(antnode,
                   network,
                   callbacks={
                       'onDevicePaired': device_found,
                       'onHeartRateData': heartrate_data
                   })

    fe = FitnessEquipment(antnode,
                          network,
                          callbacks={
                              'onDevicePaired': device_found,
                              'onPowerUpdated': updatePower
                          })

    # Unpaired, search:
    hr.open()
    pm.open()
    fe.open()
    # Paired to a specific device:
    #fe.open(ChannelID(53708, 17, 37))
    #hr.open(ChannelID(21840, 120 ,81))

    print("++++++++++++++++++++++++++++++++++")
    monitor = None
    mainloop = GLib.MainLoop()
    ble_hrm_start()
    #while True:
    #    try:
    #        time.sleep(1)
    #    except KeyboardInterrupt:
    #        break

    try:
        mainloop.run()
    except KeyboardInterrupt:
        print("KeyboardInterrupt")
    ble_hrm_stop()

    print("+++++++++++++++++++---------------")
    fe.close()
    pm.close()
    hr.close()
    antnode.stop()