MouseDragged and slowing it down across a network


#1

Hi, so I’m working on a semi-emergency project where people can draw on a canvas across the internet and it is converted to Gcode for a drawing robot I built. The problem is, it seems to really get bogged down when I do this live. Right now, it is a simple script using the processing net library:
The client has the following –
I have a mousePressed event, a mouseDragged, and a mouseReleased. The pressed sends a line of gcode telling the drawing tool to move into position and put the pen down on the paper, the drag event is basically a constant live update of the current mouse position (so as they drag around, it draws) and the release event sends a line of gcode saying “lift the pen up”.

This all works fine, but every now and then, because it seems to be sending THOUSANDS of strings to my server it really really slows it down, particularly all the mouseDragged events. Is there a way to say “only write every X seconds from a mousedragged event”? Since a mouseDragged is just a mouse movement with a “is it pressed” attached, can I pull only certain amounts of data, or will it ALWAYS be every tiny pixel of movement?

Thanks!


#2

If you want to send it slower you could use:

if(frameCount%<Amount of time you want> == 1) {
  Do something
}

#3

I ended up doing something similar basically calling millis(() within mousedragged. So it looks like this:

void mouseDragged(){
  line(mouseX,mouseY,pmouseX,pmouseY);
    m = millis()-last;
  if (millis() > last+0.1){
      last = millis();
      output.println("G1 X" + mouseX*0.025 + " Y" + (940-mouseY)*0.025 + " F80\n");
  }
}