Search in sources :

Example 1 with BaseAction

use of org.eclipse.smarthome.binding.dmx.internal.action.BaseAction in project smarthome by eclipse.

the class DmxChannel method switchToNextAction.

/**
 * Move to the next action in the action chain. This method is used by
 * automatic chains and to manually move to the next action if actions are
 * set as indefinite (e.g. endless hold). This allows the user to toggle
 * through a fixed set of values.
 */
public synchronized void switchToNextAction() {
    // push action to the back of the action list
    BaseAction action = actions.get(0);
    actions.remove(0);
    action.reset();
    actions.add(action);
    logger.trace("switching to next action {} on channel {}", actions.get(0), this);
}
Also used : BaseAction(org.eclipse.smarthome.binding.dmx.internal.action.BaseAction)

Example 2 with BaseAction

use of org.eclipse.smarthome.binding.dmx.internal.action.BaseAction in project smarthome by eclipse.

the class DmxChannel method getNewHiResValue.

/**
 * Get the new value for this channel as determined by active actions or the
 * current value.
 *
 * @param calculationTime UNIX timestamp
 * @return value 0-65535
 */
public synchronized Integer getNewHiResValue(long calculationTime) {
    if (hasRunningActions()) {
        logger.trace("checking actions, list is {}", actions);
        BaseAction action = actions.get(0);
        value = action.getNewValue(this, calculationTime);
        if (action.getState() == ActionState.COMPLETED && hasRunningActions()) {
            switchToNextAction();
        } else if (action.getState() == ActionState.COMPLETEDFINAL) {
            clearAction();
        }
    }
    // send updates not more than once in a second, and only on value change
    if ((lastStateValue != value) && (calculationTime - lastStateTimestamp > refreshTime)) {
        // notify value listeners if value changed
        for (Entry<ChannelUID, DmxThingHandler> listener : valueListeners.entrySet()) {
            int dmxValue = Util.toDmxValue(value >> 8);
            (listener.getValue()).updateChannelValue(listener.getKey(), dmxValue);
            logger.trace("sending VALUE={} (raw={}) status update to listener {} ({})", dmxValue, value, listener.getValue(), listener.getKey());
        }
        // notify on/off listeners if on/off state changed
        if ((lastStateValue == 0) || (value == 0)) {
            OnOffType state = (value == 0) ? OnOffType.OFF : OnOffType.ON;
            for (Entry<ChannelUID, DmxThingHandler> listener : onOffListeners.entrySet()) {
                (listener.getValue()).updateSwitchState(listener.getKey(), state);
                logger.trace("sending ONOFF={} (raw={}), status update to listener {}", state, value, listener.getKey());
            }
        }
        lastStateValue = value;
        lastStateTimestamp = calculationTime;
    }
    return value;
}
Also used : DmxThingHandler(org.eclipse.smarthome.binding.dmx.internal.DmxThingHandler) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) BaseAction(org.eclipse.smarthome.binding.dmx.internal.action.BaseAction)

Aggregations

BaseAction (org.eclipse.smarthome.binding.dmx.internal.action.BaseAction)2 DmxThingHandler (org.eclipse.smarthome.binding.dmx.internal.DmxThingHandler)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1