| 9 | #include "Arduino.h" |
| 10 | |
| 11 | Arduino::Arduino(const std::string& port, unsigned int baud_rate, ArduinoProtocol protocol) |
| 12 | : protocol_(protocol), |
| 13 | button_mask_(0), |
| 14 | is_open_(false), |
| 15 | timer_running_(false), |
| 16 | listening_(false), |
| 17 | aiming_active(false), |
| 18 | shooting_active(false), |
| 19 | zooming_active(false) |
| 20 | { |
| 21 | try |
| 22 | { |
| 23 | serial_.setPort(port); |
| 24 | serial_.setBaudrate(baud_rate); |
| 25 | serial_.open(); |
| 26 | |
| 27 | if (serial_.isOpen()) |
| 28 | { |
| 29 | is_open_ = true; |
| 30 | std::cout << "[Arduino] Connected! PORT: " << port << std::endl; |
| 31 | |
| 32 | if (config.arduino_enable_keys || protocol_ == ArduinoProtocol::Teensy41) |
| 33 | { |
| 34 | startListening(); |
| 35 | } |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | std::cerr << "[Arduino] Unable to connect to the port: " << port << std::endl; |
| 40 | } |
| 41 | } |
| 42 | catch (std::exception& e) |
| 43 | { |
| 44 | std::cerr << "[Arduino] Error: " << e.what() << std::endl; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | Arduino::~Arduino() |
| 49 | { |