bledev.runningspeed
Running Speed and Cadence Service (0x1814): a foot pod for running apps.
Serve it and send the speed and cadence you measure:
from bledev.runningspeed import RunningSpeedCadence
pod = RunningSpeedCadence(stride_length=True, total_distance=True, running_status=True)
ble.register_services(pod.service)
connection = await ble.advertise(name="Pod", services=[pod.SERVICE])
pod.update(2.9, 168, stride_m=1.04, distance_m=1250.0, running=True)
Speed is in metres per second and cadence in steps per minute. Pass
stride_m, distance_m or running only if you created the pod to
report them: the service sets the measurement’s flags from what you send, and
its Feature characteristic tells the app which to expect.
The SC Control Point lets a central set the total distance and ask for the
supported sensor locations. It answers with indications, so run
asyncio.create_task(pod.run()) beside your loop and have the central
subscribe to them. Give on_set_cumulative a function that takes the new
total distance in metres to accept a Set Cumulative Value; without one the
service answers “op code not supported”. On CircuitPython an indication goes
out but its acknowledgement isn’t reported (see bledev.cpble).
ble.register_services() replaces whatever was registered before, so pass
this service together with the others. Any peripheral backend serves it:
MicroPython (bledev.mpble), CircuitPython (bledev.cpble) and the fake one
for tests.
- bledev.runningspeed.encode_measurement(speed_mps, cadence, stride_m=None, distance_m=None, running=None)[source]
The RSC Measurement bytes: speed in 1/256 m/s, cadence, stride in cm, distance in 1/10 m.
runningis True for running, False for walking, None to leave the status out.
- class bledev.runningspeed.RunningSpeedCadence(stride_length=False, total_distance=False, running_status=False, location=None, locations=(), on_set_cumulative=None)[source]
Bases:
objectA Running Speed and Cadence Service.
- Parameters:
stride_length – True if the pod reports stride length.
total_distance – True if it reports total distance.
running_status – True if it says whether the wearer is walking or running.
location – A Sensor Location number (see
bledev._sig.LOCATIONS), or None to leave out the Sensor Location characteristic.locations – The locations the sensor can be set to, when it supports more than one.
on_set_cumulative –
f(distance_m)called when a central sets the total distance; return False to refuse.
- characteristic
notify only.
- Type:
The RSC Measurement
bledev.Characteristic
- update(speed_mps, cadence, stride_m=None, distance_m=None, running=None)[source]
Send a measurement to every central subscribed to it.
- Parameters:
speed_mps – Instantaneous speed in metres per second.
cadence – Steps per minute.
stride_m – Instantaneous stride length in metres.
distance_m – Total distance in metres.
running – True when running, False when walking.