|
From: <jac...@us...> - 2010-05-27 01:58:46
|
Revision: 210
http://openlcb.svn.sourceforge.net/openlcb/?rev=210&view=rev
Author: jacobsen
Date: 2010-05-27 01:58:37 +0000 (Thu, 27 May 2010)
Log Message:
-----------
new Blue/Gold 'extended' implementation
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldEngine.java
trunk/prototypes/java/test/scenarios/BlueGoldCheck.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldExtendedEngine.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldEngine.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldEngine.java 2010-05-26 19:06:52 UTC (rev 209)
+++ trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldEngine.java 2010-05-27 01:58:37 UTC (rev 210)
@@ -68,6 +68,7 @@
}
// exit
setBlueLightOn(false);
+ setGoldLightOn(false);
selectedPC = -1;
}
@@ -79,12 +80,18 @@
// Methods to be overridden in using classes
public void setBlueLightOn(boolean f) {
}
+ public boolean getBlueLightOn() {
+ return false;
+ }
public void setBlueLightBlink(int dwell) {
}
public void setGoldLightOn(boolean f) {
}
+ public boolean getGoldLightOn() {
+ return false;
+ }
public void setGoldLightBlink(int dwell) {
}
@@ -120,7 +127,10 @@
}
protected void sendLearnEventMessage(EventID eid) {
- c.put(new LearnEventMessage(nid, eid), this);
+ LearnEventMessage msg = new LearnEventMessage(nid, eid);
+ c.put(msg, this);
+ // also process here
+ handleLearnEvent(msg, null);
}
EventID getEventID(int n) {
Added: trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldExtendedEngine.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldExtendedEngine.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldExtendedEngine.java 2010-05-27 01:58:37 UTC (rev 210)
@@ -0,0 +1,103 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+/**
+ * Example of a OpenLCB algorithm for doing configuration with
+ * small number of buttons. This an extended form that allows
+ * multiple selection and deselection.
+ *<p>
+ *<ul>
+ *<li>On learners, push blue to choose a C/P, then gold to put that C/P in learn mode
+ * (complete cycle turns off blue light and starts over)
+ *<li>On the teaching node, push gold to choose teach mode, then
+ * blue to select a C/P,
+ * push Gold to send the TeachEvent message
+ *</ul>
+ *<p>
+ * This handles both "configuring" and "being configured"
+ * cases. It also handles both consumers and producers
+ * via working with the
+ * {@link SingleConsumerNode} and {@link SingleProducerNode}
+ * example classes.
+ * <p>
+ * For button inputs, it currently has only "click" operations.
+ * Perhaps "down" and "up" will be needed eventually.
+ * Similarly, it only does "on" and "off" for the two lights.
+ * @author Bob Jacobsen Copyright 2010
+ * @version $Revision$
+ */
+public class BlueGoldExtendedEngine extends BlueGoldEngine {
+
+ boolean[] isSelectedPC;
+
+ public void goldClick() {
+ if (getGoldLightOn() && getBlueLightOn()) {
+ // in teach mode, send LearnEvent
+ if (selectedPC >= 0) { // redundant, as blue is on
+ // have a selected P or C
+ sendLearnEventMessage(getEventID(selectedPC));
+ setGoldLightOn(false);
+ setBlueLightOn(false);
+ selectedPC = -1;
+ return;
+ }
+ } else if (!getGoldLightOn() && getBlueLightOn()) {
+ // in learn mode, select item
+ if (selectedPC >= 0) { // redundant, as blue is on
+ isSelectedPC[selectedPC] = true;
+ selectedPC = -1;
+ setBlueLightOn(false);
+ }
+ } else if (!getGoldLightOn() && !getBlueLightOn()) {
+ // starting up, light gold
+ setGoldLightOn(true);
+ } else { // gold on, blue off
+ // give up
+ setGoldLightOn(false);
+ setBlueLightOn(false);
+ selectedPC = -1;
+ for (boolean p : isSelectedPC) p = false;
+ }
+ }
+
+ public void blueClick() {
+ // click updates selection
+ selectedPC++;
+ //check if wrapping
+ if (selectedPC >= producers.size()+consumers.size()) {
+ // yes, turn off light until next time
+ selectedPC = -1;
+ setBlueLightOn(false);
+ } else {
+ // no, make sure light is on
+ setBlueLightOn(true);
+ }
+ return;
+ }
+
+ public void handleLearnEvent(LearnEventMessage msg, Connection sender){
+ // learn
+ for (int i=0; i<isSelectedPC.length; i++) {
+ if (isSelectedPC[i]) {
+ EventID eid = msg.getEventID();
+ System.out.println("Set "+i+" to "+eid);
+ setEventID(i, eid);
+ }
+ isSelectedPC[i] = false;
+ }
+ // exit
+ setBlueLightOn(false);
+ setGoldLightOn(false);
+ selectedPC = -1;
+ }
+
+ public BlueGoldExtendedEngine(NodeID nid, ScatterGather sg,
+ java.util.List<SingleProducer> producers,
+ java.util.List<SingleConsumer> consumers) {
+ super(nid, sg, producers, consumers);
+
+ isSelectedPC = new boolean[producers.size()+consumers.size()];
+ for (boolean p : isSelectedPC) p = false;
+ }
+}
Property changes on: trunk/prototypes/java/src/org/openlcb/implementations/BlueGoldExtendedEngine.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ native
Modified: trunk/prototypes/java/test/scenarios/BlueGoldCheck.java
===================================================================
--- trunk/prototypes/java/test/scenarios/BlueGoldCheck.java 2010-05-26 19:06:52 UTC (rev 209)
+++ trunk/prototypes/java/test/scenarios/BlueGoldCheck.java 2010-05-27 01:58:37 UTC (rev 210)
@@ -198,10 +198,13 @@
setGoldOn(false);
p1.add(goldLabel);
- engine = new BlueGoldEngine(nid, sg, producers, consumers) {
+ engine = new BlueGoldExtendedEngine(nid, sg, producers, consumers) {
public void setBlueLightOn(boolean f) {
setBlueOn(f);
}
+ public boolean getBlueLightOn() {
+ return blueOn;
+ }
public void setBlueLightBlink(int dwell) {
setBlueBlink(dwell);
@@ -210,6 +213,9 @@
public void setGoldLightOn(boolean f) {
setGoldOn(f);
}
+ public boolean getGoldLightOn() {
+ return goldOn;
+ }
public void setGoldLightBlink(int dwell) {
setGoldBlink(dwell);
@@ -314,7 +320,7 @@
else
colorBlueOff();
}
-
+
public void setBlueBlink(int dwell) {
blueBlink = true;
blueOn = true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|