Beispiel #1
0
        private void NextApp(INuimoController controller)
        {
            var currentApp = CurrentApp?.Value;

            if (currentApp != null)
            {
                controller.ThrottledGestureEventOccurred -= currentApp.OnGestureEvent;
                currentApp.OnLostFocus(controller);
            }
            else
            {
                //Set to Last so that when calling NextOrFirst, the first app will be loaded
                CurrentApp = Applications.Last;
            }

            var newAppNode = CurrentApp?.NextOrFirst();
            var newApp     = newAppNode?.Value;

            if (newApp != null)
            {
                controller.ThrottledGestureEventOccurred += newApp.OnGestureEvent;

                controller.DisplayLedMatrixAsync(newApp.Icon);
                newApp.OnFocus(controller);
                Debug.WriteLine($"Switched to {newApp.Name}");
            }

            CurrentApp = newAppNode;
        }
Beispiel #2
0
        public void OnGestureEvent(INuimoController controller, NuimoGestureEvent nuimoGestureEvent)
        {
            if (!IsInitialized)
            {
                controller.DisplayLedMatrixAsync(Icons.Cross);
                return;
            }

            switch (nuimoGestureEvent.Gesture)
            {
            case NuimoGesture.ButtonPress:
                var newState = SwitchGroupOnOff();
                var matrix   = GetPowerMatrix(newState);
                controller.DisplayLedMatrixAsync(matrix);
                break;

            case NuimoGesture.Rotate:
                var newBrightness    = ChangeBrightness(nuimoGestureEvent.Value) / 255.0;
                var brightnessMatrix = ProgressBars.VerticalBar(newBrightness);
                controller.DisplayLedMatrixAsync(brightnessMatrix);
                break;

            case NuimoGesture.SwipeLeft:
            case NuimoGesture.SwipeRight:
                var newRoom       = SwitchRoom(nuimoGestureEvent.Gesture);
                var matrixForRoom = MatrixForRoomClass(newRoom);
                controller.DisplayLedMatrixAsync(matrixForRoom);
                break;

            default:
                break;
            }
        }
 private void RemoveDelegates(INuimoController nuimoController)
 {
     nuimoController.GestureEventOccurred     -= OnNuimoGestureEventAsync;
     nuimoController.FirmwareVersionRead      -= OnFirmwareVersion;
     nuimoController.ConnectionStateChanged   -= OnConnectionState;
     nuimoController.BatteryPercentageChanged -= OnBatteryPercentage;
     nuimoController.LedMatrixDisplayed       -= OnLedMatrixDisplayed;
 }
Beispiel #4
0
 public AvailableNuimoDevice(INuimoController controller)
 {
     Controller = controller;
     Controller.BatteryPercentageChanged += ControllerOnBatteryPercentageChanged;
     Controller.ConnectionStateChanged   += Controller_ConnectionStateChanged;
     Controller.FirmwareVersionRead      += Controller_FirmwareVersionRead;
     Controller.GestureEventOccurred     += Controller_GestureEventOccurred;
 }
Beispiel #5
0
        private void OnNuimoGestureEvent(INuimoController nuimoController, NuimoGestureEvent nuimoGestureEvent)
        {
            Debug.WriteLine("Event: " + nuimoGestureEvent.Gesture + ", " + nuimoGestureEvent.Value);

            if (nuimoGestureEvent.Gesture == NuimoGesture.SwipeDown)
            {
                NextApp(nuimoController);
            }
        }
Beispiel #6
0
        public async void OnFocus(INuimoController nuimoController)
        {
            if (!IsInitialized)
            {
                nuimoController.DisplayLedMatrixAsync(NuimoBuiltinLedMatrix.Busy, 5);
                await SetupHue();

                nuimoController.DisplayLedMatrixAsync(new NuimoLedMatrix());
            }
        }
Beispiel #7
0
        private async Task HandleNewNuimoController(INuimoController nuimoController)
        {
            AddDelegates(nuimoController);
            while (!await nuimoController.ConnectAsync())
            {
            }

            nuimoController.HeartBeatInterval = TimeSpan.FromSeconds(2);
            NextApp(nuimoController);
        }
