Commit 870de46b authored by luz's avatar luz

Output mode: setting it to disabled now actually disables the output (what...

Output mode: setting it to disabled now actually disables the output (what this means is device specific) and prevents any further channel updates. A change in mode now causes all channels to re-apply.
parent 3c5bd760
......@@ -103,7 +103,11 @@ void LightBehaviour::initMinBrightness(Brightness aMin)
Brightness LightBehaviour::brightnessForHardware()
{
if (isDimmable()) {
if (!isEnabled()) {
// disabled lights are off
return 0;
}
else if (isDimmable()) {
// dim output
return brightness->getTransitionalValue();
}
......
......@@ -790,7 +790,7 @@ void Device::dimChannel(DsChannelType aChannelType, DsDimMode aDimMode)
isDimming = true;
// wait for all apply operations to really complete before starting to dim
SimpleCB dd = boost::bind(&Device::dimDoneHandler, this, ch, increment, MainLoop::now()+10*MilliSecond);
waitForApplyComplete(boost::bind(&Device::requestApplyingChannels, this, dd, false));
waitForApplyComplete(boost::bind(&Device::requestApplyingChannels, this, dd, false, false));
}
}
}
......@@ -827,8 +827,14 @@ void Device::dimDoneHandler(ChannelBehaviourPtr aChannel, double aIncrement, MLM
#define SERIALIZER_WATCHDOG 1
#define SERIALIZER_WATCHDOG_TIMEOUT (20*Second)
void Device::requestApplyingChannels(SimpleCB aAppliedOrSupersededCB, bool aForDimming)
void Device::requestApplyingChannels(SimpleCB aAppliedOrSupersededCB, bool aForDimming, bool aModeChange)
{
if (!aModeChange && output && !output->isEnabled()) {
// disabled output and not a mode change -> no operation
FOCUSLOG("requestApplyingChannels called with output disabled in device %s -> NOP\n", shortDesc().c_str());
// - just call back immediately
if (aAppliedOrSupersededCB) aAppliedOrSupersededCB();
}
FOCUSLOG("requestApplyingChannels entered in device %s\n", shortDesc().c_str());
// Caller wants current channel values applied to hardware
// Three possible cases:
......@@ -860,7 +866,7 @@ void Device::requestApplyingChannels(SimpleCB aAppliedOrSupersededCB, bool aForD
applyInProgress = true;
}
else {
// case c) applying is not currently in progress, start updating hardware now
// case c) applying is not currently in progress, can start updating hardware now
FOCUSLOG("- ready, calling applyChannelValues() in device %s\n", shortDesc().c_str());
#if SERIALIZER_WATCHDOG
// - start watchdog
......
......@@ -258,11 +258,13 @@ namespace p44 {
/// even newer values set requested to be applied.
/// @param aForDimming hint for implementations to optimize dimming, indicating that change is only an increment/decrement
/// in a single channel (and not switching between color modes etc.)
/// @param aModeChange if set, channels will be applied in all cases, even if output mode is set to "disabled".
/// This flag is set in calls when output mode has changed
/// @note this internally calls applyChannelValues() to perform actual work, but serializes the behaviour towards the caller
/// such that aAppliedOrSupersededCB of the previous request is always called BEFORE initiating subsequent
/// channel updates in the hardware. It also may discard requests (but still calling aAppliedOrSupersededCB) to
/// avoid stacking up delayed requests.
void requestApplyingChannels(SimpleCB aAppliedOrSupersededCB, bool aForDimming);
void requestApplyingChannels(SimpleCB aAppliedOrSupersededCB, bool aForDimming, bool aModeChange = false);
/// request callback when apply is really complete (all pending applies done)
/// @param aApplyCompleteCB will called when values are applied and no other change is pending
......@@ -377,6 +379,7 @@ namespace p44 {
/// @note this is the only routine that should trigger actual changes in output values. It must consult all of the device's
/// ChannelBehaviours and check isChannelUpdatePending(), and send new values to the device hardware. After successfully
/// updating the device hardware, channelValueApplied() must be called on the channels that had isChannelUpdatePending().
/// In addition, if the device output hardware has distinct disabled/enabled states, output->isEnabled() must be checked and applied.
/// @note the implementation must capture the channel values to be applied before returning from this method call,
/// because channel values might change again before a delayed apply mechanism calls aDoneCB.
/// @note this method will NOT be called again until aCompletedCB is called, even if that takes a long time.
......
......@@ -132,6 +132,21 @@ void OutputBehaviour::setGroupMembership(DsGroup aGroup, bool aIsMember)
}
void OutputBehaviour::setOutputMode(DsOutputMode aOutputMode)
{
// base class marks all channels needing re-apply and triggers a apply if mode changes
if (outputMode!=aOutputMode) {
// mode has actually changed
outputMode = aOutputMode;
for (ChannelBehaviourVector::iterator pos=channels.begin(); pos!=channels.end(); ++pos) {
(*pos)->setNeedsApplying(0); // needs immediate re-apply
}
device.requestApplyingChannels(NULL, false, true); // apply, for mode change
}
}
#pragma mark - scene handling
......@@ -447,7 +462,7 @@ bool OutputBehaviour::accessField(PropertyAccessMode aMode, ApiValuePtr aPropVal
switch (aPropertyDescriptor->fieldKey()) {
// Settings properties
case mode_key+settings_key_offset:
outputMode = (DsOutputMode)aPropValue->int32Value();
setOutputMode((DsOutputMode)aPropValue->int32Value());
markDirty();
return true;
case pushChanges_key+settings_key_offset:
......
......@@ -98,12 +98,20 @@ namespace p44 {
/// Configure hardware parameters of the output
void setHardwareOutputConfig(DsOutputFunction aOutputFunction, DsUsageHint aUsage, bool aVariableRamp, double aMaxPower);
/// @return true if device is in local priority mode
/// @param aLocalPriority true to set local priority mode, false to clear it
void setLocalPriority(bool aLocalPriority) { localPriority = aLocalPriority; };
/// @return true if device is in local priority mode
bool hasLocalPriority() { return localPriority; };
/// @return true if output is enabled
bool isEnabled() { return outputMode!=outputmode_disabled; };
/// set new output mode
/// @param aOutputMode, new output mode
/// @note a change in output mode might trigger (re-)applying channel values
virtual void setOutputMode(DsOutputMode aOutputMode);
/// @return output functionality the hardware provides
DsOutputFunction getOutputFunction() { return outputFunction; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment