So there's been a bit of chat about making an API for the polargraph machine.
Decoupling the control interface from the comms and from the pattern generation stuff is something I've been meaning to do for about as long as the controller has existed, but what I've actually done is just shoe-horned more and more stuff into the controller instead. The downside to that is that the barrier to other folks adding anything gets steeper as the code becomes more and more dense.
I think abstracting the modular parts out to a library is the right thing to do. I don't have the right skills to do that very well with the firmware, but I can do it for the processing stuff I think.
The problem I'll have is figuring out how abstract I can actually make the interface for it. Actually the current controller has the machine itself fairly well abstracted, but some extra simplification might be necessary because it incorporates all the image loading, position and guides and things on it.
So something like:
// set width, height, max drawable area (top left, bot right coords), and steps per mm,
m = new Polargraph(890, 1000, 100, 120, 790, 800, 66.7);
// define the home position throw exception if outside of drawable area
m.setHomePosition(new PVector(445, 120));
// define the area to be used for drawing operations
// this is an area that will have it's own coordinates system and can behave a bit like a mini machine
sub = m.createNewDrawing(100, 120, 400, 400);
// make a queue up and attach it to the machine object
PolargraphQueueWriter queue = new PolargraphQueueWriterVirtualCom("COM 14");
sub.addQueueWriter(queue);
queue.pause();
// build a couple of commands and put them in the queue
PolargraphCommand command = sub.getCommand(sub.SET_POSITION_TO_HOME);
queue.addCommand(command);
command = sub.getCommand(sub.MOVE_TO_POSITION);
command.addParams(100, 150);
queue.addCommand(command);
// run the queue
if (queue.ready())
queue.sendNextCommand();
I'm putting this here as a way to see if my way is stupid. Have a think about things you would want to be able to do. I'm working on the basis that you make a machine object, define an area on that machine, define a scaling value for that area, and then start firing coordinates into it. Now it could take care of the comms too, and the queue, or it could just return each input coordinate as it's own translated command, and it'd be your job (or the job of some other class) to catch those and put them in a queue, however you're connecting to it.
The former would be an easier thing to get up and running, but the latter is a better plan in the long run. I'll have a think too. This probably isn't the best way to design an API, but we'll go with it for now 🙂
Cheers!
sn
|