Exemple #1
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);
}
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);
}
Exemple #3
0
void OlaDevice::applyChannelValues(SimpleCB aDoneCB, bool aForDimming)
{
  MLMicroSeconds transitionTime = 0;
  // abort previous transition
  MainLoop::currentMainLoop().cancelExecutionTicket(transitionTicket);
  // generic device, show changed channels
  if (olaType==ola_dimmer) {
    // single channel 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 (olaType==ola_fullcolordimmer) {
    // RGB, RGBW or RGBWA dimmer
    RGBColorLightBehaviourPtr cl = boost::dynamic_pointer_cast<RGBColorLightBehaviour>(output);
    if (cl) {
      MovingLightBehaviourPtr ml = boost::dynamic_pointer_cast<MovingLightBehaviour>(output);
      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
        if (ml) ml->positionTransitionStep(); // init
        applyChannelValueSteps(aForDimming, transitionTime==0 ? 1 : (double)TRANSITION_STEP_TIME/transitionTime);
      }
      // consider applied
      if (ml) ml->appliedPosition();
      cl->appliedColorValues();
    }
  }
  inherited::applyChannelValues(aDoneCB, aForDimming);
}
Exemple #4
0
void DemoDevice::applyChannelValues(SimpleCB aDoneCB, bool aForDimming)
{
  // light device
  LightBehaviourPtr lightBehaviour = boost::dynamic_pointer_cast<LightBehaviour>(output);
  if (lightBehaviour && lightBehaviour->brightnessNeedsApplying()) {
    // This would be the place to implement sending the output value to the hardware
    // For the demo device, we show the output as a bar of 0..64 '#' chars
    // - read the brightness value from the behaviour
    int hwValue = lightBehaviour->brightnessForHardware();
    // - display as a bar of hash chars
    string bar;
    while (hwValue>0) {
      // one hash character per 2 output value steps (0..100 = 0..50 hashes)
      bar += '#';
      hwValue -= 2;
    }
    printf("Demo Device Output: %s\n", bar.c_str());
    lightBehaviour->brightnessApplied(); // confirm having applied the value
  }
  inherited::applyChannelValues(aDoneCB, aForDimming);
}