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

View File

@ -58,7 +58,7 @@ import java.lang.reflect.Method;
int majorVersionNo = 2;
int minorVersionNo = 4;
int buildNo = 1;
int buildNo = 2;
String programTitle = "Polargraph Controller v" + majorVersionNo + "." + minorVersionNo + " build " + buildNo;
ControlP5 cp5;
@ -573,7 +573,6 @@ void setup()
println("Serial ports available on your machine:");
println(serialPorts);
// println("getSerialPortNumber()"+getSerialPortNumber());
if (getSerialPortNumber() >= 0)
{
println("About to connect to serial port in slot " + getSerialPortNumber());
@ -684,17 +683,28 @@ void windowResized()
windowWidth = frame.getWidth();
windowHeight = frame.getHeight();
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())
{
Panel p = getPanels().get(key);
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
// How does this work?
cp5.setGraphics(this,0,0);
loop();
}
void draw()
{
@ -997,7 +1007,9 @@ void drawMoveImageOutline()
PVector offsetMouseVector = PVector.sub(getDisplayMachine().scaleToDisplayMachine(getMouseVector()), centroid);
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)
{
@ -3086,21 +3098,19 @@ void loadFromPropertiesFile()
if (getVectorFilename() != null)
{
RShape shape = null;
try
{
// test if file exists
File f = new File(getVectorFilename());
if (f.isFile()) {
shape = RG.loadShape(getVectorFilename());
}
catch (Exception e)
{
shape = null;
else {
println("Tried to load vector file (" + getVectorFilename() + ") but I couldn't find it.");
}
if (shape != null)
{
if (shape != null) {
setVectorShape(shape);
}
else
{
else {
println("File not found (" + getVectorFilename() + ")");
}
}