-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create arc.py Example for arc users (#9)
* 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
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |