refactor: preprocessors for wiimote and joycon compilation
This commit is contained in:
parent
65d562ee74
commit
72750c3388
11 changed files with 63 additions and 32 deletions
51
SlidePresenter/GamepadReader/WiimoteRead.cs
Normal file
51
SlidePresenter/GamepadReader/WiimoteRead.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
#if Wiimote
|
||||
using WiimoteLib.NetCore;
|
||||
|
||||
namespace ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
public class WiimoteRead : IGamepadReader {
|
||||
public event Action NextSlide;
|
||||
public event Action PrevSlide;
|
||||
|
||||
public async Task Read() {
|
||||
Wiimote wiimote = new();
|
||||
wiimote.Connect();
|
||||
|
||||
if (string.IsNullOrEmpty(wiimote.HIDDevicePath)) {
|
||||
Console.WriteLine("No controller. Please connect Wiimote via Bluetooth.");
|
||||
Console.WriteLine("Press any key to exit program.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
}
|
||||
|
||||
wiimote.WiimoteChanged += WiimoteChanged;
|
||||
|
||||
Console.WriteLine("Wiimote ready for presenting.");
|
||||
Console.WriteLine("Press Enter to exit program.");
|
||||
while (Console.ReadKey().Key != ConsoleKey.Enter) {
|
||||
await Task.Yield();
|
||||
}
|
||||
wiimote.Disconnect();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stopped.");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void WiimoteChanged(object? sender, WiimoteChangedEventArgs e) {
|
||||
if (PreviousPressed(e.WiimoteState.ButtonState)) {
|
||||
PrevSlide?.Invoke();
|
||||
}
|
||||
if (NextPressed(e.WiimoteState.ButtonState)) {
|
||||
NextSlide?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool PreviousPressed(ButtonState input) {
|
||||
return input.B || input.Left;
|
||||
}
|
||||
private static bool NextPressed(ButtonState input) {
|
||||
return input.A || input.Right;
|
||||
}
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue