Saturday, May 19, 2012

USB is working!

I spent some time digging through libftdi, and was able to get USB serial IO to work!  I had a problem sending gcode initially, but it turns out that I wasn't using the Message class correctly for inter-process IO.  Instead of handing the String to the Message directly, I needed to add it as a bundle:

public void send_gcode(String gcode) {
  if (messenger == null)
    return;
  Message msg = Message.obtain(null, TinyGDriver.GCODE, 0, 0, null);
  Bundle b = new Bundle();
  b.putString("gcode", gcode);
  msg.setData(b);
  try {
    messenger.send(msg);
  } catch (RemoteException e) {
    e.printStackTrace();
  }
}

So now all of the controls work via USB as well as through the network!  If you're interested in trying these out but don't have an Android development environment, I've placed packages for both the USB Service module and the TinyG for Android app up on my github site.

I'm working out a few kinks still, but the packages do seem to be useable.  The most important thing to note is that if you want to use the USB module, you need to select USB under Settings in the TinyG menu, but then exit the application.  I need to find a way to signal to main Activity when a preference has changed so that I can reset the Service binding, and I haven't found it yet.  Another point to be aware of is the USB permissions model on Android.  When you try to connect to USB, it will prompt you to make sure it's ok that the app does so.  It seems to be able to save this preference, but that doesn't seem to be reliable for me.

Now that the framework is all set, I can spend some time adding additional features, such as tablet-friendly layouts, and a gcode uploader.

No comments:

Post a Comment