Commit 87f81bfe authored by Jonathan Flat's avatar Jonathan Flat
Browse files

Added enabled/disabled button and comments.

parent ea19ea92
......@@ -328,14 +328,17 @@ class FlyerLayoutControlWindow extends UIWindow {
/* Window for the slider that modifies script rate generation. */
class ScriptRateWindow extends UIWindow {
final static int WIDTH = 200;
final static int HEIGHT = 60;
final static int HEIGHT = 85;
final static int BORDER = 4;
private UISlider rateSlider;
private UIButton enableButton;
ScriptRateWindow(UI ui) {
super(ui, "Script Update Rate (Hz)", BORDER, 100, WIDTH, HEIGHT);
makeRateSlider();
rateSlider.setVisible(true);
makeEnableButton();
enableButton.setVisible(true);
}
private void makeRateSlider() {
......@@ -352,6 +355,18 @@ class ScriptRateWindow extends UIWindow {
.addToContainer(this);
}
private void makeEnableButton() {
this.enableButton = new UIButton(25, 55, width-50, 20) {
public void onToggle(boolean enabled) {
pengine.setGeneratorEnabled(enabled);
}
};
this.enableButton.setInactiveLabel("Disabled");
this.enableButton.setActiveLabel("Enabled");
this.enableButton.addToContainer(this);
this.enableButton.setDescription("Enable/disable script generation.");
}
}
......
......@@ -255,6 +255,22 @@ public abstract class FlightEngine implements FlightPlaylist {
}
}
/**
* Sets the script generation rate.
* @param frequency The frequency, in Hz, to generate scripts.
*/
public void setGeneratorRate(Double frequency) {
generator.setRate(frequency);
}
/**
* Turns script generation on or off.
* @param enabled True to turn generator on, false to turn off.
*/
public void setGeneratorEnabled(boolean enabled) {
generator.setEnabled(enabled);
}
// PRIVATE FUNCTIONS
/* Adds patterns to the pattern list passed as parameter.
......@@ -324,12 +340,6 @@ public abstract class FlightEngine implements FlightPlaylist {
}
}
/* Called in the Processing code to set the generator
frequency through a UI Slider. */
public void setGeneratorRate(Double frequency) {
generator.setRate(frequency);
}
}
......@@ -50,6 +50,7 @@ public class Generator extends LXOutput implements Geometry {
Color prev_rleds[][] = new Color[3][76]; /* Previous right led colors as Color objects. */
Color prev_body[] = new Color[76]; /* Previous body led colors as Color object. */
boolean force_send; /* True forces potentially duplicate commands to be sent. */
boolean enabled; /* Linked to UI button to turn generator on/off. */
static final String LEFT_WING_POS = "wing_angle(LEFT, %s)";
static final String RIGHT_WING_POS = "wing_angle(RIGHT, %s)";
......@@ -68,6 +69,7 @@ public class Generator extends LXOutput implements Geometry {
this.tokens = 0;
this.rate = 1.0;
this.period = 1000000000;
this.enabled = false;
this.force_send = true;
}
......@@ -99,11 +101,6 @@ public class Generator extends LXOutput implements Geometry {
wing_angle(LEFT|RIGHT, angle)
*/
/*
* TODO handle the case where only one parameter has changed
* Perhaps that should be handled by engine
*/
private ArrayList<String> generateCommands(int flyerIndex) {
/*
* String s = "hello %s!";
......@@ -181,10 +178,16 @@ public class Generator extends LXOutput implements Geometry {
this.period = (long)(1000000000.0 / frequency);
}
protected void setEnabled(boolean enabled) {
this.force_send = enabled;
this.enabled = enabled;
}
@Override
protected void onSend(int[] colors, double brightness) {
// super.onSend(colors, brightness);
// super.onSend(colors, brightness);
if (!enabled) return;
long waitTime = Duration.between(timer, Instant.now()).toNanos();
if (waitTime > period) {
if (tokens < MAX_TOKENS) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment