|
| 1 | +/* Serial Port (PABotBase2) Interface |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include <QSerialPortInfo> |
| 8 | +#include <QWidget> |
| 9 | +#include "Common/Cpp/Json/JsonValue.h" |
| 10 | +#include "Controllers/ControllerTypeStrings.h" |
| 11 | +#include "SerialPABotBase2_Connection.h" |
| 12 | +#include "SerialPABotBase2_SelectorWidget.h" |
| 13 | +#include "SerialPABotBase2_Descriptor.h" |
| 14 | + |
| 15 | +//#include "Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.h" |
| 16 | +//#include "NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h" |
| 17 | +//#include "NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.h" |
| 18 | +//#include "NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Joycon.h" |
| 19 | + |
| 20 | +//#include <iostream> |
| 21 | +//using std::cout; |
| 22 | +//using std::endl; |
| 23 | + |
| 24 | +namespace PokemonAutomation{ |
| 25 | + |
| 26 | +template class InterfaceType_t<SerialPABotBase::SerialPABotBase2_Descriptor>; |
| 27 | + |
| 28 | +namespace SerialPABotBase{ |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +bool SerialPABotBase2_Descriptor::operator==(const ControllerDescriptor& x) const{ |
| 34 | + if (typeid(*this) != typeid(x)){ |
| 35 | + return false; |
| 36 | + } |
| 37 | + return m_name == static_cast<const SerialPABotBase2_Descriptor&>(x).m_name; |
| 38 | +} |
| 39 | + |
| 40 | + |
| 41 | +std::string SerialPABotBase2_Descriptor::display_name() const{ |
| 42 | +#if 0 |
| 43 | + QSerialPortInfo info(QString::fromStdString(m_name)); |
| 44 | + if (info.isNull()){ |
| 45 | + return m_name; |
| 46 | + } |
| 47 | + return m_name + " - " + info.manufacturer().toStdString(); |
| 48 | +#else |
| 49 | + return m_name; |
| 50 | +#endif |
| 51 | +} |
| 52 | +void SerialPABotBase2_Descriptor::load_json(const JsonValue& json){ |
| 53 | + const std::string* name = json.to_string(); |
| 54 | + if (name == nullptr || name->empty()){ |
| 55 | + return; |
| 56 | + } |
| 57 | + m_name = *name; |
| 58 | +} |
| 59 | +JsonValue SerialPABotBase2_Descriptor::to_json() const{ |
| 60 | + return m_name; |
| 61 | +} |
| 62 | + |
| 63 | +std::unique_ptr<ControllerConnection> SerialPABotBase2_Descriptor::open_connection( |
| 64 | + Logger& logger, |
| 65 | + bool set_to_null_controller |
| 66 | +) const{ |
| 67 | + return std::unique_ptr<ControllerConnection>( |
| 68 | + new SerialPABotBase2_Connection(logger, m_name, set_to_null_controller) |
| 69 | + ); |
| 70 | +} |
| 71 | +std::unique_ptr<AbstractController> SerialPABotBase2_Descriptor::make_controller( |
| 72 | + Logger& logger, |
| 73 | + ControllerConnection& connection, |
| 74 | + ControllerType controller_type, |
| 75 | + ControllerResetMode reset_mode |
| 76 | +) const{ |
| 77 | +#if 0 |
| 78 | + switch (controller_type){ |
| 79 | +#if 0 |
| 80 | + case ControllerType::HID_Keyboard: |
| 81 | + return std::unique_ptr<AbstractController>( |
| 82 | + new PokemonAutomation::StandardHid::SerialPABotBase_Keyboard( |
| 83 | + logger, |
| 84 | + static_cast<SerialPABotBase_Connection&>(connection), |
| 85 | + reset_mode |
| 86 | + ) |
| 87 | + ); |
| 88 | +#endif |
| 89 | +#if 0 |
| 90 | + case ControllerType::NintendoSwitch_WiredController: |
| 91 | + case ControllerType::NintendoSwitch2_WiredController: |
| 92 | + return std::unique_ptr<AbstractController>( |
| 93 | + new PokemonAutomation::NintendoSwitch::SerialPABotBase_WiredController( |
| 94 | + logger, |
| 95 | + static_cast<SerialPABotBase_Connection&>(connection), |
| 96 | + controller_type, |
| 97 | + reset_mode |
| 98 | + ) |
| 99 | + ); |
| 100 | + |
| 101 | + case ControllerType::NintendoSwitch_WiredProController: |
| 102 | + case ControllerType::NintendoSwitch_WirelessProController: |
| 103 | + return std::unique_ptr<AbstractController>( |
| 104 | + new PokemonAutomation::NintendoSwitch::SerialPABotBase_ProController( |
| 105 | + logger, |
| 106 | + static_cast<SerialPABotBase_Connection&>(connection), |
| 107 | + controller_type, |
| 108 | + reset_mode |
| 109 | + ) |
| 110 | + ); |
| 111 | + |
| 112 | + case ControllerType::NintendoSwitch_WiredLeftJoycon: |
| 113 | + case ControllerType::NintendoSwitch_WirelessLeftJoycon: |
| 114 | + return std::unique_ptr<AbstractController>( |
| 115 | + new PokemonAutomation::NintendoSwitch::SerialPABotBase_LeftJoycon( |
| 116 | + logger, |
| 117 | + static_cast<SerialPABotBase_Connection&>(connection), |
| 118 | + controller_type, |
| 119 | + reset_mode |
| 120 | + ) |
| 121 | + ); |
| 122 | + |
| 123 | + case ControllerType::NintendoSwitch_WiredRightJoycon: |
| 124 | + case ControllerType::NintendoSwitch_WirelessRightJoycon: |
| 125 | + return std::unique_ptr<AbstractController>( |
| 126 | + new PokemonAutomation::NintendoSwitch::SerialPABotBase_RightJoycon( |
| 127 | + logger, |
| 128 | + static_cast<SerialPABotBase_Connection&>(connection), |
| 129 | + controller_type, |
| 130 | + reset_mode |
| 131 | + ) |
| 132 | + ); |
| 133 | +#endif |
| 134 | + |
| 135 | + default:; |
| 136 | + } |
| 137 | +#endif |
| 138 | + |
| 139 | + logger.log( |
| 140 | + std::string("Unsupported Controller Type: ") + CONTROLLER_TYPE_STRINGS.get_string(controller_type), |
| 141 | + COLOR_RED |
| 142 | + ); |
| 143 | + return nullptr; |
| 144 | +} |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | +QWidget* SerialPABotBase2_Descriptor::make_selector_QtWidget(ControllerSelectorWidget& parent) const{ |
| 149 | + return new SerialPABotBase2_SelectorWidget(parent, this); |
| 150 | +} |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +} |
| 156 | +} |
0 commit comments