-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathCommandLine_Main.cpp
More file actions
96 lines (76 loc) · 3.66 KB
/
CommandLine_Main.cpp
File metadata and controls
96 lines (76 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* Command Line Tool Main
*
* From: https://github.com/PokemonAutomation/
*
* Command-line executable for Pokemon Automation utilities.
* GUI-free tool for tasks like camera stream checks, debugging, etc.
*/
#include <iostream>
#include "Common/Cpp/Color.h"
#include "CommonFramework/Logging/Logger.h"
// #include "CommonFramework/Logging/OutputRedirector.h"
#include "Integrations/PybindSwitchController.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
using namespace PokemonAutomation;
using namespace PokemonAutomation::NintendoSwitch;
namespace PokemonAutomation{
// This function is required by Common/Cpp/Logging/GlobalLogger.h:global_logger_raw() to initialize
// the global file logger.
// This function is called the first time `global_logger_raw()` is called to initialize the static
// local global file logger object.
FileLoggerConfig make_global_config(){
return FileLoggerConfig{
.file_path = "./SerialProgramsCommandLine.log"
};
}
}
int main(int argc, char* argv[]){
// // Set up output redirection for logging
// OutputRedirector redirect_stdout(std::cout, "stdout", Color());
// OutputRedirector redirect_stderr(std::cerr, "stderr", COLOR_RED);
// Get the global command-line logger (suitable for command-line tools)
Logger& logger = global_logger_command_line();
logger.log("================================================================================");
logger.log("Starting Program...");
logger.log("Pokemon Automation - Command Line Tool");
// Check if port name argument is provided
if (argc < 2) {
logger.log("Usage: " + std::string(argv[0]) + " <port_name>", COLOR_RED);
logger.log("Example: " + std::string(argv[0]) + " cu.usbserial-0001");
return 1;
}
// Test PybindSwitchProController
logger.log("================================================================================");
logger.log("Testing PybindSwitchProController...");
try {
// Create controller with port name from command-line argument
const std::string port_name = argv[1];
logger.log("Creating PybindSwitchProController with port: " + port_name);
PybindSwitchProController controller(port_name);
controller.wait_for_ready(5000);
// Check if controller is ready
if (controller.is_ready()) {
logger.log("Controller is ready!", COLOR_GREEN);
logger.log("Status: " + controller.current_status());
// Mash A button for 3 seconds
logger.log("Mashing A button for 3 seconds...");
for(int i = 0; i < 30; i++){
// Push A button: delay=0ms, hold=50ms, release=50ms, button=BUTTON_A
controller.push_button(0, 50, 50, static_cast<uint32_t>(BUTTON_A));
}
// Wait for all button commands to complete
logger.log("Waiting for all requests to complete...");
controller.wait_for_all_requests();
logger.log("A button mashing completed!", COLOR_GREEN);
} else {
logger.log("Controller is not ready!", COLOR_RED);
logger.log("Status: " + controller.current_status());
}
} catch (const std::exception& e) {
logger.log("Error during controller test: " + std::string(e.what()), COLOR_RED);
}
logger.log("================================================================================");
logger.log("Program completed successfully.");
logger.log("================================================================================");
return 0;
}