-
Notifications
You must be signed in to change notification settings - Fork 80
Record Keyboard Controller #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
0ff228e
add KeyboardEventHandler class
jw098 f9c8bdb
KeyboardManager inherits KeyboardEventHandler
jw098 a23f5cd
ProController inherits KeyboardEventHandler::KeyboardListener
jw098 b486ace
add KeyboardEventHandler::report_keyboard_state_changed
jw098 c329ead
KeyboardListener prints whenever it detects a send or stop command.
jw098 1b6249b
Callbacks triggered at the beginning of function, instead of at the end.
jw098 c35db68
add new program RecordKeyboardController
jw098 6502b3f
KeyboardEventHandler: use ControllerState instead of ProControllerState
jw098 717aea6
add timestamp to Keyboard event callbacks
jw098 0ed91cf
RecordKeyboardController inherits KeyboardEventHandler::KeyboardListener
jw098 5cf9bfb
added AbstractController::monitor_keyboard_events(), which allows us …
jw098 1da91fc
add ControllerState::serialize_state(). Save the serialized state alo…
jw098 4be7d67
rename AbstractController::monitor_keyboard_events() to add_keyboard_…
jw098 d17908d
convert m_controller_history to json
jw098 0c41a02
add enum class ControllerCategory
jw098 34a5b09
add ControllerCategory to controller recording Json
jw098 3db52be
add MODE and JSON_FILE_NAME to UI
jw098 bd84b79
initial implementation of json_to_cpp_code_pro_controller, with place…
jw098 d40e0ea
add string_to_button() and string_to_dpad(). Finish implementation of…
jw098 dda406d
change CONTROLLER_CATEGORY_STRINGS from global variable to using lazy…
jw098 72aa64a
implemented json_to_pbf_actions()
jw098 fbe33c6
run different actions depending on the non_neutral_controller_field.
jw098 d9bb7c6
implement pbf_controller_state() for joycons
jw098 42bdf0a
refactor json_to_pbf_actions_pro_controller() and json_to_cpp_code_pr…
jw098 6b7b102
add record/playback functionality for joycons
jw098 69af1b8
output the generated C++ code to a text file. when recording, throw a…
jw098 1c847b3
fix build
jw098 a594779
fix build
jw098 146d41d
fix build
jw098 7c436da
minor UI updates
jw098 35fefea
update time duration calculation to avoid drift due to rounding error.
jw098 3ed31c1
minior UI change
jw098 ef97a19
rename ControllerCategory to ControllerClass. adjust when timestamp i…
jw098 80a67b9
fix typo
jw098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
SerialPrograms/Source/Controllers/KeyboardInput/KeyboardEventHandler.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* Keyboard Event Handler | ||
| * | ||
| */ | ||
| #include "Common/Cpp/ListenerSet.h" | ||
| #include "Common/Cpp/Containers/Pimpl.tpp" | ||
| #include "Controllers/KeyboardInput/KeyboardInput.h" | ||
| #include "KeyboardEventHandler.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
|
|
||
|
|
||
|
|
||
| struct KeyboardEventHandler::Data{ | ||
| ListenerSet<KeyboardListener> m_listeners; | ||
| }; | ||
|
|
||
| KeyboardEventHandler::KeyboardEventHandler() | ||
| : m_data(CONSTRUCT_TOKEN) | ||
| {} | ||
|
|
||
| KeyboardEventHandler::~KeyboardEventHandler() = default; | ||
|
|
||
| void KeyboardEventHandler::add_listener(KeyboardListener& listener){ | ||
| auto scope = m_lifetime_sanitizer.check_scope(); | ||
| Data& data = *m_data; | ||
| data.m_listeners.add(listener); | ||
| } | ||
| void KeyboardEventHandler::remove_listener(KeyboardListener& listener){ | ||
| auto scope = m_lifetime_sanitizer.check_scope(); | ||
| Data& data = *m_data; | ||
| data.m_listeners.remove(listener); | ||
| } | ||
|
|
||
| void KeyboardEventHandler::report_keyboard_command_sent(WallClock time_stamp, const ControllerState& state){ | ||
| auto scope = m_lifetime_sanitizer.check_scope(); | ||
| Data& data = *m_data; | ||
| data.m_listeners.run_method_unique(&KeyboardListener::on_keyboard_command_sent, time_stamp, state); | ||
| } | ||
|
|
||
| void KeyboardEventHandler::report_keyboard_command_stopped(WallClock time_stamp){ | ||
| auto scope = m_lifetime_sanitizer.check_scope(); | ||
| Data& data = *m_data; | ||
| data.m_listeners.run_method_unique(&KeyboardListener::on_keyboard_command_stopped, time_stamp); | ||
| } | ||
|
|
||
|
|
||
| } |
46 changes: 46 additions & 0 deletions
46
SerialPrograms/Source/Controllers/KeyboardInput/KeyboardEventHandler.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* Keyboard Event Handler | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
|
|
||
| #ifndef PokemonAutomation_Controllers_KeyboardEventHandler_H | ||
| #define PokemonAutomation_Controllers_KeyboardEventHandler_H | ||
|
|
||
| #include "Common/Cpp/Containers/Pimpl.h" | ||
| #include "Common/Cpp/Time.h" | ||
| #include "Common/Cpp/LifetimeSanitizer.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
|
|
||
| class ControllerState; // forward declaration to avoid circular dependency | ||
|
|
||
| class KeyboardEventHandler{ | ||
| public: | ||
| KeyboardEventHandler(); | ||
| virtual ~KeyboardEventHandler(); | ||
|
|
||
| struct KeyboardListener{ | ||
| virtual void on_keyboard_command_sent(WallClock time_stamp, const ControllerState& state) = 0; | ||
| virtual void on_keyboard_command_stopped(WallClock time_stamp) = 0; | ||
| }; | ||
| void add_listener(KeyboardListener& listener); | ||
| void remove_listener(KeyboardListener& listener); | ||
|
|
||
| protected: | ||
| // Report that the keyboard state has changed. This will be pushed to | ||
| // all listeners. | ||
| void report_keyboard_command_sent(WallClock time_stamp, const ControllerState& state); | ||
|
|
||
| void report_keyboard_command_stopped(WallClock time_stamp); | ||
|
|
||
| private: | ||
| struct Data; | ||
| Pimpl<Data> m_data; | ||
|
|
||
| LifetimeSanitizer m_lifetime_sanitizer; | ||
| }; | ||
|
|
||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the timestamp read to just before this line since it's closer to the actual time being sent to the Switch. Having it before the lock could mean an arbitrary delay.