/// <summary> /// Updates LED on the physical controller based on touch pad input. /// </summary> private void UpdateLED() { if (_mlInputController.Touch1Active) { // Get angle of touchpad position. float angle = -Vector2.SignedAngle(Vector2.up, _mlInputController.Touch1PosAndForce); if (angle < 0.0f) { angle += 360.0f; } // Get the correct hour and map it to [0,6] int index = (int)((angle + HALF_HOUR_IN_DEGREES) * DEGREES_PER_HOUR) % LED_INDEX_DELTA; // Pass from hour to MLInputControllerFeedbackPatternLED index [0,6] -> [MAX_LED_INDEX, MIN_LED_INDEX + 1, ..., MAX_LED_INDEX - 1] index = (MAX_LED_INDEX + index > MAX_LED_INDEX) ? MIN_LED_INDEX + index : MAX_LED_INDEX; if (_lastLEDindex != index) { // a duration of 0 means leave it on indefinitely _mlInputController.StartFeedbackPatternLED((MLInputControllerFeedbackPatternLED)index, MLInputControllerFeedbackColorLED.BrightCosmicPurple, 0); _lastLEDindex = index; } } else if (_lastLEDindex != -1) { _mlInputController.StopFeedbackPatternLED(); _lastLEDindex = -1; } }
/// <summary> /// Updates LED on the physical controller based on touch pad input. /// </summary> private void UpdateLED() { if (!_controllerConnectionHandler.IsControllerValid()) { return; } MLInputController controller = _controllerConnectionHandler.ConnectedController; if (controller.Touch1Active) { // Get angle of touchpad position. float angle = -Vector2.SignedAngle(Vector2.up, controller.Touch1PosAndForce); if (angle < 0.0f) { angle += 360.0f; } // Get the correct hour and map it to [0,6] int index = (int)((angle + HALF_HOUR_IN_DEGREES) * DEGREES_PER_HOUR) % LED_INDEX_DELTA; // Pass from hour to MLInputControllerFeedbackPatternLED index [0,6] -> [MAX_LED_INDEX, MIN_LED_INDEX + 1, ..., MAX_LED_INDEX - 1] index = (MAX_LED_INDEX + index > MAX_LED_INDEX) ? MIN_LED_INDEX + index : MAX_LED_INDEX; if (_lastLEDindex != index) { // a duration of 0 means leave it on indefinitely if (controller.TouchpadGesture.Type == MLInputControllerTouchpadGestureType.Swipe) { _color = MLInputControllerFeedbackColorLED.BrightCosmicPurple; } else if (controller.TouchpadGesture.Type == MLInputControllerTouchpadGestureType.Tap) { _color = MLInputControllerFeedbackColorLED.BrightCelestialBlue; } else if (controller.TouchpadGesture.Type == MLInputControllerTouchpadGestureType.RadialScroll) { _color = MLInputControllerFeedbackColorLED.BrightMissionRed; } else if (controller.TouchpadGesture.Type == MLInputControllerTouchpadGestureType.SecondForceDown) { _color = MLInputControllerFeedbackColorLED.PastelFloridaOrange; } controller.StartFeedbackPatternLED((MLInputControllerFeedbackPatternLED)index, _color, 0); _lastLEDindex = index; } } else if (_lastLEDindex != -1) { controller.StopFeedbackPatternLED(); _lastLEDindex = -1; } }