double FanCoilUnitScene::sceneValue(int aChannelIndex)
{
  ChannelBehaviourPtr cb = getDevice().getChannelByIndex(aChannelIndex);
  switch (cb->getChannelType()) {
    case channeltype_fcu_operation_mode: return operationMode;
    case channeltype_power_state: return powerState ? 1 : 0;
  }
  return 0;
}
Beispiel #2
0
void MovingLightScene::setSceneValue(size_t aChannelIndex, double aValue)
{
  ChannelBehaviourPtr cb = getDevice().getChannelByIndex(aChannelIndex);
  switch (cb->getChannelType()) {
    case channeltype_position_h : hPos = aValue;
    case channeltype_position_v : vPos = aValue;
    default: inherited::setSceneValue(aChannelIndex, aValue); break;
  }
}
Beispiel #3
0
double MovingLightScene::sceneValue(size_t aChannelIndex)
{
  ChannelBehaviourPtr cb = getDevice().getChannelByIndex(aChannelIndex);
  switch (cb->getChannelType()) {
    case channeltype_position_h : return hPos;
    case channeltype_position_v : return vPos;
    default: return inherited::sceneValue(aChannelIndex);
  }
  return 0;
}
Beispiel #4
0
ChannelBehaviourPtr OutputBehaviour::getChannelByIndex(size_t aChannelIndex, bool aPendingApplyOnly)
{
  if (aChannelIndex<channels.size()) {
    ChannelBehaviourPtr ch = channels[aChannelIndex];
    if (!aPendingApplyOnly || ch->needsApplying())
      return ch;
    // found but has no apply pending -> return no channel
  }
  return ChannelBehaviourPtr();
}
Beispiel #5
0
// default loader for single-value outputs. Note that this is overridden by more complex behaviours such as light
void OutputBehaviour::loadChannelsFromScene(DsScenePtr aScene)
{
  if (aScene) {
    // load default channel's value from first channel of scene
    ChannelBehaviourPtr ch = getChannelByIndex(0);
    if (ch) {
      ch->setChannelValueIfNotDontCare(aScene, aScene->sceneValue(0), 0, 0, true);
    }
  }
}
Beispiel #6
0
void OutputBehaviour::saveChannelsToScene(DsScenePtr aScene)
{
  if (aScene) {
    // save default channel's value to first channel of scene
    ChannelBehaviourPtr ch = getChannelByIndex(0);
    if (ch) {
      double newval = ch->getChannelValue();
      aScene->setSceneValue(0, newval);
    }
    aScene->setSceneValueFlags(0, valueflags_dontCare, false);
  }
}
void FanCoilUnitScene::setSceneValue(int aChannelIndex, double aValue)
{
  ChannelBehaviourPtr cb = getDevice().getChannelByIndex(aChannelIndex);
  ClimateControlBehaviourPtr ccb = boost::dynamic_pointer_cast<ClimateControlBehaviour>(getOutputBehaviour());
  switch (cb->getChannelType()) {
    case channeltype_fcu_operation_mode:
      setPVar(operationMode, (FcuOperationMode)aValue);
      break;
    case channeltype_power_state:
      setPVar(powerState, aValue>0);
      break;
  }
}
bool ClimateControlBehaviour::processControlValue(const string &aName, double aValue)
{
  if (aName=="heatingLevel" && climateDeviceKind==climatedevice_simple) {
    if (isMember(group_roomtemperature_control) && isEnabled()) {
      // if we have a heating/cooling power level channel, "heatingLevel" will control it
      ChannelBehaviourPtr cb = getChannelByType(channeltype_heating_power);
      if (cb) {
        // clip to -100..0..100 range
        if (aValue<-100) aValue = -100;
        else if (aValue>100) aValue = 100;
        // limit according to heatingSystemCapability setting
        switch (heatingSystemCapability) {
          case hscapability_heatingOnly:
            // 0..100
            if (aValue<0) aValue = 0; // ignore negatives
            break;
          case hscapability_coolingOnly:
            // -100..0
            if (aValue>0) aValue = 0; // ignore positives
            break;
          default:
          case hscapability_heatingAndCooling:
            // pass all values
            break;
        }
        // adapt to hardware capabilities
        if (outputFunction!=outputFunction_bipolar_positional) {
          // non-bipolar valves can only handle positive values, even for cooling
          aValue = fabs(aValue);
        }
        // apply now
        cb->setChannelValue(aValue, 0, true); // always apply
        return true; // needs apply
      }
    }
  }
  else if (aName=="TemperatureZone") {
    zoneTemperature = aValue;
    zoneTemperatureUpdated = MainLoop::currentMainLoop().now();
  }
  else if (aName=="TemperatureSetPoint") {
    zoneTemperatureSetPoint = aValue;
    zoneTemperatureSetPointUpdated = MainLoop::currentMainLoop().now();
  }
  return inherited::processControlValue(aName, aValue);
}
Beispiel #9
0
void AnalogIODevice::applyChannelValues(SimpleCB aDoneCB, bool aForDimming)
{
  MLMicroSeconds transitionTime = 0;
  // abort previous transition
  MainLoop::currentMainLoop().cancelExecutionTicket(timerTicket);
  // generic device, show changed channels
  if (analogIOType==analogio_dimmer) {
    // single channel PWM dimmer
    LightBehaviourPtr l = boost::dynamic_pointer_cast<LightBehaviour>(output);
    if (l && l->brightnessNeedsApplying()) {
      transitionTime = l->transitionTimeToNewBrightness();
      l->brightnessTransitionStep(); // init
      applyChannelValueSteps(aForDimming, transitionTime==0 ? 1 : (double)TRANSITION_STEP_TIME/transitionTime);
    }
    // consider applied
    l->brightnessApplied();
  }
  else if (analogIOType==analogio_rgbdimmer) {
    // three channel RGB PWM dimmer
    RGBColorLightBehaviourPtr cl = boost::dynamic_pointer_cast<RGBColorLightBehaviour>(output);
    if (cl) {
      if (needsToApplyChannels()) {
        // needs update
        // - derive (possibly new) color mode from changed channels
        cl->deriveColorMode();
        // - calculate and start transition
        //   TODO: depending to what channel has changed, take transition time from that channel. For now always using brightness transition time
        transitionTime = cl->transitionTimeToNewBrightness();
        cl->brightnessTransitionStep(); // init
        cl->colorTransitionStep(); // init
        applyChannelValueSteps(aForDimming, transitionTime==0 ? 1 : (double)TRANSITION_STEP_TIME/transitionTime);
      } // if needs update
      // consider applied
      cl->appliedColorValues();
    }
  }
  else {
    // direct single channel PWM output, no smooth transitions
    ChannelBehaviourPtr ch = getChannelByIndex(0);
    if (ch && ch->needsApplying()) {
      double chVal = ch->getTransitionalValue()-ch->getMin();
      double chSpan = ch->getMax()-ch->getMin();
      analogIO->setValue(chVal/chSpan*100); // 0..100%
      ch->channelValueApplied(); // confirm having applied the value
    }
  }
  // always consider apply done, even if transition is still running
  inherited::applyChannelValues(aDoneCB, aForDimming);
}
Beispiel #10
0
void EnoceanRelayControlDevice::applyChannelValues(SimpleCB aDoneCB, bool aForDimming)
{
  // standard output behaviour
  if (output) {
    ChannelBehaviourPtr ch = output->getChannelByType(channeltype_default);
    if (ch->needsApplying()) {
      bool up = ch->getChannelValue() >= (ch->getMax()-ch->getMin())/2;
      buttonAction(false, up, true);
      MainLoop::currentMainLoop().executeOnce(boost::bind(&EnoceanRelayControlDevice::sendReleaseTelegram, this, aDoneCB, up), BUTTON_PRESS_TIME);
      ch->channelValueApplied();
    }
  }
}
Beispiel #11
0
void DigitalIODevice::applyChannelValues(SimpleCB aDoneCB, bool aForDimming)
{
  LightBehaviourPtr lightBehaviour = boost::dynamic_pointer_cast<LightBehaviour>(output);
  if (lightBehaviour) {
    // light
    if (lightBehaviour->brightnessNeedsApplying()) {
      indicatorOutput->set(lightBehaviour->brightnessForHardware());
      lightBehaviour->brightnessApplied(); // confirm having applied the value
    }
  }
  else if (output) {
    // simple switch output, activates at 50% of possible output range
    ChannelBehaviourPtr ch = output->getChannelByIndex(0);
    if (ch->needsApplying()) {
      indicatorOutput->set(ch->getChannelValue() >= (ch->getMax()-ch->getMin())/2);
      ch->channelValueApplied();
    }
  }
  inherited::applyChannelValues(aDoneCB, aForDimming);
}