Added downloading speed and lift range. Fixed some errors around vector rescaling. Added "upload speed" and "upload lift range" as buttons, but upload speed isn't showing up for some reason. Another day. Removed procontroll as a dependency and the gamepad as an input device. Commented out code in case anyone else wants it.

This commit is contained in:
Sandy Noble 2013-04-16 23:14:46 +01:00
parent 1220b94564
commit 06de465945
5 changed files with 377 additions and 299 deletions

View File

@ -104,6 +104,10 @@ void numberbox_mode_penDownPos(int value)
penLiftDownPosition = value;
}
void button_mode_sendPenliftRange()
{
addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END");
}
void button_mode_sendPenliftRangePersist()
{
addToCommandQueue(CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",1,END");
}
@ -451,24 +455,27 @@ void numberbox_mode_resizeImage(float value)
void numberbox_mode_resizeVector(float value)
{
// get current size of vector in local coordinates
PVector oldVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
oldVectorSize = PVector.mult(oldVectorSize, (vectorScaling/100));
// and current centre point of vector
PVector oldCentroid = new PVector(oldVectorSize.x / 2.0, oldVectorSize.y / 2.0);
// get newly scaled size of vector
PVector newVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
newVectorSize = PVector.mult(newVectorSize, (value/100));
// and new centre point of vector
PVector newCentroid = new PVector(newVectorSize.x / 2.0, newVectorSize.y / 2.0);
// difference is current centre minus new centre
PVector difference = PVector.sub(oldCentroid, newCentroid);
// add difference onto vector position
PVector newVectorPosition = PVector.add(vectorPosition, difference);
vectorPosition = newVectorPosition;
if (getVectorShape() != null)
{
// get current size of vector in local coordinates
PVector oldVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
oldVectorSize = PVector.mult(oldVectorSize, (vectorScaling/100));
// and current centre point of vector
PVector oldCentroid = new PVector(oldVectorSize.x / 2.0, oldVectorSize.y / 2.0);
// get newly scaled size of vector
PVector newVectorSize = new PVector(getVectorShape().width, getVectorShape().height);
newVectorSize = PVector.mult(newVectorSize, (value/100));
// and new centre point of vector
PVector newCentroid = new PVector(newVectorSize.x / 2.0, newVectorSize.y / 2.0);
// difference is current centre minus new centre
PVector difference = PVector.sub(oldCentroid, newCentroid);
// add difference onto vector position
PVector newVectorPosition = PVector.add(vectorPosition, difference);
vectorPosition = newVectorPosition;
}
vectorScaling = value;
@ -610,6 +617,18 @@ void button_mode_sendMachineSpeed()
addToRealtimeCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",END");
}
void button_mode_sendMachineSpeedPersist()
{
NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern("###.##");
addToCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",1,END");
df.applyPattern("###.##");
addToCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",1,END");
}
void button_mode_sendRoveArea()
{
if (isBoxSpecified())

View File

@ -301,7 +301,6 @@ Map<String, Controller> initialiseNumberboxValues(Map<String, Controller> map)
}
else if (MODE_CHANGE_MACHINE_WIDTH.equals(key))
{
println("key:"+key+", width: " + getDisplayMachine().getWidth() + ", multiplied:"+getDisplayMachine().inMM(getDisplayMachine().getWidth()));
n.setValue(getDisplayMachine().inMM(getDisplayMachine().getWidth()));
n.setMin(20);
n.setMultiplier(0.5);
@ -752,10 +751,12 @@ List<String> getControlNamesForDetailPanel()
controlNames.add(MODE_PEN_LIFT_POS_UP);
controlNames.add(MODE_PEN_LIFT_POS_DOWN);
controlNames.add(MODE_SEND_PEN_LIFT_RANGE);
controlNames.add(MODE_SEND_PEN_LIFT_RANGE_PERSIST);
controlNames.add(MODE_CHANGE_MACHINE_MAX_SPEED);
controlNames.add(MODE_CHANGE_MACHINE_ACCELERATION);
controlNames.add(MODE_SEND_MACHINE_SPEED);
controlNames.add(MODE_SEND_MACHINE_SPEED_PERSIST);
controlNames.add(MODE_CHANGE_SERIAL_PORT);
@ -813,8 +814,6 @@ Map<String, String> buildControlLabels()
result.put(MODE_DRAW_TESTPATTERN, "test pattern");
result.put(MODE_PLACE_IMAGE, "place image");
result.put(MODE_LOAD_IMAGE, "Load image file");
result.put(MODE_INC_ROW_SIZE, "Rowsize up");
result.put(MODE_DEC_ROW_SIZE, "Rowsize down");
result.put(MODE_SET_POSITION_HOME, "Set home");
result.put(MODE_RETURN_TO_HOME, "Return to home");
result.put(MODE_INPUT_SINGLE_PIXEL, "Choose pixel");
@ -877,6 +876,7 @@ Map<String, String> buildControlLabels()
result.put(MODE_CHANGE_MACHINE_MAX_SPEED, "Motor max speed");
result.put(MODE_CHANGE_MACHINE_ACCELERATION, "Motor acceleration");
result.put(MODE_SEND_MACHINE_SPEED, "Send speed");
result.put(MODE_SEND_MACHINE_SPEED_PERSIST, "Upload speed");
result.put(MODE_RENDER_VECTORS, "Draw vectors");
result.put(MODE_LOAD_VECTOR_FILE, "Load vector");
result.put(MODE_CHANGE_MIN_VECTOR_LINE_LENGTH, "Shortest vector");
@ -900,7 +900,8 @@ Map<String, String> buildControlLabels()
result.put(MODE_PEN_LIFT_DOWN, "Pen drop");
result.put(MODE_PEN_LIFT_POS_UP, "Pen up position");
result.put(MODE_PEN_LIFT_POS_DOWN, "Pen down position");
result.put(MODE_SEND_PEN_LIFT_RANGE, "Send lift range");
result.put(MODE_SEND_PEN_LIFT_RANGE, "Test lift range");
result.put(MODE_SEND_PEN_LIFT_RANGE_PERSIST, "Upload lift range");
result.put(MODE_SEND_ROVE_AREA, "Send Roving Area");
result.put(MODE_SEND_START_TEXT, "Start text at point");
@ -952,8 +953,6 @@ Set<String> buildControlNames()
result.add(MODE_DRAW_TESTPATTERN);
result.add(MODE_PLACE_IMAGE);
result.add(MODE_LOAD_IMAGE);
result.add(MODE_INC_ROW_SIZE);
result.add(MODE_DEC_ROW_SIZE);
result.add(MODE_SET_POSITION_HOME);
result.add(MODE_RETURN_TO_HOME);
result.add(MODE_INPUT_SINGLE_PIXEL);
@ -1037,6 +1036,7 @@ Set<String> buildControlNames()
result.add(MODE_PEN_LIFT_POS_UP);
result.add(MODE_PEN_LIFT_POS_DOWN);
result.add(MODE_SEND_PEN_LIFT_RANGE);
result.add(MODE_SEND_PEN_LIFT_RANGE_PERSIST);
result.add(MODE_SEND_ROVE_AREA);
result.add(MODE_SEND_START_TEXT);

View File

@ -120,8 +120,15 @@ void sendMachineSpec()
addToCommandQueue(command);
command = CMD_SETMACHINESTEPMULTIPLIER+machineStepMultiplier+",END";
addToCommandQueue(command);
command = CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",END";
command = CMD_SETPENLIFTRANGE+penLiftDownPosition+","+penLiftUpPosition+",1,END";
addToCommandQueue(command);
// speeds
NumberFormat nf = NumberFormat.getNumberInstance(Locale.UK);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern("###.##");
addToCommandQueue(CMD_SETMOTORSPEED+df.format(currentMachineMaxSpeed)+",1,END");
addToCommandQueue(CMD_SETMOTORACCEL+df.format(currentMachineAccel)+",1,END");
}
public PVector getMouseVector()

