refactor: change portname parameter to const char* in startCommunication and improve USB device check logic

This commit is contained in:
ishak jmilou.ishak
2025-01-21 12:23:20 +01:00
parent 29ef742a94
commit 99599a6c21
2 changed files with 5 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ public:
long loop(void *user_data, TKobukiData &Kobuki_data); long loop(void *user_data, TKobukiData &Kobuki_data);
void startCommunication(char *portname,bool CommandsEnabled,void *userDataL); void startCommunication(const char *portname,bool CommandsEnabled,void *userDataL);
int measure(); //thread function, contains an infinite loop and reads data int measure(); //thread function, contains an infinite loop and reads data
void setLed(int led1 = 0, int led2 = 0); //led1 green/red 2/1, //led2 green/red 2/1 void setLed(int led1 = 0, int led2 = 0); //led1 green/red 2/1, //led2 green/red 2/1
void setTranslationSpeed(int mmpersec); void setTranslationSpeed(int mmpersec);

View File

@@ -77,10 +77,9 @@ void checkKobukiConnection()
std::lock_guard<std::mutex> lock(connectionMutex); std::lock_guard<std::mutex> lock(connectionMutex);
std::string port = findKobukiPort(); std::string port = findKobukiPort();
// Controleer of het apparaat beschikbaar is if (port.empty()) {
if (!std::ifstream("/dev/ttyUSB0")){ if (kobuki_connected) {
if (kobuki_connected){ cout << "Kobuki disconnected: No USB device found." << endl;
cout << "Kobuki disconnected: USB device not found." << endl;
kobuki_connected = false; kobuki_connected = false;
} }
std::this_thread::sleep_for(std::chrono::seconds(5)); std::this_thread::sleep_for(std::chrono::seconds(5));
@@ -95,7 +94,7 @@ void checkKobukiConnection()
} }
cout << "Attempting to reconnect Kobuki..." << endl; cout << "Attempting to reconnect Kobuki..." << endl;
robot.startCommunication(const_cast<char*>(port.c_str()), true, nullptr); robot.startCommunication((port.c_str()), true, nullptr);
if (robot.isConnected()){ if (robot.isConnected()){
cout << "Kobuki reconnected successfully!" << endl; cout << "Kobuki reconnected successfully!" << endl;