Skip to content

Commit

Permalink
Fix examples in analogin docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xs5871 committed Jan 2, 2025
1 parent 4ecd7aa commit b89a698
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 11 additions & 8 deletions docs/en/analogin.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ value in the domain [0, 65535].
```python
from kmk.modules.analogin import AnalogInput
a = AnalogInput(
input: AnalogIn,
filter: Optional(Callable[AnalogIn, int]) = lambda input:input.value>>8,
input: AnalogInput,
filter: Optional(Callable[AnalogInput, int]) = lambda input:input.value>>8,
)

a.value
Expand Down Expand Up @@ -71,7 +71,7 @@ To be used in handler functions.
The analog version of [`Key` objects](keys.md).

```python
from analogin import AnalogEvent
from kmk.modules.analogin import AnalogEvent

AE = AnalogEvent(
on_change: Callable[self, AnalogInput, Keyboard, None] = pass,
Expand Down Expand Up @@ -99,9 +99,9 @@ AK = AnalogKey(
```python
import board
from analogio import AnalogIn
from kmk.modules.analogin import AnalogIn
from kmk.modules.analogin import AnalogInput, AnalogInputs

analog = AnalogIn(
analog = AnalogInputs(
[
AnalogInput(AnalogIn(board.A0)),
AnalogInput(AnalogIn(board.A1)),
Expand Down Expand Up @@ -131,7 +131,7 @@ import board
import busio
import adafruit_mcp4725

from kmk.modules.analogin import AnalogEvent, AnalogInput
from kmk.modules.analogin import AnalogEvent, AnalogInput, AnalogInputs

i2c = busio.I2C(board.SCL, board.SDA)
dac = adafruit_mcp4725.MCP4725(i2c)
Expand All @@ -143,13 +143,16 @@ def adj_ht_taptime(self, event, keyboard):
microcontroller.reset()

HTT = AnalogEvent(
on_press=adj_ht_taptime,
on_change=adj_ht_taptime,
on_hold=lambda self, event, keyboard: rgb.increase_hue(16),
)

a0 = AnalogInput(dac, lambda _: int(_.value / 0xFFFF * 1980) + 20)

analog = AnalogIn(
analog = AnalogInputs(
[a0],
[[HTT]],
)

keyboard.modules.append(analog)
```
1 change: 0 additions & 1 deletion kmk/modules/analogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, key, threshold=127):
self.pressed = False

def on_change(self, event, keyboard):
debug(event.value)
if event.value >= self.threshold and not self.pressed:
self.pressed = True
keyboard.pre_process_key(self.key, True)
Expand Down

0 comments on commit b89a698

Please sign in to comment.