Ejemplo n.º 1
0
 def __init__(self, macAddress):
     Nuimo.__init__(self, macAddress)
     self.onkyo = Onkyo()
     
     print("Onkyo Host: %s" % self.onkyo.Host)
     print("Onkyo power state is %s" % self.onkyo.PowerState())
     print("Onkyo volume level is %s" % self.onkyo.VolumeLevel())
Ejemplo n.º 2
0
 def foundDevice(addr):
     print 'found device: ' + addr
     nuimo = Nuimo(addr)
     nuimo.set_delegate(CustomNuimoDelegate(nuimo, app))
     nuimo.connect()
     showImagesOnNuimo(nuimo)
     while True:
         nuimo.waitForNotifications()
Ejemplo n.º 3
0
 def __init__(self, bled_com, nuimo_mac):
     NuimoDelegate.__init__(self)
     self.nuimo = Nuimo(bled_com, nuimo_mac, self)
     self.sonos = SonosAPI()
     self.default_led_timeout = 3
     self.max_volume = 42 # should be dividable by 7
     self.volume_bucket_size = int(self.max_volume / 7)
     self.last_vol_matrix = None
     self.vol_reset_timer = None
     self.stop_pending = False
Ejemplo n.º 4
0
class NuimoSonosController(NuimoDelegate):

    def __init__(self, bled_com, nuimo_mac):
        NuimoDelegate.__init__(self)
        self.nuimo = Nuimo(bled_com, nuimo_mac, self)
        self.sonos = SonosAPI()
        self.default_led_timeout = 3
        self.max_volume = 42 # should be dividable by 7
        self.volume_bucket_size = int(self.max_volume / 7)
        self.last_vol_matrix = None
        self.vol_reset_timer = None
        self.stop_pending = False

    def start(self):
        self.nuimo.connect()

        while not self.stop_pending:
            time.sleep(0.1)

        self.sonos.disconnect()
        self.nuimo.disconnect()
        self.nuimo.terminate()

    def stop(self):
        self.stop_pending = True

    def on_button(self):
        if self.sonos.is_playing():
            self.sonos.pause()
            self.nuimo.display_led_matrix(led_configs.pause, self.default_led_timeout)
        else:
            self.sonos.play()
            self.nuimo.display_led_matrix(led_configs.play, self.default_led_timeout)

    def on_swipe_right(self):
        self.sonos.next()
        self.nuimo.display_led_matrix(led_configs.next, self.default_led_timeout)

    def on_swipe_left(self):
        self.sonos.prev()
        self.nuimo.display_led_matrix(led_configs.previous, self.default_led_timeout)

    def on_fly_right(self):
        self.on_swipe_right()

    def on_fly_left(self):
        self.on_swipe_left()

    def on_wheel_right(self, value):
        self.sonos.vol_up(self._calculate_volume_delta(value))
        self._show_volume()

    def on_wheel_left(self, value):
        self.sonos.vol_down(self._calculate_volume_delta(value))
        self._show_volume()

    def on_connect(self):
        self.nuimo.display_led_matrix(led_configs.default, self.default_led_timeout)

    def _calculate_volume_delta(self, value):
        return min(value / 20 + 1, 5)

    def _show_volume(self):
        volume = self.sonos.get_volume()
        if volume is None: volume = 0

        bucket = min(int(math.ceil(volume / self.volume_bucket_size)), 7)
        matrix = getattr(led_configs, 'vol' + str(bucket))

        if matrix != self.last_vol_matrix:
            self.last_vol_matrix = matrix
            self.nuimo.display_led_matrix(matrix, self.default_led_timeout)
            if self.vol_reset_timer is not None:
                self.vol_reset_timer.cancel()
            self.vol_reset_timer = Timer(self.default_led_timeout+1, self._reset_vol).start()

    def _reset_vol(self):
        self.last_vol_matrix = None
        self.vol_reset_timer = None
Ejemplo n.º 5
0
 def __init__(self, macAddress):
     Nuimo.__init__(self, macAddress)        
     self.display = Display()
     self.font = ValidFonts()
     self.timerValue = 0
Ejemplo n.º 6
0
def connect(addr):
    nuimo = Nuimo(addr)
    nuimo.set_delegate(NuimoConsoleLoggerDelegate(nuimo))

    # Connect to Nuimo
    print("Trying to connect to %s. Press Ctrl+C to cancel." % addr)
    try:
        nuimo.connect()
    except BTLEException:
        print("Failed to connect to %s. Make sure to:\n  1. Disable the Bluetooth device: hciconfig hci0 down\n  2. Enable the Bluetooth device: hciconfig hci0 up\n  3. Enable BLE: btmgmt le on\n  4. Pass the right MAC address: hcitool lescan | grep Nuimo" % nuimo.macAddress)
        sys.exit()
    print("Connected. Waiting for input events...")

    # Display some LEDs matrices and wait for notifications
    nuimo.displayLedMatrix(
        "         " +
        " ***     " +
        " *  * *  " +
        " *  *    " +
        " ***  *  " +
        " *    *  " +
        " *    *  " +
        " *    *  " +
        "         ", 2.0)
    time.sleep(2)
    nuimo.displayLedMatrix(
        " **   ** " +
        " * * * * " +
        "  *****  " +
        "  *   *  " +
        " * * * * " +
        " *  *  * " +
        " * * * * " +
        "  *   *  " +
        "   ***   ", 20.0)

    try:
        while True:
            nuimo.waitForNotifications()
    except BTLEException as e:
        print("Connection error:", e)
    except KeyboardInterrupt:
        print("Program aborted")