Last active
January 4, 2018 10:04
-
-
Save avichalp/5e825c4ee8787e18126a4da08186e1b5 to your computer and use it in GitHub Desktop.
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
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