Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip A Levis
EE185
Commits
87f81bfe
Commit
87f81bfe
authored
Feb 09, 2021
by
Jonathan Flat
Browse files
Added enabled/disabled button and comments.
parent
ea19ea92
Changes
3
Hide whitespace changes
Inline
Side-by-side
software/FlightGui/UIComponents.pde
View file @
87f81bfe
...
...
@@ -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."
);
}
}
...
...
software/ui/src/engine/FlightEngine.java
View file @
87f81bfe
...
...
@@ -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
);
}
}
software/ui/src/engine/Generator.java
View file @
87f81bfe
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment