Skip to content

Commit

Permalink
Create arc.py Example for arc users (#9)
Browse files Browse the repository at this point in the history
* Create arc.py

* Code review comments

* Fix other vairable

* PEP8

* Fix print formatting

Co-authored-by: Artem Popov <artfwo@gmail.com>

* Code review

* Use ring_range

Co-authored-by: Artem Popov <artfwo@gmail.com>

Co-authored-by: Artem Popov <artfwo@gmail.com>
  • Loading branch information
SuuBro and artfwo authored Oct 28, 2020
1 parent 6c52ed7 commit e4f6e02
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/arc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#! /usr/bin/env python3
#
# Test for a push-button monome arc

import asyncio
import monome


class ExampleArcApp(monome.ArcApp):
def __init__(self):
super().__init__()
self.pos = [0, 0, 0, 0]

def on_arc_ready(self):
print('Ready, clearing all rings...')
for n in range(0, 4):
self.arc.ring_all(n, 0)

def on_arc_disconnect(self):
print('Arc disconnected.')

def on_arc_delta(self, ring, delta):
print(f'Ring: {ring} Delta: {delta}')

old_pos = self.pos[ring]
new_pos = old_pos + delta

if new_pos > old_pos:
self.arc.ring_range(ring, old_pos, new_pos, 15)
else:
self.arc.ring_range(ring, new_pos, old_pos, 5)

self.pos[ring] = new_pos

def on_arc_key(self, ring, s):
print(f'Ring: {ring} Pressed: {s > 0}')
self.arc.ring_all(ring, 15 if s > 0 else 0)


if __name__ == '__main__':
loop = asyncio.get_event_loop()
app = ExampleArcApp()

def serialosc_device_added(id, type, port):
if 'arc' not in type:
print(f'ignoring {id} ({type}) as device does not appear to be an arc')
return

print(f'connecting to {id} ({type})')
asyncio.ensure_future(app.arc.connect('127.0.0.1', port))

serialosc = monome.SerialOsc()
serialosc.device_added_event.add_handler(serialosc_device_added)

loop.run_until_complete(serialosc.connect())

loop.run_forever()

0 comments on commit e4f6e02

Please sign in to comment.