Switch
Description
Switch
represents a 2 or 3-position switch.
Usage
erbui
module Example {
control mode Switch { // 1.
position 19.2mm, 111mm // 2.
style on_off_on // 3.
label "ARM" // 4.
rotation 90°ccw // 5.
pins Pin1, Pin2 // 6.
}
}
Creates a switch control with name
mode
,Sets the control position on the front panel,
Sets the optional style of the control,
Sets the optional label for the control, using its default theme positioning,
Sets the optional rotation for the switch,
Sets the optional physical board pins to use, one for each extreme position. If not set, the system will choose them automatically.
Dailywell toggle switches photo are from the Thonk shop.
c++
Switch
is a type that abstracts a physical button block.
struct Example
{
ExampleUi ui;
void process () {
if (ui.mode.position_first ()) { // 1.
...
} else if (ui.mode.position_center ()) { // 2.
...
} else if (ui.mode.position_last ()) { // 3.
...
}
}
}
Checks if the switch position is on the left,
Checks if the switch position is in the middle,
Checks if the switch position is on the right.
erbui
Control Reference
control
definition
control <name> Switch { ... }
Where <name>
is the name of the control.
More details can be found in control
documentation.
position
property
position <x>, <y>
Sets the position of the control, where the axis origin is the top-left corner.
The x
axis is oriented from left to right, and the y
axis is oriented from top to bottom.
The position component values are expressed with their unit, either mm
or hp
.
Example:
position 2hp, 15mm
More details can be found in position
documentation.
style
optional property
style <keywords>
Where <keywords>
is one of:
on_on
2-position toggle switch (this is the default if not specified),on_off_on
3-position toggle switch.
More details can be found in style
documentation.
label
optional property
label "<text>"
Where <text>
is the text displayed.
More details can be found in label
documentation.
rotation
optional property
rotation <angle>
Where <angle>
is the angle to rotate the element.
The rotation
value only supports quarter turns, so that <angle>
can only be a multiple of 90.
<angle>
supported units are:
°ccw
(Counter Clockwise),°ccw
(Clockwise),°
(Clockwise, as the position y-axis goes from top to bottom).
More details can be found in rotation
documentation.
c++
Member Functions Synopsys
Name |
Synopsys |
---|---|
|
Returns true iff the switch position is first |
|
Returns true iff the switch position is centered |
|
Returns true iff the switch position is last |
|
Returns the switch position |
c++
Member Functions
position_first
bool position_first () const;
Returns true if and only if the switch is in the first position.
The first position depends on the rotation. When no rotation is applied, it corresponds to the left one.
After the switch has finished bouncing, it will take 7 process cycles, so 7ms if the buffer size is 48 samples, for the change to be detected.
position_center
bool position_center () const;
Returns true if and only if the switch is in the center position.
Even if a 2-position switch is used, the Center
position needs to be taken into account
as it will transiently transition to it when going from left to right or right to left.
position_last
bool position_last () const;
Returns true if and only if the switch is in the last position.
The first position depends on the rotation. When no rotation is applied, it corresponds to the right one.
After the switch has finished bouncing, it will take 7 process cycles, so 7ms if the buffer size is 48 samples, for the change to be detected.
operator Position
operator Position () const;
Returns the switch position, one of the following value:
Switch::Position::Out0
when the switch is on the left,Switch::Position::Center
when the switch is centered,Switch::Position::Out1
when the switch is on the right.
After the switch has finished bouncing, it will take 7 process cycles, so 7ms if the buffer size is 48 samples, for the change to be detected.
Even if a 2-position switch is used, the Center
position needs to be taken into account
as it will transiently transition to it when going from left to right or right to left.