Skip to content

Commit

Permalink
example: demo for UP CAPES
Browse files Browse the repository at this point in the history
Signed-off-by: Pineda <[email protected]>
  • Loading branch information
jpineda3 committed Feb 24, 2025
1 parent bcadbe8 commit 9dba6ab
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
80 changes: 80 additions & 0 deletions examples/adis16480_doodlejump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This demo application converts adis16480's accel channel values into keyboard inputs
# great for controlling existing games

import adi #pyadi-iio
import keyboard #pip install keyboard

dev = adi.adis16480(uri='ip:172.27.6.191')

dev.rx_output_type = "raw"
dev.rx_enabled_channels = [3, 4, 5]
dev.sample_rate = 20000
dev.rx_buffer_size = 100

print("Product id: " + str(dev.product_id))
print("Serial number: " + dev.serial_number)
print("Firmware revision: " + dev.firmware_revision)
print("Firmware date: " + dev.firmware_date)
print("\nSampling frequency: " + str(dev.sample_rate))


print("\nX acceleration: " + str(dev.accel_x_conv) + " m/s^2")
print("Y acceleration: " + str(dev.accel_y_conv) + " m/s^2")
print("Z acceleration: " + str(dev.accel_z_conv) + " m/s^2")

# limits
directions = {
"center" : (-1.9,1.9),
"soft_right" : (-6.9,-2),
"hard_right" : (-15,-7),
"soft_left" : (2,6.9),
"hard_left" : (7,15),
}

# directions
actions=[
"center",
"soft_right",
"soft_left",
"hard_right",
"hard_left",
]

def move_x(action):
if action in ["hard_left", "soft_left"]:
# keyboard.release('down')
print("left")
keyboard.release('right')
keyboard.press('left')
elif action in ["hard_right", "soft_right"]:
# keyboard.release('up')
print("right")
keyboard.release('left')
keyboard.press('right')
else:
print("center")
keyboard.release('right')
keyboard.release('left')

def move_y(action):
if action in ["hard_left", "soft_left"]:
# keyboard.release('down')
print("down")
keyboard.press('down')
elif action in ["hard_right", "soft_right"]:
# keyboard.release('up')
print("up")
keyboard.press('up')
else:
print("center")
keyboard.release('down')
keyboard.release('up')

while(True):
for action in actions:
ll,ul = directions[action]
if ll <= dev.accel_x_conv <= ul:
move_x(action)
if ll <= dev.accel_y_conv <= ul:
move_y(action)

77 changes: 77 additions & 0 deletions examples/adis16480_subwaysurfers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This demo application converts adis16480's accel channel values into keyboard inputs
# great for controlling existing games

import adi #pyadi-iio
import keyboard #pip install keyboard
from collections import Counter
import time

dev = adi.adis16480(uri='ip:172.27.6.191')

dev.rx_output_type = "raw"
dev.rx_enabled_channels = [3, 4, 5]
dev.sample_rate = 20000
dev.rx_buffer_size = 100

print("Product id: " + str(dev.product_id))
print("Serial number: " + dev.serial_number)
print("Firmware revision: " + dev.firmware_revision)
print("Firmware date: " + dev.firmware_date)
print("\nSampling frequency: " + str(dev.sample_rate))


print("\nX acceleration: " + str(dev.accel_x_conv) + " m/s^2")
print("Y acceleration: " + str(dev.accel_y_conv) + " m/s^2")
print("Z acceleration: " + str(dev.accel_z_conv) + " m/s^2")

# limits
directions = {
"center" : (-1.9,1.9),
"soft_right" : (-6.9,-2),
"hard_right" : (-15,-7),
"soft_left" : (2,6.9),
"hard_left" : (7,15),
}

# directions
actions=[
"center",
"soft_right",
"soft_left",
"hard_right",
"hard_left",
]

recent_actions = []

def move_x(action):
if action in ["hard_left", "soft_left"]:
recent_actions.append('left')
elif action in ["hard_right", "soft_right"]:
recent_actions.append('right')

def move_y(action):
if action in ["hard_left", "soft_left"]:
recent_actions.append('up')
elif action in ["hard_right", "soft_right"]:
recent_actions.append('down')

while(True):
for action in actions:
ll,ul = directions[action]
if ll <= dev.accel_x_conv <= ul:
move_x(action)
if ll <= dev.accel_y_conv <= ul:
move_y(action)
if len(recent_actions) > 2:
counter = Counter(recent_actions)
key, count = counter.most_common(1)[0]
# if len(recent_actions) > 0:
key = recent_actions[0]
keyboard.press(key)
keyboard.release(key)
print(key)
# time.sleep(0.05)
recent_actions = []


1 change: 1 addition & 0 deletions requirements_demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keyboard

0 comments on commit 9dba6ab

Please sign in to comment.