mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
refactoring of polarity aware LED
This commit is contained in:
parent
a88e38a616
commit
cb746ac5aa
@ -17,6 +17,7 @@ HEAD, planed as v0.18
|
||||
- Added a simple bidirectional splitter.
|
||||
- Added a monoflop.
|
||||
- Added a 16 Segment display.
|
||||
- Added a polarity aware LED.
|
||||
- Added a counter with preset.
|
||||
|
||||
v0.17, released on 19. Feb 2018
|
||||
|
@ -46,6 +46,16 @@ public class Out implements Element {
|
||||
.addAttribute(Keys.SIZE)
|
||||
.addAttribute(Keys.COLOR);
|
||||
|
||||
/**
|
||||
* The polarity aware LED description
|
||||
*/
|
||||
public static final ElementTypeDescription POLARITYAWARELEDDESCRIPTION
|
||||
= new ElementTypeDescription("PolarityAwareLED",
|
||||
attributes -> new Out(1, 1), input("A"), input("C"))
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.COLOR);
|
||||
|
||||
/**
|
||||
* The seven segment display description
|
||||
*/
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Helmut Neemann
|
||||
* Use of this source code is governed by the GPL v3 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package de.neemann.digital.core.io;
|
||||
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValues;
|
||||
import de.neemann.digital.core.element.Element;
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
|
||||
import static de.neemann.digital.core.element.PinInfo.input;
|
||||
|
||||
/**
|
||||
* A real LED
|
||||
*/
|
||||
public class RealLED implements Element {
|
||||
|
||||
/**
|
||||
* The LED description
|
||||
*/
|
||||
public static final ElementTypeDescription DESCRIPTION
|
||||
= new ElementTypeDescription(RealLED.class, input("A"), input("C"))
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.COLOR);
|
||||
|
||||
/**
|
||||
* Creates a new light bulb
|
||||
*
|
||||
* @param attr the attributes
|
||||
*/
|
||||
public RealLED(ElementAttributes attr) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputs(ObservableValues inputs) throws NodeException {
|
||||
inputs.get(0).checkBits(1, null, 0);
|
||||
inputs.get(1).checkBits(1, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValues getOutputs() {
|
||||
return ObservableValues.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@ import java.util.*;
|
||||
*/
|
||||
public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ElementLibrary.class);
|
||||
private static final long MIN_RESCAN_INTERVAL = 5000;
|
||||
|
||||
/**
|
||||
* @return the additional library path
|
||||
@ -82,6 +83,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
private ElementLibraryFolder custom;
|
||||
private File rootLibraryPath;
|
||||
private Exception exception;
|
||||
private long lastRescanTime;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
@ -117,7 +119,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
.add(Probe.DESCRIPTION)
|
||||
.add(new LibraryNode(Lang.get("lib_more"))
|
||||
.add(LightBulb.DESCRIPTION)
|
||||
.add(RealLED.DESCRIPTION)
|
||||
.add(Out.POLARITYAWARELEDDESCRIPTION)
|
||||
.add(Out.SEVENDESCRIPTION)
|
||||
.add(Out.SEVENHEXDESCRIPTION)
|
||||
.add(Out.SIXTEENDESCRIPTION)
|
||||
@ -396,11 +398,15 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
if (rootLibraryPath == null)
|
||||
throw new ElementNotFoundException(Lang.get("err_fileNeedsToBeSaved"));
|
||||
|
||||
rescanFolder();
|
||||
LOGGER.debug("could not find " + elementName);
|
||||
|
||||
node = map.get(elementName);
|
||||
if (node != null)
|
||||
return node.getDescription();
|
||||
if (System.currentTimeMillis() - lastRescanTime > MIN_RESCAN_INTERVAL) {
|
||||
rescanFolder();
|
||||
|
||||
node = map.get(elementName);
|
||||
if (node != null)
|
||||
return node.getDescription();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ElementNotFoundException(Lang.get("msg_errorImportingModel_N0", elementName), e);
|
||||
}
|
||||
@ -408,7 +414,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
throw new ElementNotFoundException(Lang.get("err_element_N_notFound", elementName));
|
||||
}
|
||||
|
||||
private void rescanFolder() throws IOException {
|
||||
private void rescanFolder() {
|
||||
LOGGER.debug("rescan folder");
|
||||
LibraryNode cn = custom.scanFolder(rootLibraryPath, false);
|
||||
|
||||
@ -416,6 +422,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
|
||||
if (cn != null)
|
||||
fireLibraryChanged(cn);
|
||||
lastRescanTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,9 +23,9 @@ import static de.neemann.digital.draw.shapes.PullDownShape.HEIGHT;
|
||||
import static de.neemann.digital.draw.shapes.PullDownShape.WIDTH2;
|
||||
|
||||
/**
|
||||
* The real LED shape
|
||||
* The polarity aware LED shape
|
||||
*/
|
||||
public class RealLEDShape implements Shape {
|
||||
public class PolarityAwareLEDShape implements Shape {
|
||||
private static final int RAD = SIZE * 3 / 4;
|
||||
private final PinDescriptions inputs;
|
||||
private final Style style;
|
||||
@ -42,7 +42,7 @@ public class RealLEDShape implements Shape {
|
||||
* @param inputs the inputs
|
||||
* @param outputs the outputs
|
||||
*/
|
||||
public RealLEDShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||
public PolarityAwareLEDShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||
this.inputs = inputs;
|
||||
style = Style.NORMAL.deriveFillStyle(attr.get(Keys.COLOR));
|
||||
String l = attr.getLabel();
|
@ -90,7 +90,7 @@ public final class ShapeFactory {
|
||||
map.put(Out.DESCRIPTION.getName(), OutputShape::new);
|
||||
map.put(Out.LEDDESCRIPTION.getName(), LEDShape::new);
|
||||
map.put(LightBulb.DESCRIPTION.getName(), LightBulbShape::new);
|
||||
map.put(RealLED.DESCRIPTION.getName(), RealLEDShape::new);
|
||||
map.put(Out.POLARITYAWARELEDDESCRIPTION.getName(), PolarityAwareLEDShape::new);
|
||||
map.put(Button.DESCRIPTION.getName(), ButtonShape::new);
|
||||
map.put(Probe.DESCRIPTION.getName(), ProbeShape::new);
|
||||
map.put(Clock.DESCRIPTION.getName(), ClockShape::new);
|
||||
|
@ -168,11 +168,11 @@
|
||||
<string name="elem_LightBulb_pin_A">Anschluss</string>
|
||||
<string name="elem_LightBulb_pin_B">Anschluss</string>
|
||||
|
||||
<string name="elem_RealLED">LED mit zwei Anschlüssen</string>
|
||||
<string name="elem_RealLED_tt">LED mit zwei Anschlüssen für die Kathode und die Anode. Die LED leuchtet
|
||||
<string name="elem_PolarityAwareLED">LED mit zwei Anschlüssen</string>
|
||||
<string name="elem_PolarityAwareLED_tt">LED mit zwei Anschlüssen für die Kathode und die Anode. Die LED leuchtet
|
||||
nur, wenn die Anode auf High und die Kathode auf Low gelegt wird.</string>
|
||||
<string name="elem_RealLED_pin_A">Die Anode der LED.</string>
|
||||
<string name="elem_RealLED_pin_C">Die Kathode der LED.</string>
|
||||
<string name="elem_PolarityAwareLED_pin_A">Die Anode der LED.</string>
|
||||
<string name="elem_PolarityAwareLED_pin_C">Die Kathode der LED.</string>
|
||||
|
||||
<string name="elem_Seven-Seg">Siebensegmentanzeige</string>
|
||||
<string name="elem_Seven-Seg_tt">Siebensegmentanzeige, bei der jedes Segment über einen eigenen Eingang gesteuert
|
||||
|
@ -133,11 +133,11 @@
|
||||
Lights up if the input is set to 1.</string>
|
||||
<string name="elem_LED_pin_in">LED Input. LED lights up if the input is set to 1.</string>
|
||||
|
||||
<string name="elem_RealLED">LED with two connections.</string>
|
||||
<string name="elem_RealLED_tt">LED with connections for the cathode and the anode. The LED lights up,
|
||||
<string name="elem_PolarityAwareLED">LED with two connections.</string>
|
||||
<string name="elem_PolarityAwareLED_tt">LED with connections for the cathode and the anode. The LED lights up,
|
||||
if the anode is connected to high and the cathode is connected to low.</string>
|
||||
<string name="elem_RealLED_pin_A">The anode connection of the LED.</string>
|
||||
<string name="elem_RealLED_pin_C">The cathode connection of the LED.</string>
|
||||
<string name="elem_PolarityAwareLED_pin_A">The anode connection of the LED.</string>
|
||||
<string name="elem_PolarityAwareLED_pin_C">The cathode connection of the LED.</string>
|
||||
|
||||
<string name="elem_In">Input</string>
|
||||
<string name="elem_In_tt">Can be used to interactively manipulate an input signal in a circuit with the
|
||||
|
@ -535,7 +535,7 @@
|
||||
<pos x="800" y="860"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>RealLED</elementName>
|
||||
<elementName>PolarityAwareLED</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="1200" y="420"/>
|
||||
</visualElement>
|
||||
|
@ -469,9 +469,9 @@
|
||||
<pos x="440" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>RealLED</elementName>
|
||||
<elementName>PolarityAwareLED</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="200" y="160"/>
|
||||
<pos x="200" y="180"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user