def heart_rate_data(computed_heartrate, event_time_ms, rr_interval_ms): global last global stopped t = int(time.time()) if t >= last + 1: power = int(interp(xp, yp, computed_heartrate)) if power: power_meter.update(power) stopped = False elif not stopped: power_meter.update(power) stopped = True last = t
def process(self, msg): if isinstance(msg, message.ChannelBroadcastDataMessage): page = msg.payload[1] & 0x7F if page != 0: return eventTime = convertSB(msg.payload[5:7]) if eventTime == self.lastTime: return revolutions = convertSB(msg.payload[7:9]) cadence = self.calcCadence(eventTime, revolutions) power = int(interp(xp, yp, cadence)) power_meter.update(power) self.lastTime = eventTime self.lastRevolutions = revolutions
def power_from_speed(self, revs_per_sec): kms_per_rev = self.wheel_circumference / 1000.0 speed = revs_per_sec * 3600 * kms_per_rev power = int(interp(self.xp, self.yp, speed)) return power