import processing.core.PApplet;  // need the "this" in parent app to work
import processing.serial.*;
import cc.arduino.*;

public abstract class ArduinoHandler{
  public ArduinoHandler(PApplet parent){
    String[] ard_list = Arduino.list();
    
    // Find the Arduino
    boolean found = false;
    println("Find Arduino!");
    for( int i = 0; i < ard_list.length; i++ ){
      String dev_now = ard_list[i];  // get one name
      println(dev_now);
      if( dev_now.substring(0, ard_prefix.length()).equals(ard_prefix) ){
        println("Arduino found @ "+dev_now);
        m_arduino = new Arduino(parent, Arduino.list()[i], 57600);
        found = true;  // found the arduino
        break;
      }
    }
    // not found then notify
    if(!found){
      println("No arduino found, please check your connection");
    }
    
    // Do the init
    if(!init()){
      println("Something wrong with initilization");
    }
  };
  
  protected abstract boolean init();
  protected Arduino m_arduino;
  // This is written for on arduino on MAC only needs other stuff after having multiple platforms
  protected final String ard_prefix = "/dev/cu.usbmodem";
} 
  • No labels