commit 4664d3520ccbc9a97755afef33a9214a13931037
parent e756e94ffbd6d6e98d39d93e0f359be0ecacb0c8
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 16 Sep 2018 23:56:42 -0400
Add latch button to SWITCH, makes the switch togglable.
Diffstat:
4 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/res-src/Switch-src.svg b/res-src/Switch-src.svg
@@ -29,6 +29,16 @@
</g>
</symbol>
+ <symbol id="button-small" viewBox="0 0 9px 9px">
+ <g transform="translate(4.5 4.5)">
+ <circle cx="0" cy="0" r="4.1" stroke-width="1" stroke="#00f" fill="#f00" />
+ </g>
+ </symbol>
+
+ <symbol id="light-small" viewBox="0 0 6.4px 6.4px">
+ <rect width="6.4" height="6.4" fill="#0f0" />
+ </symbol>
+
<symbol id="input" viewBox="0 0 24px 24px">
<g transform="translate(12 12)">
<circle cx="0" cy="0" r="5" stroke-width="1" stroke="#0f0" fill="#0f0" />
@@ -55,7 +65,7 @@
<!-- <rect width="45" height="7" fill="#0f0" transform="translate(0 318)" /> -->
<g transform="rotate(-90) translate(-376 13)">
- <text class="title" font-size="7pt" letter-spacing="2.5px">SWITCH</text>
+ <text class="title" font-size="7pt" letter-spacing="2.5px">SWTCH</text>
<g transform="translate(0 12)">
<text class="brand" font-size="7pt" letter-spacing="2px">BGA</text>
<rect width="3.0" height="3" fill="#ddd" transform="translate(11.5 -5)" />
@@ -70,7 +80,13 @@
<text font-size="5pt" letter-spacing="2px" transform="translate(5.5 58)">GATE</text>
</g>
- <g transform="translate(0 69)">
+ <g transform="translate(4 66)">
+ <use id="LATCH_LIGHT" xlink:href="#light-small" transform="translate(0 0.5)" />
+ <text font-size="5pt" letter-spacing="1px" transform="translate(8 6)">LTCH</text>
+ <use id="LATCH_PARAM" xlink:href="#button-small" transform="translate(29 -1)" />
+ </g>
+
+ <g transform="translate(0 79)">
<g transform="translate(5.5 0)">
<rect width="34" height="10" fill="#fafafa" transform="translate(0 29)" />
<rect width="34" height="35" rx="5" fill="#fafafa" />
@@ -91,7 +107,7 @@
</g>
</g>
- <g transform="translate(0 188)">
+ <g transform="translate(0 196)">
<g transform="translate(5.5 0)">
<rect width="34" height="10" fill="#fafafa" transform="translate(0 29)" />
<rect width="34" height="35" rx="5" fill="#fafafa" />
diff --git a/res/Switch.svg b/res/Switch.svg
Binary files differ.
diff --git a/src/Switch.cpp b/src/Switch.cpp
@@ -6,8 +6,20 @@ void bogaudio::Switch::onReset() {
}
void bogaudio::Switch::step() {
- _trigger.process(params[GATE_PARAM].value + inputs[GATE_INPUT].value);
- if (_trigger.isHigh()) {
+ bool latched = params[LATCH_PARAM].value > 0.5f;
+ lights[LATCH_LIGHT].value = latched;
+
+ bool triggered = _trigger.process(params[GATE_PARAM].value + inputs[GATE_INPUT].value);
+ if (latched) {
+ if (triggered) {
+ _latchedHigh = !_latchedHigh;
+ }
+ }
+ else {
+ _latchedHigh = false;
+ }
+
+ if (_latchedHigh || _trigger.isHigh()) {
outputs[OUT1_OUTPUT].value = inputs[HIGH1_INPUT].value;
outputs[OUT2_OUTPUT].value = inputs[HIGH2_INPUT].value;
}
@@ -35,18 +47,22 @@ struct SwitchWidget : ModuleWidget {
// generated by svg_widgets.rb
auto gateParamPosition = Vec(13.5, 22.0);
+ auto latchParamPosition = Vec(32.9, 82.9);
auto gateInputPosition = Vec(10.5, 44.0);
- auto high1InputPosition = Vec(10.5, 90.0);
- auto low1InputPosition = Vec(10.5, 126.0);
- auto high2InputPosition = Vec(10.5, 209.0);
- auto low2InputPosition = Vec(10.5, 245.0);
+ auto high1InputPosition = Vec(10.5, 100.0);
+ auto low1InputPosition = Vec(10.5, 136.0);
+ auto high2InputPosition = Vec(10.5, 217.0);
+ auto low2InputPosition = Vec(10.5, 253.0);
- auto out1OutputPosition = Vec(10.5, 164.0);
- auto out2OutputPosition = Vec(10.5, 283.0);
+ auto out1OutputPosition = Vec(10.5, 174.0);
+ auto out2OutputPosition = Vec(10.5, 291.0);
+
+ auto latchLightPosition = Vec(4.0, 84.5);
// end generated by svg_widgets.rb
- addParam(ParamWidget::create<Button18>(gateParamPosition, module, bogaudio::Switch::GATE_PARAM, 0.0, 1.0, 0.0));
+ addParam(ParamWidget::create<Button18>(gateParamPosition, module, bogaudio::Switch::GATE_PARAM, 0.0, 10.0, 0.0));
+ addParam(ParamWidget::create<StatefulButton9>(latchParamPosition, module, bogaudio::Switch::LATCH_PARAM, 0.0, 1.0, 0.0));
addInput(Port::create<Port24>(gateInputPosition, Port::INPUT, module, bogaudio::Switch::GATE_INPUT));
addInput(Port::create<Port24>(high1InputPosition, Port::INPUT, module, bogaudio::Switch::HIGH1_INPUT));
@@ -56,6 +72,8 @@ struct SwitchWidget : ModuleWidget {
addOutput(Port::create<Port24>(out1OutputPosition, Port::OUTPUT, module, bogaudio::Switch::OUT1_OUTPUT));
addOutput(Port::create<Port24>(out2OutputPosition, Port::OUTPUT, module, bogaudio::Switch::OUT2_OUTPUT));
+
+ addChild(ModuleLightWidget::create<SmallLight<GreenLight>>(latchLightPosition, module, bogaudio::Switch::LATCH_LIGHT));
}
};
diff --git a/src/Switch.hpp b/src/Switch.hpp
@@ -9,6 +9,7 @@ namespace bogaudio {
struct Switch : Module {
enum ParamsIds {
GATE_PARAM,
+ LATCH_PARAM,
NUM_PARAMS
};
@@ -28,10 +29,12 @@ struct Switch : Module {
};
enum LightsIds {
+ LATCH_LIGHT,
NUM_LIGHTS
};
SchmittTrigger _trigger;
+ bool _latchedHigh = false;
Switch() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
onReset();