1- /* SerialPABotBase: Pokken Controller
1+ /* SerialPABotBase: Wired Controller (Switch 1)
22 *
33 * From: https://github.com/PokemonAutomation/
44 *
77#include " Common/Cpp/PrettyPrint.h"
88#include " Common/Cpp/Exceptions.h"
99#include " Common/Cpp/Concurrency/ReverseLockGuard.h"
10- #include " Common/Cpp/Options/TimeExpressionOption.h"
11- #include " Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h"
10+ // #include "Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h"
1211#include " CommonFramework/Options/Environment/ThemeSelectorOption.h"
1312#include " Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h"
14- #include " Controllers/SerialPABotBase/SerialPABotBase_Routines_NS_Generic .h"
15- #include " NintendoSwitch_SerialPABotBase_PokkenController .h"
13+ #include " Controllers/SerialPABotBase/SerialPABotBase_Routines_NS1_WiredController .h"
14+ #include " NintendoSwitch_SerialPABotBase_WiredController .h"
1615
1716// #include <iostream>
1817// using std::cout;
@@ -26,7 +25,7 @@ using namespace std::chrono_literals;
2625
2726
2827
29- SerialPABotBase_PokkenController::SerialPABotBase_PokkenController (
28+ SerialPABotBase_WiredController::SerialPABotBase_WiredController (
3029 Logger& logger,
3130 SerialPABotBase::SerialPABotBase_Connection& connection
3231)
@@ -37,13 +36,13 @@ SerialPABotBase_PokkenController::SerialPABotBase_PokkenController(
3736 connection
3837 )
3938 , m_stopping(false )
40- , m_status_thread(&SerialPABotBase_PokkenController ::status_thread, this )
39+ , m_status_thread(&SerialPABotBase_WiredController ::status_thread, this )
4140{}
42- SerialPABotBase_PokkenController ::~SerialPABotBase_PokkenController (){
41+ SerialPABotBase_WiredController ::~SerialPABotBase_WiredController (){
4342 stop ();
4443 m_status_thread.join ();
4544}
46- void SerialPABotBase_PokkenController ::stop (){
45+ void SerialPABotBase_WiredController ::stop (){
4746 if (m_stopping.exchange (true )){
4847 return ;
4948 }
@@ -62,7 +61,7 @@ void SerialPABotBase_PokkenController::stop(){
6261
6362
6463
65- void SerialPABotBase_PokkenController ::push_state (const Cancellable* cancellable, WallDuration duration){
64+ void SerialPABotBase_WiredController ::push_state (const Cancellable* cancellable, WallDuration duration){
6665 // Must be called inside "m_state_lock".
6766
6867 if (!is_ready ()){
@@ -192,7 +191,7 @@ void SerialPABotBase_PokkenController::push_state(const Cancellable* cancellable
192191 while (time_left > Milliseconds::zero ()){
193192 Milliseconds current = std::min (time_left, 65535ms);
194193 m_serial->issue_request (
195- SerialPABotBase::DeviceRequest_NS_Generic_ControllerStateMs (
194+ SerialPABotBase::DeviceRequest_NS1_WiredController_ControllerStateMs (
196195 (uint16_t )current.count (),
197196 buttons,
198197 dpad,
@@ -231,69 +230,8 @@ class ExtendedLengthCounter{
231230};
232231
233232
234- #if 0
235- class TickRateTracker{
236- public:
237- TickRateTracker(double expected_ticks_per_second)
238- : m_expected_ticks_per_second(expected_ticks_per_second)
239- // , m_history(10)
240- {}
241-
242-
243- double push_ticks(uint64_t ticks){
244- WallClock now = current_time();
245-
246- // if (m_history.full()){
247- // m_history.pop_front();
248- // }
249-
250- if (ticks <= m_last_ticks){
251- m_last_push = WallClock::min();
252- m_last_ticks = 0;
253- m_consecutive_off = 0;
254- }
255-
256- double ticks_per_second = 0;
257-
258- if (m_last_push != WallClock::min()){
259- uint64_t elapsed_ticks = ticks - m_last_ticks;
260- double elapsed_seconds = std::chrono::duration_cast<std::chrono::microseconds>(now - m_last_push).count() * 0.000001;
261- ticks_per_second = elapsed_ticks / elapsed_seconds;
262- // m_history.push_back(ticks_per_second);
263-
264- double rate_error = std::abs(ticks_per_second - m_expected_ticks_per_second) / m_expected_ticks_per_second;
265- if (rate_error > 0.1){
266- m_consecutive_off++;
267- }else{
268- m_consecutive_off = 0;
269- }
270-
271- }
272-
273- m_last_push = now;
274- m_last_ticks = ticks;
275-
276- return ticks_per_second;
277- }
278-
279- size_t consecutive_off_readings() const{
280- return m_consecutive_off;
281- }
282-
283-
284- private:
285- double m_expected_ticks_per_second;
286- WallClock m_last_push = WallClock::min();
287- uint64_t m_last_ticks = 0;
288-
289- size_t m_consecutive_off = 0;
290-
291- // CircularBuffer<double> m_history;
292- };
293- #endif
294-
295233
296- void SerialPABotBase_PokkenController ::status_thread (){
234+ void SerialPABotBase_WiredController ::status_thread (){
297235 constexpr std::chrono::milliseconds PERIOD (1000 );
298236 std::atomic<WallClock> last_ack (current_time ());
299237
0 commit comments