Skip to content

Commit ef97a19

Browse files
committed
rename ControllerCategory to ControllerClass. adjust when timestamp is taken. refactor JsonObject operator!=. refactor button_to_code_string() and button_to_string().
1 parent 3ed31c1 commit ef97a19

15 files changed

+65
-101
lines changed

Common/Cpp/Json/JsonObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JsonObject{
2323
return dump() == x.dump();
2424
}
2525
bool operator!=(const JsonObject& x){
26-
return dump() != x.dump();
26+
return !(*this == *this);
2727
}
2828
private:
2929
// Private to avoid accidental copying.

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace PokemonAutomation{
2020
class RecursiveThrottler;
2121
enum class ControllerType;
2222
enum class ControllerPerformanceClass;
23-
enum class ControllerCategory;
23+
enum class ControllerClass;
2424

2525

2626

@@ -66,7 +66,7 @@ class AbstractController{
6666

6767
virtual const char* name() = 0;
6868
virtual ControllerType controller_type() const = 0;
69-
virtual ControllerCategory controller_category() const = 0;
69+
virtual ControllerClass controller_class() const = 0;
7070
virtual ControllerPerformanceClass performance_class() const = 0;
7171

7272
// If the controller is polled at a fixed interval, this is that interval.

SerialPrograms/Source/Controllers/ControllerTypeStrings.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS{
3232
{ControllerType::NintendoSwitch2_RightJoycon, "NS2: Right Joycon"},
3333
};
3434

35-
const EnumStringMap<ControllerCategory>& CONTROLLER_CATEGORY_STRINGS(){
36-
static EnumStringMap<ControllerCategory> database{
37-
{ControllerCategory::NONE, "none"},
38-
{ControllerCategory::LEFT_JOYCON, "left-joycon"},
39-
{ControllerCategory::RIGHT_JOYCON, "right-joycon"},
40-
{ControllerCategory::PRO_CONTROLLER, "pro-controller"},
35+
const EnumStringMap<ControllerClass>& CONTROLLER_CLASS_STRINGS(){
36+
static EnumStringMap<ControllerClass> database{
37+
{ControllerClass::NONE, "none"},
38+
{ControllerClass::LEFT_JOYCON, "left-joycon"},
39+
{ControllerClass::RIGHT_JOYCON, "right-joycon"},
40+
{ControllerClass::PRO_CONTROLLER, "pro-controller"},
4141
};
4242
return database;
4343
}

SerialPrograms/Source/Controllers/ControllerTypeStrings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace PokemonAutomation{
1616

1717
extern const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS;
1818
extern const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS;
19-
const EnumStringMap<ControllerCategory>& CONTROLLER_CATEGORY_STRINGS();
19+
const EnumStringMap<ControllerClass>& CONTROLLER_CLASS_STRINGS();
2020

2121

2222

SerialPrograms/Source/Controllers/ControllerTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum class ControllerPerformanceClass{
4444
SysbotBase,
4545
};
4646

47-
enum class ControllerCategory{
47+
enum class ControllerClass{
4848
NONE,
4949
LEFT_JOYCON,
5050
RIGHT_JOYCON,

SerialPrograms/Source/Controllers/KeyboardInput/KeyboardEventHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class KeyboardEventHandler{
2121
KeyboardEventHandler();
2222
virtual ~KeyboardEventHandler();
2323

24-
struct KeyboardListener{
24+
struct KeyboardListener{
2525
virtual void on_keyboard_command_sent(WallClock time_stamp, const ControllerState& state) = 0;
2626
virtual void on_keyboard_command_stopped(WallClock time_stamp) = 0;
2727
};

SerialPrograms/Source/Controllers/KeyboardInput/KeyboardInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ class KeyboardManager : public KeyboardInputController, public KeyboardEventHand
126126
deltas.to_state(static_cast<StateType&>(state));
127127
}
128128
virtual void cancel_all_commands() override{
129-
WallClock time_stamp = current_time();
130129
WriteSpinLock lg(m_lock);
131130
if (m_controller == nullptr){
132131
return;
133132
}
133+
WallClock time_stamp = current_time();
134134
m_controller->cancel_all_commands();
135135
report_keyboard_command_stopped(time_stamp);
136136
}

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class SerialPABotBase_Keyboard final :
5353
virtual ControllerType controller_type() const override{
5454
return ControllerType::HID_Keyboard;
5555
}
56-
virtual ControllerCategory controller_category() const override{
57-
return ControllerCategory::KEYBOARD;
56+
virtual ControllerClass controller_class() const override{
57+
return ControllerClass::KEYBOARD;
5858
}
5959
virtual ControllerPerformanceClass performance_class() const override{
6060
return ControllerPerformanceClass::SerialPABotBase_Wired;

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.cpp

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,12 @@ const EnumStringMap<Button> BUTTON_CODE_STRINGS{
7272

7373
std::string button_to_string(Button button){
7474
std::string str;
75-
if (button & BUTTON_Y) str += BUTTON_STRINGS.get_string(BUTTON_Y) + " ";
76-
if (button & BUTTON_B) str += BUTTON_STRINGS.get_string(BUTTON_B) + " ";
77-
if (button & BUTTON_A) str += BUTTON_STRINGS.get_string(BUTTON_A) + " ";
78-
if (button & BUTTON_X) str += BUTTON_STRINGS.get_string(BUTTON_X) + " ";
79-
if (button & BUTTON_L) str += BUTTON_STRINGS.get_string(BUTTON_L) + " ";
80-
if (button & BUTTON_R) str += BUTTON_STRINGS.get_string(BUTTON_R) + " ";
81-
if (button & BUTTON_ZL) str += BUTTON_STRINGS.get_string(BUTTON_ZL) + " ";
82-
if (button & BUTTON_ZR) str += BUTTON_STRINGS.get_string(BUTTON_ZR) + " ";
83-
if (button & BUTTON_MINUS) str += BUTTON_STRINGS.get_string(BUTTON_MINUS) + " ";
84-
if (button & BUTTON_PLUS) str += BUTTON_STRINGS.get_string(BUTTON_PLUS) + " ";
85-
if (button & BUTTON_LCLICK) str += BUTTON_STRINGS.get_string(BUTTON_LCLICK) + " ";
86-
if (button & BUTTON_RCLICK) str += BUTTON_STRINGS.get_string(BUTTON_RCLICK) + " ";
87-
if (button & BUTTON_HOME) str += BUTTON_STRINGS.get_string(BUTTON_HOME) + " ";
88-
if (button & BUTTON_CAPTURE) str += BUTTON_STRINGS.get_string(BUTTON_CAPTURE) + " ";
89-
if (button & BUTTON_GR) str += BUTTON_STRINGS.get_string(BUTTON_GR) + " ";
90-
if (button & BUTTON_GL) str += BUTTON_STRINGS.get_string(BUTTON_GL) + " ";
91-
if (button & BUTTON_UP) str += BUTTON_STRINGS.get_string(BUTTON_UP) + " ";
92-
if (button & BUTTON_RIGHT) str += BUTTON_STRINGS.get_string(BUTTON_RIGHT) + " ";
93-
if (button & BUTTON_DOWN) str += BUTTON_STRINGS.get_string(BUTTON_DOWN) + " ";
94-
if (button & BUTTON_LEFT) str += BUTTON_STRINGS.get_string(BUTTON_LEFT) + " ";
95-
if (button & BUTTON_LEFT_SL) str += BUTTON_STRINGS.get_string(BUTTON_LEFT_SL) + " ";
96-
if (button & BUTTON_LEFT_SR) str += BUTTON_STRINGS.get_string(BUTTON_LEFT_SR) + " ";
97-
if (button & BUTTON_RIGHT_SL) str += BUTTON_STRINGS.get_string(BUTTON_RIGHT_SL) + " ";
98-
if (button & BUTTON_RIGHT_SR) str += BUTTON_STRINGS.get_string(BUTTON_RIGHT_SR) + " ";
99-
if (button & BUTTON_C) str += BUTTON_STRINGS.get_string(BUTTON_C) + " ";
75+
for (auto iter = BUTTON_STRINGS.begin(); iter != BUTTON_STRINGS.end(); ++iter){
76+
if (iter->first & button){
77+
str += iter->second + " ";
78+
}
79+
}
80+
10081
if (str.empty()){
10182
str = BUTTON_STRINGS.get_string(BUTTON_NONE);
10283
}
@@ -119,36 +100,18 @@ Button string_to_button(std::string multi_button_string){
119100

120101
std::string button_to_code_string(Button button){
121102
std::string str;
122-
if (button & BUTTON_Y) str += BUTTON_CODE_STRINGS.get_string(BUTTON_Y) + " | ";
123-
if (button & BUTTON_B) str += BUTTON_CODE_STRINGS.get_string(BUTTON_B) + " | ";
124-
if (button & BUTTON_A) str += BUTTON_CODE_STRINGS.get_string(BUTTON_A) + " | ";
125-
if (button & BUTTON_X) str += BUTTON_CODE_STRINGS.get_string(BUTTON_X) + " | ";
126-
if (button & BUTTON_L) str += BUTTON_CODE_STRINGS.get_string(BUTTON_L) + " | ";
127-
if (button & BUTTON_R) str += BUTTON_CODE_STRINGS.get_string(BUTTON_R) + " | ";
128-
if (button & BUTTON_ZL) str += BUTTON_CODE_STRINGS.get_string(BUTTON_ZL) + " | ";
129-
if (button & BUTTON_ZR) str += BUTTON_CODE_STRINGS.get_string(BUTTON_ZR) + " | ";
130-
if (button & BUTTON_MINUS) str += BUTTON_CODE_STRINGS.get_string(BUTTON_MINUS) + " | ";
131-
if (button & BUTTON_PLUS) str += BUTTON_CODE_STRINGS.get_string(BUTTON_PLUS) + " | ";
132-
if (button & BUTTON_LCLICK) str += BUTTON_CODE_STRINGS.get_string(BUTTON_LCLICK) + " | ";
133-
if (button & BUTTON_RCLICK) str += BUTTON_CODE_STRINGS.get_string(BUTTON_RCLICK) + " | ";
134-
if (button & BUTTON_HOME) str += BUTTON_CODE_STRINGS.get_string(BUTTON_HOME) + " | ";
135-
if (button & BUTTON_CAPTURE) str += BUTTON_CODE_STRINGS.get_string(BUTTON_CAPTURE) + " | ";
136-
if (button & BUTTON_GR) str += BUTTON_CODE_STRINGS.get_string(BUTTON_GR) + " | ";
137-
if (button & BUTTON_GL) str += BUTTON_CODE_STRINGS.get_string(BUTTON_GL) + " | ";
138-
if (button & BUTTON_UP) str += BUTTON_CODE_STRINGS.get_string(BUTTON_UP) + " | ";
139-
if (button & BUTTON_RIGHT) str += BUTTON_CODE_STRINGS.get_string(BUTTON_RIGHT) + " | ";
140-
if (button & BUTTON_DOWN) str += BUTTON_CODE_STRINGS.get_string(BUTTON_DOWN) + " | ";
141-
if (button & BUTTON_LEFT) str += BUTTON_CODE_STRINGS.get_string(BUTTON_LEFT) + " | ";
142-
if (button & BUTTON_LEFT_SL) str += BUTTON_CODE_STRINGS.get_string(BUTTON_LEFT_SL) + " | ";
143-
if (button & BUTTON_LEFT_SR) str += BUTTON_CODE_STRINGS.get_string(BUTTON_LEFT_SR) + " | ";
144-
if (button & BUTTON_RIGHT_SL) str += BUTTON_CODE_STRINGS.get_string(BUTTON_RIGHT_SL) + " | ";
145-
if (button & BUTTON_RIGHT_SR) str += BUTTON_CODE_STRINGS.get_string(BUTTON_RIGHT_SR) + " | ";
146-
if (button & BUTTON_C) str += BUTTON_CODE_STRINGS.get_string(BUTTON_C) + " | ";
103+
std::string logical_or = " | ";
104+
for (auto iter = BUTTON_CODE_STRINGS.begin(); iter != BUTTON_CODE_STRINGS.end(); ++iter){
105+
if (iter->first & button){
106+
str += iter->second + logical_or;
107+
}
108+
}
109+
147110
if (str.empty()){
148111
str = BUTTON_CODE_STRINGS.get_string(BUTTON_NONE);
149112
}
150-
if (str.substr(str.size() - 3) == " | "){
151-
str = str.substr(0, str.size() - 3);
113+
if (str.substr(str.size() - logical_or.size()) == logical_or){ // remove trailing " | "
114+
str = str.substr(0, str.size() - logical_or.size());
152115
}
153116
return str;
154117
}

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_Joycon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class JoyconController::KeyboardManager final :
5757
stop();
5858
}
5959
virtual void send_state(const ControllerState& state) override{
60-
WallClock time_stamp = current_time();
60+
6161
const JoyconState& switch_state = static_cast<const JoyconState&>(state);
6262
#if 0
6363
m_controller->logger().log(
@@ -72,6 +72,7 @@ class JoyconController::KeyboardManager final :
7272
return;
7373
}
7474
Milliseconds ticksize = m_controller->ticksize();
75+
WallClock time_stamp = current_time();
7576
static_cast<JoyconController*>(m_controller)->issue_full_controller_state(
7677
nullptr,
7778
switch_state.buttons,

0 commit comments

Comments
 (0)