コード例 #1
0
ファイル: antnode.py プロジェクト: cecob/ant-fan
 def start(self):
     try:
         self.node.start()
         self.node.setNetworkKey(NETWORK_NUMBER_PUBLIC, self.network)
         logger.info('ANT started. Connecting to devices...')
         for profile in self.deviceManager:
             profile.open()
     except ANTException as err:
         logger.info(f'Could not start ANT.\n{err}')
コード例 #2
0
    def set_power_level(self, power_level):
        if power_level == self.current_power_level or power_level > 3 or power_level < 0:
            return None

        logger.info(f'changing power level to {power_level}')
        self.current_power_level = power_level
        self.__r1.value = power_level == 0
        self.__r2.value = power_level == 2
        self.__r3.value = power_level == 1
コード例 #3
0
 def say_hallo(self):
     logger.info('hi')
     self.__r3.value = True
     sleep(0.25)
     self.__r2.value = True
     sleep(0.25)
     self.__r3.value = False
     sleep(0.25)
     self.__r2.value = False
コード例 #4
0
ファイル: bikecomputer.py プロジェクト: cecob/ant-fan
    def __init__(self, history_caching_time=60, *args: DataSeries):
        self.measurements = {}
        self.antnode = AntNode()
        for series in args:
            self.measurements[series] = Measurement(series,
                                                    ttl=history_caching_time)

        if DataSeries.HEART_RATE in args or DataSeries.RR_INTERVAL in args:
            logger.info('add heart rate sensor')
            self.antnode.add_heart_rate_monitor(wahoo_heart_rate_sensor,
                                                self._process_heart_rate_data)

        logger.info('init completed. starting ant communication')
コード例 #5
0
ファイル: antnode.py プロジェクト: cecob/ant-fan
 def __init__(self, device_profile: DeviceProfile, channel_id: ChannelID):
     self.channel_id = channel_id
     self.device_profile = device_profile
     self.device_profile.callbacks.update({
         'onSearchTimeout':
         lambda x: logger.warn(f'search for {device_profile.name} timed out'
                               ),
         'onDevicePaired':
         lambda x, y: logger.info(
             f'Connected to {device_profile.name} ({channel_id})'),
         'onChannelClosed':
         lambda x: logger.info(f'Channel closed for {device_profile.name}')
     })
コード例 #6
0
    computer = BikeComputer(20, DataSeries.HEART_RATE) \
        .subscribe_once(Event.DATA_AVAILABLE, DataSeries.HEART_RATE, lambda x: fan.say_hallo()) \
        .start()

    while True:
        try:
            time.sleep(5)
            # fan should switch up faster that it would switch down
            avg_hr_5_sec = computer.map_reduce(DataSeries.HEART_RATE, 5,
                                               statistics.mean)
            avg_hr_15_sec = computer.map_reduce(DataSeries.HEART_RATE, 15,
                                                statistics.mean)
            pl_5_sec = map_to_power_level(avg_hr_5_sec)
            pl_15_sec = map_to_power_level(avg_hr_15_sec)

            logger.debug(f'avg 5s HR: {avg_hr_5_sec} -> PL {pl_5_sec} '
                         f'avg 10s HR: {avg_hr_15_sec} -> PL {pl_5_sec}')

            if pl_5_sec >= fan.current_power_level:
                fan.set_power_level(pl_5_sec)
            else:
                fan.set_power_level(pl_15_sec)

        except KeyboardInterrupt:
            break

    computer.stop()
    logger.info('stopped')
else:
    raise ImportError("Run this file directly, don't import it!")
コード例 #7
0
ファイル: antnode.py プロジェクト: cecob/ant-fan
 def close(self):
     logger.info(f'closing communication channel {self.channel_id}')
     self.device_profile.close()
コード例 #8
0
ファイル: antnode.py プロジェクト: cecob/ant-fan
 def open(self):
     logger.info(f'searching for device on channel: {self.channel_id}...')
     self.device_profile.open(channelId=self.channel_id,
                              searchTimeout=255 * 2.5)