Skip to content

Instantly share code, notes, and snippets.

@avichalp
Last active January 4, 2018 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avichalp/5e825c4ee8787e18126a4da08186e1b5 to your computer and use it in GitHub Desktop.
Save avichalp/5e825c4ee8787e18126a4da08186e1b5 to your computer and use it in GitHub Desktop.
from nuimo import Controller
from nuimo import ControllerListener
from nuimo import ControllerManager
from nuimo import ControllerManagerListener
from nuimo import LedMatrix
manager = ControllerManager(adapter_name='hci0')
class NuimoControllerListener(ControllerListener):
def __init__(self, controller):
self.controller = controller
def received_gesture_event(self, event):
print("nuimo sent gesture event", str(event))
def started_connecting(self):
print("started connecting ")
def connect_succeeded(self):
# WTF???
# Why is it not printing.
# Does it even print on the simulator?
print("connection succeeded")
matrix = LedMatrix(
"* *"
" * * "
" * * "
" * * "
" * "
" * * "
" * * "
" * * "
"* *"
)
self.controller.display_matrix(matrix)
def connect_failed(self, error):
print("connection failed")
def started_disconnecting(self):
print("starting to disconnect")
def disconnect_succeeded(self):
print("diconnect complete")
class ControllerManagerPrintListner(ControllerManagerListener):
'''
Listner class.
Objects of this class should be used
with the ControllerManager instance to connect to nuimo
via bluetooth.
For eg: manager.listner = ControllerManagerPrintListner()
'''
def controller_discovered(self, controller):
print("Discovered Nuimo with Mac address: ", controller.mac_address)
controller.listener = NuimoControllerListener(controller)
controller.connect()
print("is controller connected ", controller.is_connected())
# start listener? how?
# Todo: Need to look up how protocol works later.
manager.listener = ControllerManagerPrintListner()
# Try to find the numino via bluetooth
print("Start device discovery")
manager.start_discovery()
# What does run does
# Todo: Need to look up how protocol works later.
manager.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment