inoUtils.cpp 920 Bytes
#include "inoUtils.h"

#include "ofMain.h"

#if defined(__linux__)
const string patterns[] = {
  "/dev/ttyACM", 
  "/dev/ttyUSB"
};
#elif defined(__APPLE__)
const string patterns[] = { 
  "/dev/tty.usbmodem", 
  "/dev/tty.usbserial"
};
#else
const string patterns[] = {
  "COM"
};
#endif

bool isArduinoPort(const string & path) {
  for(string pattern : patterns) {
    if(path.compare(0, pattern.size(), pattern) == 0)
      return true;
  }
  return false;
}

vector<string> getArduinoDevices() {
  ofSerial serial;
  vector<ofSerialDeviceInfo> deviceList = serial.getDeviceList();
  auto it = remove_if(deviceList.begin(), deviceList.end(), 
      [](ofSerialDeviceInfo & info) {
      return ! isArduinoPort(info.getDevicePath());
      });
  deviceList.erase(it, deviceList.end());
  vector<string> paths;
  for(ofSerialDeviceInfo dev : deviceList) {
    paths.push_back(dev.getDevicePath());
  }
  return paths;
}