View File

@ -1,197 +1,234 @@
ControllIO controllIO;
ControllDevice joypad;
//ControllIO controllIO;
//ControllDevice joypad;
//
//ControllButton buttonA;
//ControllButton buttonB;
//ControllButton buttonX;
//ControllButton buttonY;
//ControllButton buttonL;
//ControllButton buttonR;
//ControllButton buttonStart;
//
//ControllCoolieHat dpad;
//
//List<String> devices = new ArrayList<String>(
// Arrays.asList("Controller (Xbox 360 Wireless Receiver for Windows)",
// "Controller (XBOX 360 For Windows)"));
//
//String signalFromGamepad = null;
//
//static final String BUTTON_A_RELEASED = "ButtonAReleased";
//static final String BUTTON_B_RELEASED = "ButtonBReleased";
//static final String BUTTON_L_RELEASED = "ButtonLReleased";
//static final String BUTTON_R_RELEASED = "ButtonRReleased";
//static final String BUTTON_START_RELEASED = "ButtonStartReleased";
//
//void gamepad_init()
//{
// controllIO = ControllIO.getInstance(this);
//
// try
// {
// controllIO.printDevices();
// for (int i = 0; i<devices.size(); i++)
// {
// try
// {
// println("trying " + i + ": " + devices.get(i));
// joypad = controllIO.getDevice(devices.get(i));
// break;
// }
// catch (RuntimeException e)
// {
// println("Requested device (" + devices.get(i) + ") not found.");
// joypad = null;
// }
// }
//
// if (joypad != null)
// {
// joypad.printButtons();
//
// buttonA = joypad.getButton("Button 0");
// buttonB = joypad.getButton("Button 1");
// buttonX = joypad.getButton("Button 2");
// buttonY = joypad.getButton("Button 3");
//
// buttonL = joypad.getButton("Button 4");
// buttonR = joypad.getButton("Button 5");
//
// buttonStart = joypad.getButton("Button 7");
//
// buttonA.plug(this, "buttonARelease", ControllIO.ON_RELEASE);
// buttonB.plug(this, "buttonBRelease", ControllIO.ON_RELEASE);
// buttonX.plug(this, "buttonXPress", ControllIO.ON_PRESS);
// buttonX.plug(this, "buttonXRelease", ControllIO.ON_RELEASE);
// buttonY.plug(this, "buttonYRelease", ControllIO.ON_RELEASE);
//
// buttonL.plug(this, "buttonLRelease", ControllIO.ON_RELEASE);
// buttonR.plug(this, "buttonRRelease", ControllIO.ON_RELEASE);
//
// buttonStart.plug(this, "buttonStartRelease", ControllIO.ON_RELEASE);
//
// dpad = joypad.getCoolieHat(10);
// dpad.setMultiplier(4);
// dpad.plug(this, "dpadPress", ControllIO.ON_PRESS);
// }
// }
// catch (RuntimeException e)
// {
// println("Exception occurred while initialising gamepad: " + e.getMessage());
// }
//}
//
//public void buttonARelease()
//{
// signalFromGamepad = BUTTON_A_RELEASED;
//}
//public void buttonBRelease()
//{
// signalFromGamepad = BUTTON_B_RELEASED;
//}
//public void buttonLRelease()
//{
// signalFromGamepad = BUTTON_L_RELEASED;
//}
//public void buttonRRelease()
//{
// signalFromGamepad = BUTTON_R_RELEASED;
//}
//public void buttonStartRelease()
//{
// signalFromGamepad = BUTTON_START_RELEASED;
//}
//
//void buttonXPress()
//{
// drawingLiveVideo = true;
//}
//void buttonXRelease()
//{
// drawingLiveVideo = false;
//}
//void buttonYRelease()
//{
// flipWebcamImage = !flipWebcamImage;
//}
//
//void dpadPress(float x, float y)
//{
// float val = dpad.getValue();
// if (val == 6.0)
// {
// liveSimplification--;
// if (liveSimplification < LIVE_SIMPLIFICATION_MIN)
// liveSimplification = LIVE_SIMPLIFICATION_MIN;
// }
// else if (val == 2.0)
// {
// liveSimplification++;
// if (liveSimplification > LIVE_SIMPLIFICATION_MAX)
// liveSimplification = LIVE_SIMPLIFICATION_MAX;
// }
// if (val == 8.0) // left
// {
// pathLengthHighPassCutoff--;
// if (pathLengthHighPassCutoff < PATH_LENGTH_HIGHPASS_CUTOFF_MIN)
// pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MIN;
// }
// else if (val == 4.0) // right
// {
// pathLengthHighPassCutoff++;
// if (pathLengthHighPassCutoff > PATH_LENGTH_HIGHPASS_CUTOFF_MAX)
// pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MAX;
// }
//
// Numberbox n = (Numberbox) getAllControls().get(MODE_LIVE_SIMPLIFICATION_VALUE);
// n.setValue(liveSimplification);
// n.update();
//
// n = (Numberbox) getAllControls().get(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF);
// n.setValue(pathLengthHighPassCutoff);
// n.update();
//
//}
//
//void processGamepadInput()
//{
// if (signalFromGamepad != null)
// {
// println("Signal from gamepad: " + signalFromGamepad);
// if (signalFromGamepad == BUTTON_A_RELEASED)
// {
// if (captureShape == null && !confirmedDraw)
// button_mode_liveCaptureFromLive();
// else if (captureShape != null && !confirmedDraw)
// button_mode_liveClearCapture();
// else if (captureShape != null && confirmedDraw)
// {
// button_mode_liveClearCapture();
// button_mode_clearQueue();
// confirmedDraw = false;
// }
// }
// else if (signalFromGamepad == BUTTON_B_RELEASED)
// {
// if (captureShape != null && !confirmedDraw)
// button_mode_liveConfirmDraw();
// }
// else if (signalFromGamepad == BUTTON_L_RELEASED)
// {
// commandQueueRunning = !commandQueueRunning;
// }
// else if (signalFromGamepad == BUTTON_R_RELEASED)
// {
// }
// else if (signalFromGamepad == BUTTON_START_RELEASED)
// {
// preLoadCommandQueue();
// button_mode_setPositionHome();
// }
//
//
// // clear the signal
// signalFromGamepad = null;
// }
//
//}
ControllButton buttonA;
ControllButton buttonB;
ControllButton buttonX;
ControllButton buttonY;
ControllButton buttonL;
ControllButton buttonR;
ControllButton buttonStart;
ControllCoolieHat dpad;
List<String> devices = new ArrayList<String>(
Arrays.asList("Controller (Xbox 360 Wireless Receiver for Windows)",
"Controller (XBOX 360 For Windows)"));
String signalFromGamepad = null;
static final String BUTTON_A_RELEASED = "ButtonAReleased";
static final String BUTTON_B_RELEASED = "ButtonBReleased";
static final String BUTTON_L_RELEASED = "ButtonLReleased";
static final String BUTTON_R_RELEASED = "ButtonRReleased";
static final String BUTTON_START_RELEASED = "ButtonStartReleased";
void gamepad_init()
{
controllIO = ControllIO.getInstance(this);
try
{
controllIO.printDevices();
for (int i = 0; i<devices.size(); i++)
{
try
{
println("trying " + i + ": " + devices.get(i));
joypad = controllIO.getDevice(devices.get(i));
break;
}
catch (RuntimeException e)
{
println("Requested device (" + devices.get(i) + ") not found.");
joypad = null;
}
}
if (joypad != null)
{
joypad.printButtons();
buttonA = joypad.getButton("Button 0");
buttonB = joypad.getButton("Button 1");
buttonX = joypad.getButton("Button 2");
buttonY = joypad.getButton("Button 3");
buttonL = joypad.getButton("Button 4");
buttonR = joypad.getButton("Button 5");
buttonStart = joypad.getButton("Button 7");
buttonA.plug(this, "buttonARelease", ControllIO.ON_RELEASE);
buttonB.plug(this, "buttonBRelease", ControllIO.ON_RELEASE);
buttonX.plug(this, "buttonXPress", ControllIO.ON_PRESS);
buttonX.plug(this, "buttonXRelease", ControllIO.ON_RELEASE);
buttonY.plug(this, "buttonYRelease", ControllIO.ON_RELEASE);
buttonL.plug(this, "buttonLRelease", ControllIO.ON_RELEASE);
buttonR.plug(this, "buttonRRelease", ControllIO.ON_RELEASE);
buttonStart.plug(this, "buttonStartRelease", ControllIO.ON_RELEASE);
dpad = joypad.getCoolieHat(10);
dpad.setMultiplier(4);
dpad.plug(this, "dpadPress", ControllIO.ON_PRESS);
}
}
catch (RuntimeException e)
{
println("Exception occurred while initialising gamepad: " + e.getMessage());
}
}
public void buttonARelease()
{
signalFromGamepad = BUTTON_A_RELEASED;
}
public void buttonBRelease()
{
signalFromGamepad = BUTTON_B_RELEASED;
}
public void buttonLRelease()
{
signalFromGamepad = BUTTON_L_RELEASED;
}
public void buttonRRelease()
{
signalFromGamepad = BUTTON_R_RELEASED;
}
public void buttonStartRelease()
{
signalFromGamepad = BUTTON_START_RELEASED;
}
void buttonXPress()
{
drawingLiveVideo = true;
}
void buttonXRelease()
{
drawingLiveVideo = false;
}
void buttonYRelease()
{
flipWebcamImage = !flipWebcamImage;
}
void dpadPress(float x, float y)
{
float val = dpad.getValue();
if (val == 6.0)
{
liveSimplification--;
if (liveSimplification < LIVE_SIMPLIFICATION_MIN)
liveSimplification = LIVE_SIMPLIFICATION_MIN;
}
else if (val == 2.0)
{
liveSimplification++;
if (liveSimplification > LIVE_SIMPLIFICATION_MAX)
liveSimplification = LIVE_SIMPLIFICATION_MAX;
}
if (val == 8.0) // left
{
pathLengthHighPassCutoff--;
if (pathLengthHighPassCutoff < PATH_LENGTH_HIGHPASS_CUTOFF_MIN)
pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MIN;
}
else if (val == 4.0) // right
{
pathLengthHighPassCutoff++;
if (pathLengthHighPassCutoff > PATH_LENGTH_HIGHPASS_CUTOFF_MAX)
pathLengthHighPassCutoff = PATH_LENGTH_HIGHPASS_CUTOFF_MAX;
}
Numberbox n = (Numberbox) getAllControls().get(MODE_LIVE_SIMPLIFICATION_VALUE);
n.setValue(liveSimplification);
n.update();
n = (Numberbox) getAllControls().get(MODE_VECTOR_PATH_LENGTH_HIGHPASS_CUTOFF);
n.setValue(pathLengthHighPassCutoff);
n.update();
}
void processGamepadInput()
{
if (signalFromGamepad != null)
{
println("Signal from gamepad: " + signalFromGamepad);
if (signalFromGamepad == BUTTON_A_RELEASED)
{
if (captureShape == null && !confirmedDraw)
button_mode_liveCaptureFromLive();
else if (captureShape != null && !confirmedDraw)
button_mode_liveClearCapture();
else if (captureShape != null && confirmedDraw)
{
button_mode_liveClearCapture();
button_mode_clearQueue();
confirmedDraw = false;
}
}
else if (signalFromGamepad == BUTTON_B_RELEASED)
{
if (captureShape != null && !confirmedDraw)
button_mode_liveConfirmDraw();
}
else if (signalFromGamepad == BUTTON_L_RELEASED)
{
commandQueueRunning = !commandQueueRunning;
}
else if (signalFromGamepad == BUTTON_R_RELEASED)
{
}
else if (signalFromGamepad == BUTTON_START_RELEASED)
{
preLoadCommandQueue();
button_mode_setPositionHome();
}
// clear the signal
signalFromGamepad = null;
}
}
//void displayGamepadOverlay()
//{
// textSize(40);
// fill(255);
//
// if (captureShape == null)
// {
// image(aButtonImage, width-400, height-180, 128, 128);
// text("SNAP!", width-400, height-200);
//
// textSize(30);
// image(dpadYImage, width-600, height-180, 128, 128);
// text("Simplify", width-600, height-200);
//
// image(dpadXImage, width-600, height-400, 128, 128);
// text("Filter short paths", width-600, height-420);
// }
// else
// {
// if (confirmedDraw)
// {
// image(aButtonImage, width-400, height-180, 128, 128);
// text("CANCEL!", width-385, height-200);
// }
// else
// {
// image(aButtonImage, width-400, height-180, 128, 128);
// text("BACK", width-400, height-200);
// image(bButtonImage, width-190, height-180, 128, 128);
// text("DRAW!", width-180, height-200);
// }
// }
//
//
// textSize(12);
//}