Beispiel #8
0
 private async Task ShowTimeoutAlert(INuimoController controller)
 {
     for (var i = 0; i < 10; i++)
     {
         var durationSeconds = 0.7;
         controller.DisplayLedMatrixAsync(Icons.Timer, durationSeconds,
                                          NuimoLedMatrixWriteOptions.WithoutWriteResponse);
         await Task.Delay(TimeSpan.FromSeconds(durationSeconds));
     }
 }
Beispiel #9
0
        private async void _pairedNuimoManager_NuimoFound(INuimoController nuimoController)
        {
            var isWhiteListed = _options.WhitelistedNuimos.Any(
                whitelistItem => whitelistItem.DeviceId.Substring(23, 35)
                .Equals(nuimoController.Identifier, StringComparison.OrdinalIgnoreCase));

            if (isWhiteListed)
            {
                await HandleNewNuimoController(nuimoController);
            }
        }
Beispiel #10
0
 private void SetUnset(INuimoController controller)
 {
     if (TimerIsRunning)
     {
         StopCountdown();
     }
     else
     {
         Timer          = new Timer(ProcessCountdownTick, controller, TimeSpan.Zero, TimeSpan.FromSeconds(1));
         TimerIsRunning = true;
     }
 }
Beispiel #11
0
        public void OnGestureEvent(INuimoController sender, NuimoGestureEvent nuimoGestureEvent)
        {
            switch (nuimoGestureEvent.Gesture)
            {
            case NuimoGesture.Rotate:
                ChangeTime(nuimoGestureEvent.Value);
                ShowTime(sender);
                break;

            case NuimoGesture.ButtonPress:
                SetUnset(sender);
                break;
            }
        }
Beispiel #12
0
        private void AddDelegates(INuimoController controller)
        {
            if (controller == null)
            {
                return;
            }

            controller.FirmwareVersionRead += OnFirmwareVersion;
            controller.HardwareVersionRead += OnHardwareVersion;
            controller.ColorRead           += OnColorRead;

            controller.BatteryPercentageChanged += OnBatteryPercentage;
            controller.LedMatrixDisplayed       += OnLedMatrixDisplayed;

            controller.GestureEventOccurred += OnNuimoGestureEvent;

            controller.ConnectionStateChanged += OnConnectionState;
            controller.HeartbeatReceived      += OnHeartbeatReceived;
        }
Beispiel #13
0
        public void OnGestureEvent(INuimoController sender, NuimoGestureEvent nuimoGestureEvent)
        {
            switch (nuimoGestureEvent.Gesture)
            {
            case NuimoGesture.ButtonPress:
                PlayPause();
                break;

            case NuimoGesture.Rotate:
                ChangeVolume(nuimoGestureEvent.Value);
                break;

            case NuimoGesture.SwipeLeft:
                Previous();
                break;

            case NuimoGesture.SwipeRight:
                Next();
                break;
            }
        }
Beispiel #14
0
        private void ShowTime(INuimoController controller)
        {
            var timeDisplay = new NuimoLedMatrix("");

            if (TimeLeft >= TimeSpan.FromHours(1))
            {
                timeDisplay = timeDisplay.AddHours(TimeLeft.Hours);
            }

            if (TimeLeft >= TimeSpan.FromMinutes(1))
            {
                timeDisplay = timeDisplay.AddMinutes(TimeLeft.Minutes);
            }
            else
            {
                timeDisplay = timeDisplay.AddSeconds(TimeLeft.Seconds);
            }

            controller?.DisplayLedMatrixAsync(timeDisplay, 2, NuimoLedMatrixWriteOptions.WithoutWriteResponse);
            Debug.WriteLine(TimeLeft);
        }
