Skip to content

Commit

Permalink
xinput open QAM OSK
Browse files Browse the repository at this point in the history
  • Loading branch information
project-sbc committed Jul 20, 2022
1 parent c496d3a commit fe81e1e
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 45 deletions.
95 changes: 78 additions & 17 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,20 @@ public static class GlobalVariables
//TDP change class
public static PowerControlPanel.Classes.ChangeTDP.ChangeTDP tdp = new PowerControlPanel.Classes.ChangeTDP.ChangeTDP();

//controller handler class
public static PowerControlPanel.Classes.ControllerHandler ch = new PowerControlPanel.Classes.ControllerHandler();

//Routine update class
public static RoutineUpdate routineUpdate = new RoutineUpdate();


}


public static class TimerEvents
{




}
public partial class MainWindow : MetroWindow
{
private NavigationServiceEx navigationServiceEx;

private DispatcherTimer timer = new DispatcherTimer();

private Controller controller;
private Gamepad gamepad;

public static Window overlay;
public static Window osk;
Expand All @@ -77,12 +72,55 @@ public MainWindow()
//Run code to set up hamburger menu
initializeNavigationFrame();

initializeTimer();


}

private void initializeTimer()
{
timer.Interval = new TimeSpan(0, 0, 1);
timer.Tick += timerTick;
timer.Start();

}
private void timerTick(object sender, EventArgs e)
{
controller = new Controller(UserIndex.One);
if (controller != null)
{
if (controller.IsConnected)
{
gamepad = controller.GetState().Gamepad;

if (gamepad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
{
if (gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadRight))
{
handleOpenCloseQAM();

}
if (gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown))
{
handleOpenCloseOSK();

}
}

}
}
}
private void OSKEvent(object sender, EventArgs e)
{
handleOpenCloseOSK();

}

private void QAMEvent(object sender, EventArgs e)
{

handleOpenCloseQAM();
}

//Navigation routines
#region navigation
Expand All @@ -100,17 +138,14 @@ private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItem

if (e.InvokedItem is MenuItem menuItem)
{
if (menuItem.Label == "Overlay")
if (menuItem.Label == "Quick Access Menu")
{
overlay = new QuickAccessMenu();
overlay.Show();

handleOpenCloseQAM();
}
if (menuItem.Label == "On Screen Keyboard")
{
osk = new OSK();

osk.Show();
handleOpenCloseOSK();

}
if (menuItem.IsNavigation)
Expand All @@ -121,6 +156,32 @@ private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItem
}
}

private void handleOpenCloseQAM()
{
if (overlay == null)
{
overlay = new QuickAccessMenu();
overlay.Show();
}
else
{
overlay.Close();
}

}
private void handleOpenCloseOSK()
{
if (osk == null)
{
osk = new OSK();
osk.Show();
}
else
{
osk.Close();
}

}
private void NavigationServiceEx_OnNavigated(object sender, NavigationEventArgs e)
{
// select the menu item
Expand Down
2 changes: 1 addition & 1 deletion OSK.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public OSK()

void setUpControllerHandler()
{
ch.createGamePadStateCollectorLoop();
ch.createGamePadStateCollectorLoop(15,true);

ch.events.pressAEvent += HandlePressAEvent;

Expand Down
2 changes: 2 additions & 0 deletions PowerControlPanel/Classes/ChangeTDP/ChangeTDP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ChangeTDP
public void readTDP()
{



try
{
//add small delay to prevent write and read operations from interfering
Expand Down
89 changes: 63 additions & 26 deletions PowerControlPanel/Classes/ControllerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ public class ControllerHandler
public Controller controller;
private Gamepad gamepadCurrent;
private Gamepad gamepadOld;
private int threadSleep;
private bool readEvents = true;

public buttonEvents events = new buttonEvents();

public void createGamePadStateCollectorLoop()
public void createGamePadStateCollectorLoop(int threadSleepValue, bool readEventArg)
{
controllerThread = new Thread(new ThreadStart(gamePadStateCollector));
controllerThread.IsBackground = true;
threadSleep = threadSleepValue;
readEvents = readEventArg;
controllerThread.Start();
}

public void gamePadStateCollector()
{


while (GlobalVariables.useRoutineThread)
{
Expand All @@ -47,36 +50,61 @@ public void gamePadStateCollector()
if (controller.IsConnected)
{
gamepadCurrent = controller.GetState().Gamepad;
Task.Delay(15);
Thread.Sleep(15);
while (GlobalVariables.useRoutineThread && controller.IsConnected)
{
gamepadOld = gamepadCurrent;
gamepadCurrent = controller.GetState().Gamepad;

if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.A) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.A))
if (!readEvents)
{
events.RaiseEventA();
gamepadCurrent = controller.GetState().Gamepad;
if (gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
{
if (gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.DPadRight))
{
events.RaiseEventQAM();
}
if (gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.DPadDown))
{
events.RaiseEventOSK();
}
}
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.B) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.B))
else
{
events.RaiseEventB();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.X) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.X))
{
events.RaiseEventX();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.Y) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.Y))
{
events.RaiseEventY();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
{
events.RaiseEventLB();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.RightShoulder))
{
events.RaiseEventRB();
gamepadOld = gamepadCurrent;
gamepadCurrent = controller.GetState().Gamepad;

if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.A) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.A))
{
events.RaiseEventA();

}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.B) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.B))
{
events.RaiseEventB();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.X) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.X))
{
events.RaiseEventX();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.Y) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.Y))
{
events.RaiseEventY();
}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
{
events.RaiseEventLB();

}
if (!gamepadOld.Buttons.HasFlag(GamepadButtonFlags.RightShoulder) && gamepadCurrent.Buttons.HasFlag(GamepadButtonFlags.RightShoulder))
{
events.RaiseEventRB();

}

}

Thread.Sleep(threadSleep);
}


Expand Down Expand Up @@ -112,7 +140,16 @@ public void gamePadStateCollector()

public class buttonEvents
{

public void RaiseEventOSK()
{
pressOSKEvent?.Invoke(this, EventArgs.Empty);
}
public event EventHandler pressOSKEvent;
public void RaiseEventQAM()
{
pressQAMEvent?.Invoke(this, EventArgs.Empty);
}
public event EventHandler pressQAMEvent;
public void RaiseEventA()
{
pressAEvent?.Invoke(this, EventArgs.Empty);
Expand Down
2 changes: 1 addition & 1 deletion PowerControlPanel/Classes/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ShellViewModel()
this.Menu.Add(new MenuItem()
{
Icon = new PackIconFontAwesome() { Kind = PackIconFontAwesomeKind.WindowRestoreSolid },
Label = "Overlay",
Label = "Quick Access Menu",

});
this.Menu.Add(new MenuItem()
Expand Down

0 comments on commit fe81e1e

Please sign in to comment.