View File

@ -8,8 +8,6 @@ import org.apache.batik.svggen.font.table.*;
import org.apache.batik.svggen.font.*;
import java.util.zip.CRC32;
import procontroll.*;
//import net.java.games.input.*;
// for OSX
import java.text.*;
@ -198,8 +196,6 @@ static final String MODE_RENDER_PIXEL_DIALOG = "button_mode_drawPixelsDialog";
static final String MODE_INPUT_ROW_START = "button_mode_inputRowStart";
static final String MODE_INPUT_ROW_END = "button_mode_inputRowEnd";
static final String MODE_DRAW_TESTPATTERN = "button_mode_drawTestPattern";
static final String MODE_INC_ROW_SIZE = "button_mode_incRowSize";
static final String MODE_DEC_ROW_SIZE = "button_mode_decRowSize";
static final String MODE_DRAW_GRID = "button_mode_drawGrid";
static final String MODE_PLACE_IMAGE = "button_mode_placeImage";
static final String MODE_LOAD_IMAGE = "button_mode_loadImage";
@ -276,6 +272,7 @@ static final String MODE_CHANGE_PEN_TEST_INCREMENT_SIZE = "numberbox_mode_change
static final String MODE_CHANGE_MACHINE_MAX_SPEED = "numberbox_mode_changeMachineMaxSpeed";
static final String MODE_CHANGE_MACHINE_ACCELERATION = "numberbox_mode_changeMachineAcceleration";
static final String MODE_SEND_MACHINE_SPEED = "button_mode_sendMachineSpeed";
static final String MODE_SEND_MACHINE_SPEED_PERSIST = "button_mode_sendMachineSpeedPersist";
static final String MODE_RENDER_VECTORS = "button_mode_renderVectors";
static final String MODE_LOAD_VECTOR_FILE = "button_mode_loadVectorFile";
@ -296,6 +293,7 @@ static final String MODE_PEN_LIFT_DOWN = "button_mode_penDown";
static final String MODE_PEN_LIFT_POS_UP = "numberbox_mode_penUpPos";
static final String MODE_PEN_LIFT_POS_DOWN = "numberbox_mode_penDownPos";
static final String MODE_SEND_PEN_LIFT_RANGE = "button_mode_sendPenliftRange";
static final String MODE_SEND_PEN_LIFT_RANGE_PERSIST = "button_mode_sendPenliftRangePersist";
static final String MODE_SEND_ROVE_AREA = "button_mode_sendRoveArea";
static final String MODE_SEND_START_TEXT = "toggle_mode_sendStartText";
@ -458,6 +456,7 @@ boolean overwriteExistingStoreFile = true;
public static Console console;
public boolean useWindowedConsole = false;
static boolean webcamEnabled = false;
static boolean drawingLiveVideo = false;
static boolean drawingWebcamShape = true;
static boolean flipWebcamImage = true;
@ -491,14 +490,14 @@ String shapeSavePath = "../../savedcaptures/";
String shapeSavePrefix = "shape-";
String shapeSaveExtension = ".svg";
boolean displayGamepadOverlay = true;
PImage yButtonImage = null;
PImage xButtonImage = null;
PImage aButtonImage = null;
PImage bButtonImage = null;
PImage dpadXImage = null;
PImage dpadYImage = null;
//boolean displayGamepadOverlay = false;
//PImage yButtonImage = null;
//PImage xButtonImage = null;
//PImage aButtonImage = null;
//PImage bButtonImage = null;
//
//PImage dpadXImage = null;
//PImage dpadYImage = null;
void setup()
{
@ -571,11 +570,20 @@ void setup()
addEventListeners();
gamepad_init();
String[] cameras = Capture.list();
if (cameras.length > 0) {
liveCamera = new Capture(this, 640, 480, cameras[0]);
//liveCamera.start();
//gamepad_init();
try
{
String[] cameras = Capture.list();
if (cameras.length > 0) {
liveCamera = new Capture(this, 640, 480, cameras[0]);
//liveCamera.start();
webcamEnabled = true;
}
}
catch (Exception e)
{
println("Exception occurred trying to look for attached webcams. Webcam will not be used. " + e.getMessage());
webcamEnabled = false;
}
blob_detector = new BlobDetector( 640, 480);
@ -835,12 +843,19 @@ void drawWebcamPage()
strokeWeight(3);
stroke(150);
noFill();
getDisplayMachine().drawForWebcam();
stroke(255, 0, 0);
for (Panel panel : getPanelsForTab(TAB_NAME_WEBCAM))
if (webcamEnabled)
{
panel.draw();
getDisplayMachine().drawForWebcam();
stroke(255, 0, 0);
for (Panel panel : getPanelsForTab(TAB_NAME_WEBCAM))
{
panel.draw();
}
}
else
{
text("No camera attached.", 250, 100);
}
if (displayingInfoTextOnInputPage)
@ -848,10 +863,10 @@ void drawWebcamPage()
drawStatusText((int)statusTextPosition.x, (int)statusTextPosition.y);
showCommandQueue((int) width-200, 20);
processGamepadInput();
if (displayGamepadOverlay)
displayGamepadOverlay();
// processGamepadInput();
//
// if (displayGamepadOverlay)
// displayGamepadOverlay();
}
@ -887,42 +902,7 @@ void drawImageLoadPage()
drawImagePage();
}
void displayGamepadOverlay()
{
textSize(40);
fill(255);
if (captureShape == null)
{
image(aButtonImage, width-400, height-180, 128, 128);
text("SNAP!", width-400, height-200);
textSize(30);
image(dpadYImage, width-600, height-180, 128, 128);
text("Simplify", width-600, height-200);
image(dpadXImage, width-600, height-400, 128, 128);
text("Filter short paths", width-600, height-420);
}
else
{
if (confirmedDraw)
{
image(aButtonImage, width-400, height-180, 128, 128);
text("CANCEL!", width-385, height-200);
}
else
{
image(aButtonImage, width-400, height-180, 128, 128);
text("BACK", width-400, height-200);
image(bButtonImage, width-190, height-180, 128, 128);
text("DRAW!", width-180, height-200);
}
}
textSize(12);
}
void drawMoveImageOutline()
{
@ -2455,6 +2435,11 @@ void serialEvent(Serial myPort)
readStepsPerRev(incoming);
else if (incoming.startsWith("PGSTEPMULTIPLIER"))
readStepMultiplier(incoming);
else if (incoming.startsWith("PGLIFT"))
readPenLiftRange(incoming);
else if (incoming.startsWith("PGSPEED"))
readMachineSpeed(incoming);
else if ("RESEND".equals(incoming))
resendLastCommand();
else if ("DRAWING".equals(incoming))
@ -2574,6 +2559,36 @@ void readMachineName(String sync)
}
}
void readMachineSpeed(String in)
{
String[] splitted = split(in, ",");
if (splitted.length == 4)
{
String speed = splitted[1];
String accel = splitted[2];
currentMachineMaxSpeed = Float.parseFloat(speed);
currentMachineAccel = Float.parseFloat(accel);
updateNumberboxValues();
}
}
void readPenLiftRange(String in)
{
String[] splitted = split(in, ",");
if (splitted.length == 4)
{
String downPos = splitted[1];
String upPos = splitted[2];
penLiftDownPosition = Integer.parseInt(downPos);
penLiftUpPosition = Integer.parseInt(upPos);
updateNumberboxValues();
}
}
void resendLastCommand()
{
println("Re-sending command: " + lastCommand);
@ -3026,24 +3041,24 @@ void initLogging()
}
void initImages()
{
try
{
yButtonImage = loadImage("y.png");
xButtonImage = loadImage("x.png");
aButtonImage = loadImage("a.png");
bButtonImage = loadImage("b.png");
dpadXImage = loadImage("dpadlr.png");
dpadYImage = loadImage("dpadud.png");
}
catch (Exception e)
{
yButtonImage = makeColourImage(64,64,color(180,180,0));
xButtonImage = makeColourImage(64,64,color(0,0,180));
aButtonImage = makeColourImage(64,64,color(0,180,0));
bButtonImage = makeColourImage(64,64,color(180,0,0));
}
// try
// {
// yButtonImage = loadImage("y.png");
// xButtonImage = loadImage("x.png");
// aButtonImage = loadImage("a.png");
// bButtonImage = loadImage("b.png");
// dpadXImage = loadImage("dpadlr.png");
// dpadYImage = loadImage("dpadud.png");
// }
// catch (Exception e)
// {
// yButtonImage = makeColourImage(64,64,color(180,180,0));
// xButtonImage = makeColourImage(64,64,color(0,0,180));
// aButtonImage = makeColourImage(64,64,color(0,180,0));
// bButtonImage = makeColourImage(64,64,color(180,0,0));
// }
}
PImage makeColourImage(int w, int h, int colour)
{
PImage img = createImage(w,h,RGB);