#14 converted serial port radio button to dropdown control - still has debug code in place because I don't have multiple serial ports to test with on home pc.

This commit is contained in:
Sandy Noble 2017-04-17 22:33:57 +01:00
parent a7f37d8553
commit 7da0e7e378
2 changed files with 48 additions and 31 deletions

View File

@ -1,7 +1,7 @@
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
Class and controllers on the "serial port" subwindow Class and controllers on the "serial port" subwindow
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) { ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName ); final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor ); final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
@ -28,36 +28,43 @@ ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int t
} }
catch(Exception e) { catch(Exception e) {
} }
// set up controls ScrollableList sl = p.cp5().addScrollableList("dropdown_serialPort")
RadioButton r = p.cp5().addRadioButton("radio_serialPort")
.setPosition(10, 10) .setPosition(10, 10)
.setSize(15, 15) .setSize(150, 100)
.setSpacingRow(5) .setBarHeight(20)
.plugTo(this, "radio_serialPort"); .setItemHeight(20)
.plugTo(this, "dropdown_serialPort");
r.addItem("No serial connection", -1); sl.addItem("No serial connection", -1);
String[] ports = Serial.list();
String[] ports = {"a", "b", "c", "d", "e", "f", "g", "h"};
//Serial.list();
for (int i = 0; i < ports.length; i++) { for (int i = 0; i < ports.length; i++) {
println("Adding " + ports[i]); println("Adding " + ports[i]);
r.addItem(ports[i], i); sl.addItem(ports[i], i);
} }
int portNo = getSerialPortNumber(); int portNo = getSerialPortNumber();
if (portNo >= 0 && portNo < ports.length) println("portNo: " + portNo);
r.activate(ports[portNo]); if (portNo < 0 || portNo >= ports.length)
else portNo = -1;
r.activate("No serial connection");
// set the value of the actual control
sl.setValue(portNo);
sl.setOpen(false);
return p; return p;
} }
void radio_serialPort(int newSerialPort) void dropdown_serialPort(int newSerialPort)
{ {
println("In radio_serialPort"); println("In dropdown_serialPort");
if (newSerialPort == -2) if (newSerialPort == -2)
{ {
} }

View File

@ -58,7 +58,7 @@ import java.lang.reflect.Method;
int majorVersionNo = 2; int majorVersionNo = 2;
int minorVersionNo = 4; int minorVersionNo = 4;
int buildNo = 1; int buildNo = 2;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo; String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
ControlP5 cp5; ControlP5 cp5;
@ -573,7 +573,6 @@ void setup()
println("Serial ports available on your machine:"); println("Serial ports available on your machine:");
println(serialPorts); println(serialPorts);
// println("getSerialPortNumber()"+getSerialPortNumber());
if (getSerialPortNumber() >= 0) if (getSerialPortNumber() >= 0)
{ {
println("About to connect to serial port in slot " + getSerialPortNumber()); println("About to connect to serial port in slot " + getSerialPortNumber());
@ -684,17 +683,28 @@ void windowResized()
windowWidth = frame.getWidth(); windowWidth = frame.getWidth();
windowHeight = frame.getHeight(); windowHeight = frame.getHeight();
println("New window size: " + windowWidth + " x " + windowHeight); println("New window size: " + windowWidth + " x " + windowHeight);
if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
println("Max");
frame.setExtendedState(0);
frame.setSize(windowWidth, windowHeight);
}
for (String key : getPanels().keySet()) for (String key : getPanels().keySet())
{ {
Panel p = getPanels().get(key); Panel p = getPanels().get(key);
p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2)); p.setSizeByHeight(windowHeight - p.getOutline().getTop() - (DEFAULT_CONTROL_SIZE.y*2));
if (debugPanels) {
println("Resize " + key + " to be " + p.getOutline().getWidth() + "px across, " + p.getOutline().getHeight() + "px tall");
}
} }
// Required to tell CP5 to be able to use the new sized window // Required to tell CP5 to be able to use the new sized window
// How does this work?
cp5.setGraphics(this,0,0); cp5.setGraphics(this,0,0);
loop(); loop();
} }
void draw() void draw()
{ {
@ -997,7 +1007,9 @@ void drawMoveImageOutline()
PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid); PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid);
if (pointPaths != null) if (pointPaths != null)
{ {
for (int i = 0; i<pointPaths.length; i++) int increment = round((pointPaths.length/10.0)+0.5);
println(increment);
for (int i = 0; i<pointPaths.length; i+=increment)
{ {
if (pointPaths[i] != null) if (pointPaths[i] != null)
{ {
@ -3086,21 +3098,19 @@ void loadFromPropertiesFile()
if (getVectorFilename() != null) if (getVectorFilename() != null)
{ {
RShape shape = null; RShape shape = null;
try // test if file exists
{ File f = new File(getVectorFilename());
if (f.isFile()) {
shape = RG.loadShape(getVectorFilename()); shape = RG.loadShape(getVectorFilename());
} }
catch (Exception e) else {
{ println("Tried to load vector file (" + getVectorFilename() + ") but I couldn't find it.");
shape = null;
} }
if (shape != null) if (shape != null) {
{
setVectorShape(shape); setVectorShape(shape);
} }
else else {
{
println("File not found (" + getVectorFilename() + ")"); println("File not found (" + getVectorFilename() + ")");
} }
} }