Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step counter #209

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion docs/tildagon-apps/reference/badge-hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ To use the `Pin`s:

## `IMU`

The IMU device is a highly integrated, low power inertial measurement unit (IMU) that combines precise acceleration and angular rate (gyroscopic) measurement. The triple axis device has been configured to measure 2g and 2 degree per second ranges.
The IMU device is a highly integrated, low power inertial measurement unit (IMU) that combines precise acceleration and angular rate (gyroscopic) measurement. The triple axis device has been configured to measure 2g and 2 degree per second ranges. It also has a step count function intended for wrist mounted applications.

!!! note "More information about the sensor"

Expand Down Expand Up @@ -409,6 +409,42 @@ class ExampleApp(app.App):
ctx.restore()


__app_export__ = ExampleApp
```

npentrel marked this conversation as resolved.
Show resolved Hide resolved
The following example app measures steps as you walk aroudn with your badge:

```python
import app
import imu

from events.input import Buttons, BUTTON_TYPES


class ExampleApp(app.App):
def __init__(self):
self.button_states = Buttons(self)
self.acc_read = None
self.steps_read = None

def update(self, delta):
if self.button_states.get(BUTTON_TYPES["CANCEL"]):
self.button_states.clear()
self.minimise()
else:
self.steps_read = imu.step_counter_read()

def draw(self, ctx):
ctx.save()
ctx.rgb(0.2, 0, 0).rectangle(-120, -120, 240, 240).fill()
if self.steps_read:
ctx.rgb(1, 0, 0).move_to(-80, -40).text(
"steps:\n{}\n".format(self.steps_read))
else:
ctx.rgb(1, 0, 0).move_to(-80, 0).text("no readings yet")
ctx.restore()


__app_export__ = ExampleApp
npentrel marked this conversation as resolved.
Show resolved Hide resolved
```

Expand All @@ -421,6 +457,7 @@ The api currently only allows access to the raw data.
| ------ | ----------- | --------- | ------- |
| `acc_read()` | Get the accelerometer data. | None | `(x,y,z)`: The accelerometer data as a tuple of floats (m/s^2). |
| `gyro_read()` | Get the gyro data. | None | `(x,y,z)`: The gyro data as a tuple of floats (d/s). |
| `step_counter_read()` | Get the step count | None | `count`: The step count |

### Usage

Expand Down
Loading