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. *
*
* 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 2010
* @version $Revision: 215 $
*/
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 longBluePress() {
// reset selections, leave gold alone
for (int i=0; i