package org.openlcb.implementations; import org.openlcb.*; /** * Example of a OpenLCB algorithm for doing configuration with * small number of buttons. *
*
* 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. *
* 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 2009
* @version $Revision: 529 $
*/
public class BlueGoldEngine extends MessageDecoder implements Connection {
int selectedPC = -1;
public void goldClick() {
if (selectedPC >= 0) {
// have a selected P or C
sendLearnEventMessage(getEventID(selectedPC));
setGoldLightOn(false);
setBlueLightOn(false);
selectedPC = -1;
System.out.println("send learn event");
return;
}
}
public void longGoldPress() {}
public void blueClick() {
// click updates selection
selectedPC++;
setBlueLightOn(true);
//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);
}
// and print for now (no GUI for this, add LEDs?)
System.out.println("incremented selectedPC to "+selectedPC);
return;
}
public void longBluePress() {}
public void handleLearnEvent(LearnEventMessage msg, Connection sender){
// learn
if (selectedPC >= 0) {
EventID eid = msg.getEventID();
System.out.println("Set "+selectedPC+" to "+eid);
setEventID(selectedPC, eid);
}
// exit
setBlueLightOn(false);
setGoldLightOn(false);
selectedPC = -1;
}
//*************************************************
//
// Below here is the class infrastructure
//
// 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) {
}
// ctors, local code and variables, etc
public BlueGoldEngine(NodeID nid, ScatterGather sg,
java.util.List