Beispiel #15
0
 public void OnGestureEvent(INuimoController sender, NuimoGestureEvent nuimoGestureEvent)
 {
     if (nuimoGestureEvent.Gesture == NuimoGesture.Rotate)
     {
         if (nuimoGestureEvent.Value > 0)
         {
             TestValue += 0.1;
         }
         else if (nuimoGestureEvent.Value < 0)
         {
             TestValue -= 0.1;
         }
         var progressMatrix = ProgressBars.VerticalBar(TestValue);
         sender.DisplayLedMatrixAsync(progressMatrix, 2,
                                      NuimoLedMatrixWriteOptions.WithFadeTransition | NuimoLedMatrixWriteOptions.WithoutWriteResponse);
     }
     if (nuimoGestureEvent.Gesture == NuimoGesture.ButtonPress)
     {
         sender.DisplayLedMatrixAsync(NuimoBuiltinLedMatrix.Busy);
     }
     Debug.WriteLine(nuimoGestureEvent.Gesture);
 }
        private async void ConnectButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_nuimoControllers == null)
            {
                return;
            }
            var oldNuimoController = _nuimoController;

            if (oldNuimoController != null)
            {
                RemoveDelegates(oldNuimoController);
            }
            _nuimoController = _nuimoControllers.ElementAt(PairedNuimosComboBox.SelectedIndex);

            AddDelegates(_nuimoController);

            switch (_nuimoController.ConnectionState)
            {
            case NuimoConnectionState.Disconnected: await _nuimoController.ConnectAsync(); break;

            case NuimoConnectionState.Connected: await _nuimoController.DisconnectAsync(); break;
            }
        }
Beispiel #17
0
 private void OnHardwareVersion(INuimoController nuimoController, string hardwareVersion)
 {
     Debug.WriteLine(hardwareVersion);
 }
Beispiel #18
0
 public void OnLostFocus(INuimoController sender)
 {
     HasFocus = false;
 }
Beispiel #19
0
 public void OnFocus(INuimoController sender)
 {
     HasFocus = true;
 }
Beispiel #20
0
 private void Controller_ConnectionStateChanged(INuimoController arg1, NuimoConnectionState arg2)
 {
     NuimoHub.AllClients.ConnectionStateChanged(arg1.Identifier, arg2);
 }
Beispiel #21
0
 private void OnColorRead(INuimoController nuimoController, NuimoColor color)
 {
     Debug.WriteLine(color);
 }
Beispiel #22
0
 private void ControllerOnBatteryPercentageChanged(INuimoController nuimoController, int i)
 {
     Battery = i;
     NuimoHub.AllClients.BatteryPercentageChanged(nuimoController.Identifier, i);
 }
Beispiel #23
0
 private void Controller_GestureEventOccurred(INuimoController arg1, NuimoGestureEvent arg2)
 {
     NuimoHub.AllClients.ConnectionStateChanged(arg1.Identifier, arg2);
 }
Beispiel #24
0
 private void OnLedMatrixDisplayed(INuimoController nuimoController)
 {
     Debug.WriteLine("LED matrix displayed");
 }
Beispiel #25
0
 private void OnBatteryPercentage(INuimoController nuimoController, int batteryPercentage)
 {
     Debug.WriteLine("Battery percentage: " + batteryPercentage);
 }
Beispiel #26
0
 private void OnConnectionState(INuimoController nuimoController, NuimoConnectionState nuimoConnectionState)
 {
     Debug.WriteLine("Connection state: " + nuimoConnectionState);
 }
Beispiel #27
0
 private void Controller_FirmwareVersionRead(INuimoController arg1, string arg2)
 {
     NuimoHub.AllClients.ConnectionStateChanged(arg1.Identifier, arg2);
 }
Beispiel #28
0
 private void OnHeartbeatReceived(INuimoController nuimoController, object heartbeatObject)
 {
     Debug.WriteLine("Heartbeat received");
 }
Beispiel #29
0
 public void OnFocus(INuimoController sender)
 {
     //throw new NotImplementedException();
 }
Beispiel #30
0
 private void OnFirmwareVersion(INuimoController nuimoController, string firmwareVersion)
 {
     Debug.WriteLine(firmwareVersion);
 }