Skip to content

Commit

Permalink
update ftms example for target setting features and simulation parame…
Browse files Browse the repository at this point in the history
…ters
  • Loading branch information
bytosaur committed Mar 6, 2024
1 parent c0d9471 commit 563ca3e
Showing 1 changed file with 66 additions and 42 deletions.
108 changes: 66 additions & 42 deletions examples/fitness_machine_service_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,49 @@ async def run(address):
async with BleakClient(address, timeout=10) as client:
ftms = FitnessMachineService(client)

# Print all 'read' characteristics
# Print 'read' characteristics

supported_resistance_level_range = (
await ftms.get_supported_resistance_level_range()
)
### Fitness Machine Features
fitness_machine_features, target_setting_features = await ftms.get_fitness_machine_feature()
fitness_machine_features = fitness_machine_features._asdict()
target_setting_features = target_setting_features._asdict()

print("Supported resistance level range:")
print(supported_resistance_level_range)
print()

max_resistance = supported_resistance_level_range.maximum_resistance
def print_features(features):
for key, value in features.items():
print(f"{key}: {value}")
print()

print("Fitness machine feature:")
print_features(fitness_machine_features)

supported_power_range = await ftms.get_supported_power_range()
print("Target setting features:")
print_features(target_setting_features)

print("Supported power range:")
print(supported_power_range)
print()
print(target_setting_features)

max_power = supported_power_range.maximum_power

fitness_machine_feature = await ftms.get_fitness_machine_feature()
if target_setting_features["resistance_target_setting_supported"]:
supported_resistance_level_range = (
await ftms.get_supported_resistance_level_range()
)
print("Supported resistance level range:")
print(supported_resistance_level_range)
print()
max_resistance = supported_resistance_level_range.maximum_resistance

print("Fitness machine feature:")
print(fitness_machine_feature)
print()
if target_setting_features["power_target_setting_supported"]:
supported_power_range = await ftms.get_supported_power_range()
print("Supported power range:")
print(supported_power_range)
print()
max_power = supported_power_range.maximum_power

# Start receiving and printing 'notify' characteristics
def print_indoor_bike_data(data):
print("Received indoor bike data:")
print(data)
print()

# Start receiving and printing 'notify' characteristics
ftms.set_indoor_bike_data_handler(print_indoor_bike_data)
await ftms.enable_indoor_bike_data_notify()

Expand Down Expand Up @@ -73,44 +84,57 @@ def print_control_point_response(message):
# 3. (recommended) 'write' a reset command
await ftms.reset()

print(
"Setting target resistance level to 25 percent of maximum resistance level..."
)
await ftms.set_target_resistance_level(max_resistance * 0.25)
# Set target resistance level
if target_setting_features["resistance_target_setting_supported"]:
print("Setting target resistance level to 25 percent of maximum resistance level...")
await ftms.set_target_resistance_level(max_resistance * 0.25)

await asyncio.sleep(5)
await asyncio.sleep(5)

print(
"Increasing target resistance level to 50 percent of maximum resistance level..."
)
await ftms.set_target_resistance_level(max_resistance * 0.5)
print("Increasing target resistance level to 50 percent of maximum resistance level...")
await ftms.set_target_resistance_level(max_resistance * 0.5)

await asyncio.sleep(5)
await asyncio.sleep(5)

# Reset target resistance level
print("Resetting target resistance level...")
# Reset target resistance level
print("Resetting target resistance level...")

await ftms.reset()
await ftms.reset()

power_level = 4 / 100 * max_power
print(f"Increasing target power to 4 percent of maximum power ({power_level}W).")
print("The trainer will automatically adjust resistance based on your leg speed.")
print(f"Try pedaling above {power_level}W to feel decreasing resistance, and vice versa.")
await ftms.set_target_power(power_level)
# Set target power
if target_setting_features["power_target_setting_supported"]:
power_level = 4 / 100 * max_power
print(f"Increasing target power to 4 percent of maximum power ({power_level}W).")
print("The trainer will automatically adjust resistance based on your leg speed.")
print(f"Try pedaling above {power_level}W to feel decreasing resistance, and vice versa.")
await ftms.set_target_power(power_level)

await asyncio.sleep(30)
await asyncio.sleep(30)

# Reset
print("Resetting target power...")
await ftms.reset()
# Reset
print("Resetting target power...")
await ftms.reset()

# Set simulation parameters
if target_setting_features["indoor_bike_simulation_parameters_supported"]:
print("Setting indoor bike simulation parameters to 0")
await ftms.set_simulation_parameters(0, 0, 0, 0)
await asyncio.sleep(5)
print("Setting indoor bike simulation grade to 10%")
print("if connected to a compatible machine (like elite rizer), this should set its grade to +10%")
await ftms.set_simulation_parameters(0, 1000, 0, 0)
await asyncio.sleep(5)

print("Resetting indoor bike simulation parameters...")
await ftms.reset()


if __name__ == "__main__":
import os

os.environ["PYTHONASYNCIODEBUG"] = str(1)

device_address = "DEVICE_ADDRESS HERE"
device_address = "1702F6B3-5042-A004-DE51-A89AC74BBB84"
loop = asyncio.get_event_loop()
loop.run_until_complete(run(device_address))

Expand Down

0 comments on commit 563ca3e

Please sign in to comment.