refactor: Moved wiimote reading to event-based calls
This commit is contained in:
parent
e8996a382d
commit
42f5ed78fe
3 changed files with 168 additions and 34 deletions
140
.idea/.idea.SwitchSlidePresenter/.idea/workspace.xml
generated
Normal file
140
.idea/.idea.SwitchSlidePresenter/.idea/workspace.xml
generated
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoGeneratedRunConfigurationManager">
|
||||
<projectFile>SwitchSlidePresenter.csproj</projectFile>
|
||||
</component>
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="756a98cd-4cfe-4a7d-9110-f232a435843b" name="Changes" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="DpaMonitoringSettings">
|
||||
<option name="autoShow" value="false" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="GitHubPullRequestSearchHistory">{
|
||||
"lastFilter": {
|
||||
"state": "OPEN",
|
||||
"assignee": "GerardGascon"
|
||||
}
|
||||
}</component>
|
||||
<component name="GithubPullRequestsUISettings">{
|
||||
"selectedUrlAndAccountId": {
|
||||
"url": "https://github.com/GerardGascon/Switch-Slide-Presenter.git",
|
||||
"accountId": "0af66c52-cbb7-4844-ad24-01b5c5b9bee8"
|
||||
}
|
||||
}</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="file://$USER_HOME$/AppData/Local/Symbols/src/dotnet/runtime/bf5e279d9239bfef5bb1b8d6212f1b971c434606/src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/045ef3cb636f4aaa894e8cefcc5e4b367e00/c1/d22d509a/Wiimote.cs" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/SlidePresenter/Program.cs" root0="FORCE_HIGHLIGHTING" />
|
||||
</component>
|
||||
<component name="MetaFilesCheckinStateConfiguration" checkMetaFiles="true" />
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 6
|
||||
}</component>
|
||||
<component name="ProjectId" id="2htCW7BWCLo4IJC4dn1HIEGkg1I" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
|
||||
<ConfirmationsSetting value="2" id="Add" />
|
||||
</component>
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
".NET Project.SwitchSlidePresenter.executor": "Run",
|
||||
"Publish to folder.Publish ControllerSlidePresenter to folder.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"rider.external.source.directories": [
|
||||
"C:\\Users\\ggasc\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
|
||||
"C:\\Users\\ggasc\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
|
||||
"C:\\Users\\ggasc\\AppData\\Local\\Symbols\\src"
|
||||
]
|
||||
}
|
||||
}</component>
|
||||
<component name="RunManager" selected="Publish to folder.Publish ControllerSlidePresenter to folder">
|
||||
<configuration name="Publish ControllerSlidePresenter to folder" type="DotNetFolderPublish" factoryName="Publish to folder">
|
||||
<riderPublish configuration="Release" delete_existing_files="true" platform="Any CPU" runtime="Portable" target_folder="$PROJECT_DIR$/SlidePresenter/bin/Release/net8.0/publish" target_framework="net8.0" uuid_high="-467478054054508763" uuid_low="-8110965388391740835" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="ControllerSlidePresenter" type="DotNetProject" factoryName=".NET Project">
|
||||
<option name="EXE_PATH" value="$PROJECT_DIR$/SlidePresenter/bin/Debug/net8.0/ControllerSlidePresenter.exe" />
|
||||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/SlidePresenter/bin/Debug/net8.0" />
|
||||
<option name="PASS_PARENT_ENVS" value="1" />
|
||||
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||
<option name="USE_MONO" value="0" />
|
||||
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||
<option name="PROJECT_PATH" value="$PROJECT_DIR$/SlidePresenter/ControllerSlidePresenter.csproj" />
|
||||
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
|
||||
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
|
||||
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
|
||||
<option name="PROJECT_KIND" value="DotNetCore" />
|
||||
<option name="PROJECT_TFM" value="net8.0" />
|
||||
<method v="2">
|
||||
<option name="Build" />
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue=".NET Project.ControllerSlidePresenter" />
|
||||
<item itemvalue="Publish to folder.Publish ControllerSlidePresenter to folder" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="756a98cd-4cfe-4a7d-9110-f232a435843b" name="Changes" comment="" />
|
||||
<created>1718404015037</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1718404015037</updated>
|
||||
<workItem from="1718404016227" duration="5433000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="feat: Added wiimote support and cleaned up the project">
|
||||
<option name="closed" value="true" />
|
||||
<created>1718408820801</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1718408820801</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="rename: switch slide project to controller slide">
|
||||
<option name="closed" value="true" />
|
||||
<created>1718408956240</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1718408956240</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="3" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
|
||||
<component name="VcsManagerConfiguration">
|
||||
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||
<MESSAGE value="feat: Added wiimote support and cleaned up the project" />
|
||||
<MESSAGE value="rename: switch slide project to controller slide" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="rename: switch slide project to controller slide" />
|
||||
</component>
|
||||
</project>
|
|
@ -16,7 +16,7 @@ public class JoyConRead : IGamepadReader {
|
|||
|
||||
HidDevice? device = GetHidDevice();
|
||||
if (device == null) {
|
||||
Console.WriteLine("No controller. Please connect Joy-Con or Pro controller via Bluetooth.");
|
||||
Console.WriteLine("No controller. Please connect Joy-Con via Bluetooth.");
|
||||
Console.WriteLine("Press any key to exit program.");
|
||||
Console.ReadKey();
|
||||
return;
|
||||
|
@ -39,11 +39,14 @@ public class JoyConRead : IGamepadReader {
|
|||
|
||||
Console.WriteLine("JoyCon ready for presenting.");
|
||||
Console.WriteLine("Press Enter to exit program.");
|
||||
while (Console.ReadKey().Key != ConsoleKey.Enter) { }
|
||||
while (Console.ReadKey().Key != ConsoleKey.Enter) {
|
||||
await Task.Yield();
|
||||
}
|
||||
joycon.Stop();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stopped.");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static async Task LogDeviceInfo(JoyCon joycon) {
|
||||
|
|
|
@ -6,39 +6,37 @@ public class WiimoteRead : IGamepadReader {
|
|||
public event Action NextSlide;
|
||||
public event Action PrevSlide;
|
||||
|
||||
private const int RetryDelay = 1000;
|
||||
|
||||
public async Task Read() {
|
||||
Wiimote wiimote = new();
|
||||
while (string.IsNullOrEmpty(wiimote.HIDDevicePath)) {
|
||||
wiimote.Connect();
|
||||
if (string.IsNullOrEmpty(wiimote.HIDDevicePath)) {
|
||||
Console.WriteLine("Wiimote connection failed, trying again...");
|
||||
await Task.Delay(RetryDelay);
|
||||
} else {
|
||||
Console.WriteLine("Wiimote ready for presenting!");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
ButtonState previousState = wiimote.WiimoteState.ButtonState;
|
||||
while (true) {
|
||||
if (PreviousPressed(wiimote.WiimoteState.ButtonState, previousState)) {
|
||||
PrevSlide?.Invoke();
|
||||
}
|
||||
if (NextPressed(wiimote.WiimoteState.ButtonState, previousState)) {
|
||||
NextSlide?.Invoke();
|
||||
}
|
||||
previousState = wiimote.WiimoteState.ButtonState;
|
||||
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();
|
||||
|
||||
if (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Enter)
|
||||
continue;
|
||||
wiimote.Disconnect();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stopped.");
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Stopped.");
|
||||
break;
|
||||
private void WiimoteChanged(object? sender, WiimoteChangedEventArgs e) {
|
||||
if (PreviousPressed(e.WiimoteState.ButtonState)) {
|
||||
PrevSlide?.Invoke();
|
||||
}
|
||||
if (NextPressed(e.WiimoteState.ButtonState)) {
|
||||
NextSlide?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,11 +46,4 @@ public class WiimoteRead : IGamepadReader {
|
|||
private static bool NextPressed(ButtonState input) {
|
||||
return input.A || input.Right;
|
||||
}
|
||||
|
||||
private static bool PreviousPressed(ButtonState input, ButtonState previousState) {
|
||||
return PreviousPressed(input) && !PreviousPressed(previousState);
|
||||
}
|
||||
private static bool NextPressed(ButtonState input, ButtonState previousState) {
|
||||
return NextPressed(input) && !NextPressed(previousState);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue