diff --git a/Universal x86 Tuning Utility Handheld/Scripts/ControllerControl.cs b/Universal x86 Tuning Utility Handheld/Scripts/ControllerControl.cs index 1956aad..22d7b9f 100644 --- a/Universal x86 Tuning Utility Handheld/Scripts/ControllerControl.cs +++ b/Universal x86 Tuning Utility Handheld/Scripts/ControllerControl.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media; using Universal_x86_Tuning_Utility_Handheld.Scripts.Misc; namespace Universal_x86_Tuning_Utility_Handheld.Scripts @@ -21,7 +22,7 @@ internal class ControllerControl static HidHideControlService con = new HidHideControlService(); static ViGEmClient viGEmClient = new ViGEmClient(); - static IXbox360Controller targetController = viGEmClient.CreateXbox360Controller(); + static IXbox360Controller targetController360 = viGEmClient.CreateXbox360Controller(); public static bool isStarted = false; @@ -30,7 +31,7 @@ public static async void SetUp() await Task.Run(() => { HideOriginalController(false); - targetController.Connect(); + targetController360.Connect(); while (isStarted) { @@ -43,7 +44,7 @@ public static async void SetUp() public static void Stop() { HideOriginalController(true); - targetController.Disconnect(); + targetController360.Disconnect(); viGEmClient.Dispose(); } @@ -95,33 +96,36 @@ static void UpdateController(UserIndex index) { Controller physicalController = new Controller(index); - State state = physicalController.GetState(); + if (physicalController.IsConnected) + { + State state = physicalController.GetState(); - targetController.SetButtonState(Xbox360Button.Start, (state.Gamepad.Buttons & GamepadButtonFlags.Start) != 0); - targetController.SetButtonState(Xbox360Button.Back, (state.Gamepad.Buttons & GamepadButtonFlags.Back) != 0); + targetController360.SetButtonState(Xbox360Button.Start, (state.Gamepad.Buttons & GamepadButtonFlags.Start) != 0); + targetController360.SetButtonState(Xbox360Button.Back, (state.Gamepad.Buttons & GamepadButtonFlags.Back) != 0); - if (Global._appVis != Visibility.Visible) - { - targetController.SetButtonState(Xbox360Button.A, (state.Gamepad.Buttons & GamepadButtonFlags.A) != 0); - targetController.SetButtonState(Xbox360Button.B, (state.Gamepad.Buttons & GamepadButtonFlags.B) != 0); - targetController.SetButtonState(Xbox360Button.X, (state.Gamepad.Buttons & GamepadButtonFlags.X) != 0); - targetController.SetButtonState(Xbox360Button.Y, (state.Gamepad.Buttons & GamepadButtonFlags.Y) != 0); - targetController.SetButtonState(Xbox360Button.LeftShoulder, (state.Gamepad.Buttons & GamepadButtonFlags.LeftShoulder) != 0); - targetController.SetButtonState(Xbox360Button.RightShoulder, (state.Gamepad.Buttons & GamepadButtonFlags.RightShoulder) != 0); - targetController.SetButtonState(Xbox360Button.LeftThumb, (state.Gamepad.Buttons & GamepadButtonFlags.LeftThumb) != 0); - targetController.SetButtonState(Xbox360Button.RightThumb, (state.Gamepad.Buttons & GamepadButtonFlags.RightThumb) != 0); - - targetController.SetButtonState(Xbox360Button.Up, (state.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0); - targetController.SetButtonState(Xbox360Button.Down, (state.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0); - targetController.SetButtonState(Xbox360Button.Left, (state.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0); - targetController.SetButtonState(Xbox360Button.Right, (state.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0); - - targetController.SetAxisValue(0, state.Gamepad.LeftThumbX); - targetController.SetAxisValue(1, state.Gamepad.LeftThumbY); - targetController.SetAxisValue(2, state.Gamepad.RightThumbX); - targetController.SetAxisValue(3, state.Gamepad.RightThumbY); - targetController.SetSliderValue(0, state.Gamepad.LeftTrigger); - targetController.SetSliderValue(1, state.Gamepad.RightTrigger); + if (Global._appVis != Visibility.Visible) + { + targetController360.SetButtonState(Xbox360Button.A, (state.Gamepad.Buttons & GamepadButtonFlags.A) != 0); + targetController360.SetButtonState(Xbox360Button.B, (state.Gamepad.Buttons & GamepadButtonFlags.B) != 0); + targetController360.SetButtonState(Xbox360Button.X, (state.Gamepad.Buttons & GamepadButtonFlags.X) != 0); + targetController360.SetButtonState(Xbox360Button.Y, (state.Gamepad.Buttons & GamepadButtonFlags.Y) != 0); + targetController360.SetButtonState(Xbox360Button.LeftShoulder, (state.Gamepad.Buttons & GamepadButtonFlags.LeftShoulder) != 0); + targetController360.SetButtonState(Xbox360Button.RightShoulder, (state.Gamepad.Buttons & GamepadButtonFlags.RightShoulder) != 0); + targetController360.SetButtonState(Xbox360Button.LeftThumb, (state.Gamepad.Buttons & GamepadButtonFlags.LeftThumb) != 0); + targetController360.SetButtonState(Xbox360Button.RightThumb, (state.Gamepad.Buttons & GamepadButtonFlags.RightThumb) != 0); + + targetController360.SetButtonState(Xbox360Button.Up, (state.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0); + targetController360.SetButtonState(Xbox360Button.Down, (state.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0); + targetController360.SetButtonState(Xbox360Button.Left, (state.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0); + targetController360.SetButtonState(Xbox360Button.Right, (state.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0); + + targetController360.SetAxisValue(0, state.Gamepad.LeftThumbX); + targetController360.SetAxisValue(1, state.Gamepad.LeftThumbY); + targetController360.SetAxisValue(2, state.Gamepad.RightThumbX); + targetController360.SetAxisValue(3, state.Gamepad.RightThumbY); + targetController360.SetSliderValue(0, state.Gamepad.LeftTrigger); + targetController360.SetSliderValue(1, state.Gamepad.RightTrigger); + } } } } diff --git a/Universal x86 Tuning Utility Handheld/Scripts/Misc/Controller_Event.cs b/Universal x86 Tuning Utility Handheld/Scripts/Misc/Controller_Event.cs new file mode 100644 index 0000000..e85010f --- /dev/null +++ b/Universal x86 Tuning Utility Handheld/Scripts/Misc/Controller_Event.cs @@ -0,0 +1,554 @@ +using SharpDX.XInput; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Threading; +using Universal_x86_Tuning_Utility_Handheld.Properties; + +namespace Universal_x86_Tuning_Utility_Handheld.Scripts.Misc +{ + internal class Controller_Event + { + public static Controller? controller; + public static Gamepad currentGamePad; + public static Gamepad previousGamePad; + + public static bool suspendEventsForGamepadHotKeyProgramming = false; + + public static DispatcherTimer timerController = new DispatcherTimer(DispatcherPriority.Send); + + public static buttonEvents buttonEvents = new buttonEvents(); + public static int activeTimerTickInterval = 60; + public static int passiveTimerTickInterval = 100; + + + + + public static void start_Controller_Management() + { + //create background thread to handle controller input + getController(); + //timerController.Interval = TimeSpan.FromMilliseconds(activeTimerTickInterval); + //timerController.Tick += controller_Tick; + + //timerController.Start(); + Thread controllerThread = new Thread(controller_Tickthread); + controllerThread.IsBackground = true; + controllerThread.Start(); + } + private static string continuousInputNew = ""; + private static string continuousInputCurrent = ""; + private static int continuousInputCounter = 0; + private static void controller_Tick(object sender, EventArgs e) + { + //start timer to read and compare controller inputs + //Controller input handler + //error number CM05 + try + { + if (controller == null) + + + { + getController(); + if (controller.IsConnected == false) + { + getController(); + } + } + else if (!controller.IsConnected) + { + getController(); + } + + + if (controller != null) + { + if (controller.IsConnected) + { + //a quick routine to check other controllers for the swap controller command + checkSwapController(); + + //var watch = System.Diagnostics.Stopwatch.StartNew(); + currentGamePad = controller.GetState().Gamepad; + + ushort btnShort = ((ushort)currentGamePad.Buttons); + + + if (!suspendEventsForGamepadHotKeyProgramming) + { + //check if controller combo is in controller hot key dictionary + + + //reset continuousNew for every cycle + continuousInputNew = ""; + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Back) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Back)) + { + buttonEvents.raiseControllerInput("Back"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Start) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Start)) + { + buttonEvents.raiseControllerInput("Start"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb)) + { + buttonEvents.raiseControllerInput("L3"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.RightThumb) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.RightThumb)) + { + buttonEvents.raiseControllerInput("R3"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.A) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.A)) + { + buttonEvents.raiseControllerInput("A"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.X) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.X)) + { + buttonEvents.raiseControllerInput("X"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Y) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Y)) + { + buttonEvents.raiseControllerInput("Y"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.B) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.B)) + { + buttonEvents.raiseControllerInput("B"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) + { + buttonEvents.raiseControllerInput("LB"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder)) + { + buttonEvents.raiseControllerInput("RB"); + } + if (currentGamePad.LeftTrigger > 200 && previousGamePad.LeftTrigger <= 200) + { + buttonEvents.raiseControllerInput("LT"); + } + if (currentGamePad.RightTrigger > 200 && previousGamePad.RightTrigger <= 200) + { + buttonEvents.raiseControllerInput("RT"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) || currentGamePad.LeftThumbY > 12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) && previousGamePad.LeftThumbY <= 12000) + { + buttonEvents.raiseControllerInput("Up"); + } + else + { + continuousInputNew = "Up"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || currentGamePad.LeftThumbY < -12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) && previousGamePad.LeftThumbY >= -12000) + { + buttonEvents.raiseControllerInput("Down"); + } + else + { + continuousInputNew = "Down"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) || currentGamePad.LeftThumbX > 12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) && previousGamePad.LeftThumbX <= 12000) + { + buttonEvents.raiseControllerInput("Right"); + } + else + { + continuousInputNew = "Right"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) || currentGamePad.LeftThumbX < -12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) && previousGamePad.LeftThumbX >= -12000) + { + buttonEvents.raiseControllerInput("Left"); + } + else + { + continuousInputNew = "Left"; + } + } + + + if (continuousInputNew != continuousInputCurrent) + { + continuousInputCurrent = continuousInputNew; + continuousInputCounter = 1; + } + else + { + if (continuousInputCurrent != "") + { + continuousInputCounter++; + if (continuousInputCounter > 9) + { + + buttonEvents.raiseControllerInput(continuousInputCurrent); + } + } + + } + + } + + + + } + //watch.Stop(); + //Debug.WriteLine($"Total Execution Time: {watch.ElapsedMilliseconds} ms"); + //doSomeWork(); + + previousGamePad = currentGamePad; + } + } + catch (Exception ex) + { + + } + + + + } + private static void controller_Tickthread() + { + //start timer to read and compare controller inputs + //Controller input handler + //error number CM05 + while (true) + { + try + { + if (controller == null) + + + { + getController(); + if (controller.IsConnected == false) + { + getController(); + } + } + else if (!controller.IsConnected) + { + getController(); + } + + + if (controller != null) + { + if (controller.IsConnected) + { + //a quick routine to check other controllers for the swap controller command + checkSwapController(); + + //var watch = System.Diagnostics.Stopwatch.StartNew(); + currentGamePad = controller.GetState().Gamepad; + + ushort btnShort = ((ushort)currentGamePad.Buttons); + + + if (!suspendEventsForGamepadHotKeyProgramming) + { + + + //reset continuousNew for every cycle + continuousInputNew = ""; + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Back) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Back)) + { + buttonEvents.raiseControllerInput("Back"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Start) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Start)) + { + buttonEvents.raiseControllerInput("Start"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb)) + { + buttonEvents.raiseControllerInput("L3"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.RightThumb) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.RightThumb)) + { + buttonEvents.raiseControllerInput("R3"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.A) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.A)) + { + buttonEvents.raiseControllerInput("A"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.X) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.X)) + { + buttonEvents.raiseControllerInput("X"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.Y) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.Y)) + { + buttonEvents.raiseControllerInput("Y"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.B) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.B)) + { + buttonEvents.raiseControllerInput("B"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) + { + buttonEvents.raiseControllerInput("LB"); + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && !previousGamePad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder)) + { + buttonEvents.raiseControllerInput("RB"); + } + if (currentGamePad.LeftTrigger > 200 && previousGamePad.LeftTrigger <= 200) + { + buttonEvents.raiseControllerInput("LT"); + } + if (currentGamePad.RightTrigger > 200 && previousGamePad.RightTrigger <= 200) + { + buttonEvents.raiseControllerInput("RT"); + } + + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) || currentGamePad.LeftThumbY > 12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) && previousGamePad.LeftThumbY <= 12000) + { + buttonEvents.raiseControllerInput("Up"); + } + else + { + continuousInputNew = "Up"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || currentGamePad.LeftThumbY < -12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) && previousGamePad.LeftThumbY >= -12000) + { + buttonEvents.raiseControllerInput("Down"); + } + else + { + continuousInputNew = "Down"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) || currentGamePad.LeftThumbX > 12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) && previousGamePad.LeftThumbX <= 12000) + { + buttonEvents.raiseControllerInput("Right"); + } + else + { + continuousInputNew = "Right"; + } + } + if (currentGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) || currentGamePad.LeftThumbX < -12000) + { + if (!previousGamePad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) && previousGamePad.LeftThumbX >= -12000) + { + buttonEvents.raiseControllerInput("Left"); + } + else + { + continuousInputNew = "Left"; + } + } + + + if (continuousInputNew != continuousInputCurrent) + { + continuousInputCurrent = continuousInputNew; + continuousInputCounter = 1; + } + else + { + if (continuousInputCurrent != "") + { + continuousInputCounter++; + if (continuousInputCounter > 9) + { + + buttonEvents.raiseControllerInput(continuousInputCurrent); + } + } + + } + } + } + Controller: + previousGamePad = currentGamePad; + Thread.Sleep(activeTimerTickInterval); + } + + + } + catch (Exception ex) + { + + } + } + } + + private static void checkSwapController() + { + + //error number CM03 + try + { + List controllerList = new List(); + + controllerList.Add(new Controller(UserIndex.One)); + controllerList.Add(new Controller(UserIndex.Two)); + controllerList.Add(new Controller(UserIndex.Three)); + controllerList.Add(new Controller(UserIndex.Four)); + + foreach (Controller swapController in controllerList) + { + + if (swapController != null) + { + if (swapController.IsConnected) + { + Gamepad swapGamepad = swapController.GetState().Gamepad; + if (swapGamepad.Buttons.HasFlag(GamepadButtonFlags.Start) && swapGamepad.Buttons.HasFlag(GamepadButtonFlags.Back)) + { + + controller = swapController; + } + } + } + + } + } + catch (Exception ex) + { + + } + } + + + private static void getController() + { + //error number CM04 + try + { + int controllerNum = 1; + //get controller used, loop controller number if less than 5, so if controller is connected make num = 5 to get out of while loop + while (controllerNum < 6) + { + switch (controllerNum) + { + default: + break; + case 1: + controller = new Controller(UserIndex.One); + break; + case 2: + controller = new Controller(UserIndex.Two); + break; + case 3: + controller = new Controller(UserIndex.Three); + break; + case 4: + controller = new Controller(UserIndex.Four); + break; + case 5: + timerController.Interval = TimeSpan.FromMilliseconds(1500); + controllerNum = 6; + buttonEvents.raiseControllerStatusChanged(); + break; + } + if (controller == null) + { + controllerNum++; + } + else + { + if (controller.IsConnected) + { + controllerNum = 6; + timerController.Interval = TimeSpan.FromMilliseconds(activeTimerTickInterval); + buttonEvents.raiseControllerStatusChanged(); + } + else + { + controllerNum++; + } + } + } + } + catch (Exception ex) + { + + } + } + } + + public class buttonEvents + { + + public event EventHandler controllerStatusChangedEvent; + public void raiseControllerStatusChanged() + { + controllerStatusChangedEvent?.Invoke(this, EventArgs.Empty); + } + + + public event EventHandler controllerInput; + + public void raiseControllerInput(string action) + { + + System.Windows.Application.Current.Dispatcher.BeginInvoke(() => + { + controllerInput?.Invoke(this, new controllerInputEventArgs(action)); + }); + + } + + public event EventHandler openAppEvent; + public void RaiseOpenAppEvent() + { + openAppEvent?.Invoke(this, EventArgs.Empty); + } + } + public class controllerInputEventArgs : EventArgs + { + public string Action { get; set; } + public controllerInputEventArgs(string action) + { + this.Action = action; + } + } + public class controllerPageInputEventArgs : EventArgs + { + public string Action { get; set; } + public string WindowPage { get; set; } + public controllerPageInputEventArgs(string action, string windowpage) + { + this.Action = action; + this.WindowPage = windowpage; + } + } + public class controllerUserControlInputEventArgs : EventArgs + { + public string Action { get; set; } + public string WindowPage { get; set; } + public string UserControl { get; set; } + public controllerUserControlInputEventArgs(string action, string windowpage, string usercontrol) + { + this.Action = action; + this.WindowPage = windowpage; + this.UserControl = usercontrol; + } + } +} \ No newline at end of file diff --git a/Universal x86 Tuning Utility Handheld/Views/Pages/AdvancedPage.xaml.cs b/Universal x86 Tuning Utility Handheld/Views/Pages/AdvancedPage.xaml.cs index 6fc4179..872d167 100644 --- a/Universal x86 Tuning Utility Handheld/Views/Pages/AdvancedPage.xaml.cs +++ b/Universal x86 Tuning Utility Handheld/Views/Pages/AdvancedPage.xaml.cs @@ -29,6 +29,9 @@ using Universal_x86_Tuning_Utility_Handheld.Services; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; using Universal_x86_Tuning_Utility.Scripts; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; +using System.Diagnostics; +using Universal_x86_Tuning_Utility_Handheld.Scripts.Fan_Control; namespace Universal_x86_Tuning_Utility_Handheld.Views.Pages { @@ -47,6 +50,9 @@ public ViewModels.AdvancedViewModel ViewModel } private DispatcherTimer checkInput = new DispatcherTimer(); private DispatcherTimer updateGUI = new DispatcherTimer(); + + private static CardControl[] cards = new CardControl[1]; + public AdvancedPage(ViewModels.AdvancedViewModel viewModel) { ViewModel = viewModel; @@ -57,7 +63,7 @@ public AdvancedPage(ViewModels.AdvancedViewModel viewModel) normalBorderBrush = ccSection12.BorderBrush; - checkInput.Interval = TimeSpan.FromSeconds(0.12); + checkInput.Interval = TimeSpan.FromSeconds(0.5); checkInput.Tick += checkInput_Tick; checkInput.Start(); @@ -69,6 +75,27 @@ public AdvancedPage(ViewModels.AdvancedViewModel viewModel) ViewModel.BatteryIcon = Global.battery; Garbage.Garbage_Collect(); + + Controller_Event.buttonEvents.controllerInput += handleControllerInputs; + + if (Family.TYPE == Family.ProcessorType.Amd_Apu) + { + CardControl[] cardsTemp = { ccSection1, ccSection2, ccSection3, ccSection4, ccSection41, ccSection42, ccSection43, ccSection431, ccSection44, ccSection45, ccSection46, ccSection5, ccSection6, ccSection7, ccSection8, ccSection81, ccSection82, ccSection9, ccSection10, ccSection101, ccSection102, ccSection103, ccSection104, ccSection105, ccSection11, ccSection12, ccSection13, ccSection14 }; + cards = cardsTemp; + } + if (Family.TYPE == Family.ProcessorType.Intel) + { + ccSection1.Visibility = Visibility.Collapsed; + ccSection2.Visibility = Visibility.Collapsed; + ccSection5.Visibility = Visibility.Collapsed; + ccSection9.Visibility = Visibility.Collapsed; + ccSection13.Visibility = Visibility.Collapsed; + CardControl[] cardsTemp = { ccSection3, ccSection4, ccSection41, ccSection42, ccSection43, ccSection431, ccSection44, ccSection45, ccSection46, ccSection7, ccSection8, ccSection81, ccSection82, ccSection101, ccSection102, ccSection103, ccSection104, ccSection105, ccSection11, ccSection12 }; + cards = cardsTemp; + } + + if (ViewModel.IsAdaptiveTDP == true) { if (Family.FAM == Family.RyzenFamily.Renoir || Family.FAM == Family.RyzenFamily.Mendocino || Family.FAM == Family.RyzenFamily.Rembrandt || Family.FAM == Family.RyzenFamily.PhoenixPoint) ViewModel.ShowAdaptiveiGPU = true; } + else ViewModel.ShowAdaptiveiGPU = false; } int selected = 0, lastSelected = -1; @@ -77,8 +104,30 @@ async void checkInput_Tick(object sender, EventArgs e) { if (Global._mainWindowNav.SelectedPageIndex == 1 && Global._appVis == Visibility.Visible && Global.shortCut == false) { - UpdateGUI(UserIndex.One); - UpdateGUI(UserIndex.Two); + if (!Controller_Event.controller.IsConnected) + { + foreach (var card in cards) + { + card.BorderBrush = normalBorderBrush; + card.BorderThickness = normalThickness; + } + lastSelected = -1; + } + else + { + if (cards[cards.Length - 1].Visibility == Visibility.Visible) + { + cards[cards.Length - 2].Margin = new Thickness(0, 9, 0, 0); + cards[cards.Length - 1].Margin = new Thickness(0, 9, 0, 18); + } + else + { + cards[cards.Length - 2].Margin = new Thickness(0, 9, 0, 18); + cards[cards.Length - 1].Margin = new Thickness(0, 9, 0, 0); + } + } + + if (ViewModel.IsAdaptiveTDP == false && ViewModel.IsAdaptiveiGPU == true) ViewModel.IsAdaptiveiGPU = false; var foregroundBrush = (Brush)System.Windows.Application.Current.FindResource("TextFillColorPrimaryBrush"); selectedBorderBrush = foregroundBrush; @@ -91,59 +140,16 @@ async void updateGUI_Tick(object sender, EventArgs e) ViewModel.BatteryIcon = Global.battery; } - private static Controller controller; - private void UpdateGUI(UserIndex controllerNo) + private void handleControllerInputs(object sender, EventArgs e) { try { - CardControl[] cards = new CardControl[1]; - - if (Family.TYPE == Family.ProcessorType.Amd_Apu) - { - CardControl[] cardsTemp = { ccSection1, ccSection2, ccSection3, ccSection4, ccSection41, ccSection42, ccSection43, ccSection431, ccSection44, ccSection45, ccSection46, ccSection5, ccSection6, ccSection7, ccSection8, ccSection81, ccSection82, ccSection9, ccSection10, ccSection101, ccSection102, ccSection103, ccSection104, ccSection105, ccSection11, ccSection12, ccSection13, ccSection14 }; - cards = cardsTemp; - } - if (Family.TYPE == Family.ProcessorType.Intel) + if (Global._mainWindowNav.SelectedPageIndex == 1 && Global._appVis == Visibility.Visible && Global.shortCut == false) { - ccSection1.Visibility = Visibility.Collapsed; - ccSection2.Visibility = Visibility.Collapsed; - ccSection5.Visibility = Visibility.Collapsed; - ccSection9.Visibility = Visibility.Collapsed; - ccSection13.Visibility = Visibility.Collapsed; - CardControl[] cardsTemp = { ccSection3, ccSection4, ccSection41, ccSection42, ccSection43, ccSection431, ccSection44, ccSection45, ccSection46, ccSection7, ccSection8, ccSection81, ccSection82, ccSection101, ccSection102, ccSection103, ccSection104, ccSection105, ccSection11, ccSection12 }; - cards = cardsTemp; - } - - if (ViewModel.IsAdaptiveTDP == false && ViewModel.IsAdaptiveiGPU == true) ViewModel.IsAdaptiveiGPU = false; - - if (ViewModel.IsAdaptiveTDP == true) { if (Family.FAM == Family.RyzenFamily.Renoir || Family.FAM == Family.RyzenFamily.Mendocino || Family.FAM == Family.RyzenFamily.Rembrandt || Family.FAM == Family.RyzenFamily.PhoenixPoint) ViewModel.ShowAdaptiveiGPU = true; } - else ViewModel.ShowAdaptiveiGPU = false; - - controller = new Controller(controllerNo); - bool connected = controller.IsConnected; - - if (cards[cards.Length - 1].Visibility == Visibility.Visible) - { - cards[cards.Length - 2].Margin = new Thickness(0, 9, 0, 0); - cards[cards.Length - 1].Margin = new Thickness(0, 9, 0, 18); - } - else - { - cards[cards.Length - 2].Margin = new Thickness(0, 9, 0, 18); - cards[cards.Length - 1].Margin = new Thickness(0, 9, 0, 0); - } - - if (connected) - { - //get controller state - var state = controller.GetState(); - SharpDX.XInput.Gamepad gamepad = controller.GetState().Gamepad; - float tx = gamepad.LeftThumbX; - float ty = gamepad.LeftThumbY; - ScrollViewer svMain = Global.FindVisualChild(this); - - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) || ty > 18000) + Universal_x86_Tuning_Utility_Handheld.Scripts.Misc.controllerInputEventArgs args = (Universal_x86_Tuning_Utility_Handheld.Scripts.Misc.controllerInputEventArgs)e; + if (ViewModel.IsAdaptiveTDP == false && ViewModel.IsAdaptiveiGPU == true) ViewModel.IsAdaptiveiGPU = false; + if (args.Action == "Up") { if (selected > 0) selected--; else selected = 0; @@ -169,7 +175,7 @@ private void UpdateGUI(UserIndex controllerNo) if (selected <= 1) svMain.ScrollToTop(); } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || ty < -18000) + if (args.Action == "Down") { if (selected < cards.Length - 1) selected++; else selected = cards.Length - 1; @@ -177,7 +183,7 @@ private void UpdateGUI(UserIndex controllerNo) if (cards[selected].Visibility == Visibility.Collapsed) { do selected++; - while (cards[selected].Visibility == Visibility.Collapsed); + while (cards[selected].Visibility == Visibility.Collapsed && selected > cards.Length - 2); if (selected > cards.Length - 1) selected = lastSelected; } @@ -196,7 +202,7 @@ private void UpdateGUI(UserIndex controllerNo) if (selected >= cards.Length - 2) svMain.ScrollToBottom(); } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) || tx < -26000) + if (args.Action == "Left") { Slider slider = Global.FindVisualChild(cards[selected]); @@ -219,18 +225,7 @@ private void UpdateGUI(UserIndex controllerNo) } } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A)) - { - ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); - - if (toggleSwitch != null) - { - if (toggleSwitch.IsChecked == true) toggleSwitch.IsChecked = false; - else toggleSwitch.IsChecked = true; - } - } - - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) || tx > 26000) + if (args.Action == "Right") { Slider slider = Global.FindVisualChild(cards[selected]); @@ -253,6 +248,17 @@ private void UpdateGUI(UserIndex controllerNo) } } + if (args.Action == "A") + { + ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); + + if (toggleSwitch != null) + { + if (toggleSwitch.IsChecked == true) toggleSwitch.IsChecked = false; + else toggleSwitch.IsChecked = true; + } + } + if (selected != lastSelected && cards[selected].Visibility != Visibility.Collapsed && cards[selected].BorderBrush != selectedBorderBrush) { if (selected < 0) selected = 0; @@ -292,18 +298,9 @@ private void UpdateGUI(UserIndex controllerNo) } } } - else if (controllerNo == UserIndex.One && !connected) - { - foreach (var card in cards) - { - card.BorderBrush = normalBorderBrush; - card.BorderThickness = normalThickness; - } + } catch { - lastSelected = -1; - } } - catch { } } private void ToggleSwitch_Checked(object sender, RoutedEventArgs e) diff --git a/Universal x86 Tuning Utility Handheld/Views/Pages/DashboardPage.xaml.cs b/Universal x86 Tuning Utility Handheld/Views/Pages/DashboardPage.xaml.cs index 212a1bc..75704a7 100644 --- a/Universal x86 Tuning Utility Handheld/Views/Pages/DashboardPage.xaml.cs +++ b/Universal x86 Tuning Utility Handheld/Views/Pages/DashboardPage.xaml.cs @@ -29,6 +29,10 @@ using Universal_x86_Tuning_Utility_Handheld.Services; using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; using Universal_x86_Tuning_Utility_Handheld.Scripts.Fan_Control; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using static System.Windows.Forms.AxHost; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; +using System.Collections.Generic; namespace Universal_x86_Tuning_Utility_Handheld.Views.Pages { @@ -48,7 +52,7 @@ public ViewModels.DashboardViewModel ViewModel private DispatcherTimer checkInput = new DispatcherTimer(); private readonly XgMobileConnectionService xgMobileConnectionService; - + bool isSetUp = false; public DashboardPage(ViewModels.DashboardViewModel viewModel) { ViewModel = viewModel; @@ -64,11 +68,15 @@ public DashboardPage(ViewModels.DashboardViewModel viewModel) UpdateASUS(); SetRecordingDeviceState(ViewModel.Recording); + isSetUp = true; + normalBorderBrush = ccSection8.BorderBrush; - checkInput.Interval = TimeSpan.FromSeconds(0.12); + checkInput.Interval = TimeSpan.FromSeconds(0.5); checkInput.Tick += checkInput_Tick; checkInput.Start(); + Controller_Event.buttonEvents.controllerInput += handleControllerInputs; + if (Settings.Default.isASUS) { this.xgMobileConnectionService = App.xgMobileConnectionService; @@ -95,217 +103,206 @@ private async void UpdateXgMobileStatus(bool detected, bool connected) else ViewModel.IsXgMobile = true; eGPU = detected && connected ? 1 : 0; - if (eGPU == 0 && ViewModel.XgMobileTag != "Activate ROG XG Mobile") ViewModel.XgMobileTag = "Activate ROG XG Mobile"; - if (eGPU == 1 && ViewModel.XgMobileTag != "Deactivate ROG XG Mobile") ViewModel.XgMobileTag = "Deactivate ROG XG Mobile"; + if (eGPU == 0 && ViewModel.XgMobileTag != "Activate ROG XG Mobile") ViewModel.XgMobileTag = "Activate ROG XG Mobile"; + if (eGPU == 1 && ViewModel.XgMobileTag != "Deactivate ROG XG Mobile") ViewModel.XgMobileTag = "Deactivate ROG XG Mobile"; } catch { } } int selected = 0, lastSelected = 0; bool wasMini = true; + async void checkInput_Tick(object sender, EventArgs e) { if (Global._mainWindowNav.SelectedPageIndex == 0 && Global._appVis == Visibility.Visible && Global.shortCut == false) - { - UpdateGUI(UserIndex.One); - UpdateGUI(UserIndex.Two); - - var foregroundBrush = (Brush)Application.Current.FindResource("TextFillColorPrimaryBrush"); - selectedBorderBrush = foregroundBrush; - } - else wasMini = true; - } - - private static Controller controller; - private void UpdateGUI(UserIndex controllerNo) - { - try { if (wasMini) { + isSetUp = false; getBrightness(); getVol(); + isSetUp = true; getWifi(); getBluetooth(); wasMini = false; } - CardControl[] cards = { ccSection1, ccSection2, ccSection3, ccSection4, ccSection5, ccSection51, ccSection6, ccSection7, ccSection8, ccSection9, ccSection10, ccSection11, ccSection12, ccMini, ccClose }; - controller = new Controller(controllerNo); - bool connected = controller.IsConnected; - - if (connected) + if (!Controller_Event.controller.IsConnected) { - //get controller state - var state = controller.GetState(); - SharpDX.XInput.Gamepad gamepad = controller.GetState().Gamepad; - float tx = gamepad.LeftThumbX; - float ty = gamepad.LeftThumbY; - - ScrollViewer svMain = Global.FindVisualChild(this); - - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadUp) || ty > 18000) + CardControl[] cards = { ccSection1, ccSection2, ccSection3, ccSection4, ccSection5, ccSection51, ccSection6, ccSection7, ccSection8, ccSection9, ccSection10, ccSection11, ccSection12, ccMini, ccClose }; + foreach (var card in cards) { - if (selected > 0) selected--; - else selected = 0; + card.BorderBrush = normalBorderBrush; + card.BorderThickness = normalThickness; + } + lastSelected = -1; + } - if (cards[selected].Visibility == Visibility.Collapsed) - { - do selected--; - while (cards[selected].Visibility == Visibility.Collapsed); + var foregroundBrush = (Brush)Application.Current.FindResource("TextFillColorPrimaryBrush"); + selectedBorderBrush = foregroundBrush; + } + else wasMini = true; + } - if (selected < 0) selected = lastSelected; - } + private void handleControllerInputs(object sender, EventArgs e) + { + if (Global._mainWindowNav.SelectedPageIndex == 0 && Global._appVis == Visibility.Visible && Global.shortCut == false) + { + CardControl[] cards = { ccSection1, ccSection2, ccSection3, ccSection4, ccSection5, ccSection51, ccSection6, ccSection7, ccSection8, ccSection9, ccSection10, ccSection11, ccSection12, ccMini, ccClose }; + ScrollViewer svMain = Global.FindVisualChild(this); + Universal_x86_Tuning_Utility_Handheld.Scripts.Misc.controllerInputEventArgs args = (Universal_x86_Tuning_Utility_Handheld.Scripts.Misc.controllerInputEventArgs)e; - GeneralTransform transform = cards[selected].TransformToVisual(svMain); - Point topPosition = transform.Transform(new Point(0, 0)); - Point bottomPosition = transform.Transform(new Point(0, cards[selected].ActualHeight)); + if (args.Action == "Up") + { + if (selected > 0) selected--; + else selected = 0; - if (topPosition.Y < 0 || bottomPosition.Y > svMain.ActualHeight) - { - double targetOffset = svMain.VerticalOffset + topPosition.Y - 12; - svMain.ScrollToVerticalOffset(targetOffset); - } + if (cards[selected].Visibility == Visibility.Collapsed) + { + do selected--; + while (cards[selected].Visibility == Visibility.Collapsed); - if (selected <= 1) svMain.ScrollToTop(); + if (selected < 0) selected = lastSelected; } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || ty < -18000) - { - if (selected < cards.Length - 1) selected++; - else selected = cards.Length - 1; + GeneralTransform transform = cards[selected].TransformToVisual(svMain); + Point topPosition = transform.Transform(new Point(0, 0)); + Point bottomPosition = transform.Transform(new Point(0, cards[selected].ActualHeight)); - if (cards[selected].Visibility == Visibility.Collapsed) - { - do selected++; - while (cards[selected].Visibility == Visibility.Collapsed); + if (topPosition.Y < 0 || bottomPosition.Y > svMain.ActualHeight) + { + double targetOffset = svMain.VerticalOffset + topPosition.Y - 12; + svMain.ScrollToVerticalOffset(targetOffset); + } - if (selected > cards.Length - 1) selected = lastSelected; - } + if (selected <= 1) svMain.ScrollToTop(); + } - GeneralTransform transform = cards[selected].TransformToVisual(svMain); - Point topPosition = transform.Transform(new Point(0, 0)); - Point bottomPosition = transform.Transform(new Point(0, cards[selected].ActualHeight)); + if (args.Action == "Down") + { + if (selected < cards.Length - 1) selected++; + else selected = cards.Length - 1; - if (topPosition.Y < 0 || bottomPosition.Y > svMain.ActualHeight) - { - double targetOffset = svMain.VerticalOffset + bottomPosition.Y - svMain.ActualHeight + 12; - svMain.ScrollToVerticalOffset(targetOffset); - } + if (cards[selected].Visibility == Visibility.Collapsed) + { + do selected++; + while (cards[selected].Visibility == Visibility.Collapsed); - if (selected >= cards.Length - 2) svMain.ScrollToBottom(); + if (selected > cards.Length - 1) selected = lastSelected; } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) || tx < -26000) + GeneralTransform transform = cards[selected].TransformToVisual(svMain); + Point topPosition = transform.Transform(new Point(0, 0)); + Point bottomPosition = transform.Transform(new Point(0, cards[selected].ActualHeight)); + + if (topPosition.Y < 0 || bottomPosition.Y > svMain.ActualHeight) { - Slider slider = Global.FindVisualChild(cards[selected]); + double targetOffset = svMain.VerticalOffset + bottomPosition.Y - svMain.ActualHeight + 12; + svMain.ScrollToVerticalOffset(targetOffset); + } - if (slider != null) - { - int currentValue = (int)slider.Value; - currentValue--; - if (currentValue < slider.Minimum) currentValue = (int)slider.Minimum; - if (currentValue > slider.Maximum) currentValue = (int)slider.Maximum; - slider.Value = currentValue; - } + if (selected >= cards.Length - 2) svMain.ScrollToBottom(); + } - ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); + if (args.Action == "Left") + { + Slider slider = Global.FindVisualChild(cards[selected]); - if (toggleSwitch != null) - { - toggleSwitch.IsChecked = false; - } + if (slider != null) + { + int currentValue = (int)slider.Value; + currentValue--; + if (currentValue < slider.Minimum) currentValue = (int)slider.Minimum; + if (currentValue > slider.Maximum) currentValue = (int)slider.Maximum; + slider.Value = currentValue; } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A)) + ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); + + if (toggleSwitch != null) { - ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); + toggleSwitch.IsChecked = false; + } + } - if (toggleSwitch != null) - { - if(toggleSwitch.IsChecked == true) toggleSwitch.IsChecked = false; - else toggleSwitch.IsChecked = true; - } + if (args.Action == "Right") + { + Slider slider = Global.FindVisualChild(cards[selected]); - if (cards[selected] == ccSection11) new XG_Mobile_Prompt(false).Show(); - if (cards[selected] == ccMini) MainWindow.minimise = 1; - if (cards[selected] == ccClose) - { - if (Fan_Control.isSupported) Fan_Control.disableFanControl(); - Process.GetCurrentProcess().Kill(); - } + if (slider != null) + { + int currentValue = (int)slider.Value; + currentValue++; + if (currentValue < slider.Minimum) currentValue = (int)slider.Minimum; + if (currentValue > slider.Maximum) currentValue = (int)slider.Maximum; + slider.Value = currentValue; } - if (state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadRight) || tx > 26000) - { - Slider slider = Global.FindVisualChild(cards[selected]); + ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); - if (slider != null) - { - int currentValue = (int)slider.Value; - currentValue++; - if (currentValue < slider.Minimum) currentValue = (int)slider.Minimum; - if (currentValue > slider.Maximum) currentValue = (int)slider.Maximum; - slider.Value = currentValue; - } + if (toggleSwitch != null) + { + toggleSwitch.IsChecked = true; + } + } - ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); + if (args.Action == "A") + { + ToggleSwitch toggleSwitch = Global.FindVisualChild(cards[selected]); - if (toggleSwitch != null) - { - toggleSwitch.IsChecked = true; - } + if (toggleSwitch != null) + { + if (toggleSwitch.IsChecked == true) toggleSwitch.IsChecked = false; + else toggleSwitch.IsChecked = true; } - if (selected != lastSelected && cards[selected].Visibility != Visibility.Collapsed && cards[selected].BorderBrush != selectedBorderBrush) + if (cards[selected] == ccSection11) new XG_Mobile_Prompt(false).Show(); + if (cards[selected] == ccMini) MainWindow.minimise = 1; + if (cards[selected] == ccClose) { - if (selected < 0) selected = 0; - if (selected > cards.Length - 1) selected = cards.Length - 1; - - foreach (var card in cards) - { - card.BorderBrush = normalBorderBrush; - card.BorderThickness = normalThickness; - } + if (Fan_Control.isSupported) Fan_Control.disableFanControl(); + Process.GetCurrentProcess().Kill(); + } + } + if (selected != lastSelected && cards[selected].Visibility != Visibility.Collapsed && cards[selected].BorderBrush != selectedBorderBrush) + { + if (selected < 0) selected = 0; + if (selected > cards.Length - 1) selected = cards.Length - 1; - cards[selected].BorderBrush = selectedBorderBrush; - cards[selected].BorderThickness = selectedThickness; - lastSelected = selected; + foreach (var card in cards) + { + card.BorderBrush = normalBorderBrush; + card.BorderThickness = normalThickness; } - else if (selected == lastSelected && cards[selected].Visibility == Visibility.Collapsed) + + cards[selected].BorderBrush = selectedBorderBrush; + cards[selected].BorderThickness = selectedThickness; + lastSelected = selected; + } + else if (selected == lastSelected && cards[selected].Visibility == Visibility.Collapsed) + { + if (selected > cards.Length / 2) { - if(selected > cards.Length / 2) + if (cards[selected].Visibility == Visibility.Collapsed) { - if (cards[selected].Visibility == Visibility.Collapsed) - { - do selected--; - while (cards[selected].Visibility == Visibility.Collapsed); + do selected--; + while (cards[selected].Visibility == Visibility.Collapsed); - if (selected < 0) selected = lastSelected; - } + if (selected < 0) selected = lastSelected; } - else + } + else + { + if (cards[selected].Visibility == Visibility.Collapsed) { - if (cards[selected].Visibility == Visibility.Collapsed) - { - do selected++; - while (cards[selected].Visibility == Visibility.Collapsed); + do selected++; + while (cards[selected].Visibility == Visibility.Collapsed); - if (selected > cards.Length - 1) selected = lastSelected; - } + if (selected > cards.Length - 1) selected = lastSelected; } } } - else if (controllerNo == UserIndex.One && !connected) - { - foreach (var card in cards) - { - card.BorderBrush = normalBorderBrush; - card.BorderThickness = normalThickness; - } - lastSelected = -1; - } - } catch { } + } } private void ToggleSwitch_Checked(object sender, RoutedEventArgs e) @@ -316,7 +313,7 @@ private void ToggleSwitch_Checked(object sender, RoutedEventArgs e) if (ViewModel.IsXgMobile) { - if(ViewModel.IsXgMobileLED) xgMobileConnectionService.EnableXgMobileLight(); + if (ViewModel.IsXgMobileLED) xgMobileConnectionService.EnableXgMobileLight(); else xgMobileConnectionService.DisableXgMobileLight(); } @@ -419,7 +416,7 @@ private async void UpdateASUS() if (Settings.Default.isASUS) App.wmi.DeviceSet(ASUSWmi.PerformanceMode, ASUSWmi.PerformanceTurbo); } - if(ViewModel.ChargeLimit >= 50 && Settings.Default.isASUS) App.wmi.DeviceSet(ASUSWmi.BatteryLimit, ViewModel.ChargeLimit); + if (ViewModel.ChargeLimit >= 50 && Settings.Default.isASUS) App.wmi.DeviceSet(ASUSWmi.BatteryLimit, ViewModel.ChargeLimit); }); Settings.Default.acMode = ViewModel.AcMode; @@ -441,7 +438,7 @@ async void SetRecordingDeviceState(bool mute) device.AudioEndpointVolume.Mute = mute; } - if(mute == true) ViewModel.MicIcon = SymbolRegular.MicOff24; + if (mute == true) ViewModel.MicIcon = SymbolRegular.MicOff24; else ViewModel.MicIcon = SymbolRegular.Mic24; }); } @@ -450,6 +447,7 @@ async void SetRecordingDeviceState(bool mute) public async void updateBrightness(int newBirghtness) { + if (isSetUp) try { await Task.Run(() => @@ -474,7 +472,8 @@ public async void updateBrightness(int newBirghtness) public async void updateVolume(int newVolume) { - try + if (isSetUp) + try { await Task.Run(() => { diff --git a/Universal x86 Tuning Utility Handheld/Views/Windows/MainWindow.xaml.cs b/Universal x86 Tuning Utility Handheld/Views/Windows/MainWindow.xaml.cs index e39fd83..f07b78a 100644 --- a/Universal x86 Tuning Utility Handheld/Views/Windows/MainWindow.xaml.cs +++ b/Universal x86 Tuning Utility Handheld/Views/Windows/MainWindow.xaml.cs @@ -110,6 +110,8 @@ public MainWindow(ViewModels.MainWindowViewModel viewModel, ViewModels.AdvancedV ApplyController(); _navigationService = navigationService; + Controller_Event.start_Controller_Management(); + if (Settings.Default.isASUS == true) App.wmi.SubscribeToEvents(WatcherEventArrived); UpdatePreset("Default"); @@ -166,8 +168,8 @@ private async void MainWindow_Loaded(object sender, RoutedEventArgs e) Fan_Control.UpdateAddresses(); - ControllerControl.isStarted = true; - ControllerControl.SetUp(); + //ControllerControl.isStarted = true; + //ControllerControl.SetUp(); } int i = 0; @@ -182,7 +184,7 @@ private void Timer_Tick(object sender, EventArgs e) } else { - if (Visibility == Visibility.Visible && update >= 2) + if (Visibility == Visibility.Visible && update >= 4) { UpdateInfo(); GetWifi(); @@ -592,6 +594,9 @@ private void ApplyController() // controller.SetVibration(vibration); // } //} + + + } private void UiWindow_StateChanged(object sender, EventArgs e)