/** {@inheritDoc} */
 @Override
 public void execute(DmxService service) {
   int i = 0;
   for (Fade f : fades) {
     // first fade should reset any running fades
     int j = 0;
     for (int channel : item.getChannels()) {
       service.fadeChannel(channel, f.getTime(), f.targetValues[j++], f.getHoldTime(), i == 0);
       if (j == f.targetValues.length) {
         j = 0;
       }
     }
     i++;
   }
 }
Beispiel #2
0
  private void setHSBValue(DmxService service, HSBType hsbValue) {

    hsbState = hsbValue;

    int valueLength = isRgbw() ? 4 : 3;
    int[] values = new int[valueLength];
    values[0] = DmxUtil.getByteFromPercentType(hsbValue.getRed());
    values[1] = DmxUtil.getByteFromPercentType(hsbValue.getGreen());
    values[2] = DmxUtil.getByteFromPercentType(hsbValue.getBlue());
    if (isRgbw()) {
      values[3] = DmxUtil.calculateWhite(values[0], values[1], values[3]);
    }

    int j = 0;
    for (int c : channels) {
      service.setChannelValue(c, values[j++]);
      if (j == values.length) {
        j = 0;
      }
    }
  }
Beispiel #3
0
  /** {@inheritDoc} */
  @Override
  public void processCommand(DmxService service, Command command) {

    // process HSB command
    if (command instanceof HSBType) {
      HSBType hsbValue = (HSBType) command;
      setHSBValue(service, hsbValue);
      return;
    }

    // process increase/decrease
    if (command instanceof IncreaseDecreaseType
        && !isRedefinedByCustomCommand(command)
        && !service.hasChannelActions(channels[0])) {

      // rather than doing a linear fade on all channels, we fade only the
      // V part of HSV to maintain the color during the fade

      HSBType hsb = hsbState;
      int brightness = 0;
      IncreaseDecreaseType t = (IncreaseDecreaseType) command;
      if (IncreaseDecreaseType.INCREASE.equals(t)) {

        if (hsb == null) {
          hsb = new HSBType(Color.WHITE);
        }
        for (int ch : channels) {
          service.enableChannel(ch);
        }

        brightness = hsb.getBrightness().intValue();
        brightness += BRIGHTNESS_STEP_SIZE;
        if (brightness > 100) {
          brightness = 100;
        }

      } else {

        if (hsb == null) {
          hsb = new HSBType(Color.BLACK);
        }
        brightness = hsb.getBrightness().intValue();
        brightness -= BRIGHTNESS_STEP_SIZE;
        if (brightness <= 0) {
          brightness = 0;
        }
      }

      HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(brightness));
      setHSBValue(service, newHsb);
      return;
    }

    // process percent command
    if (command instanceof PercentType
        && !isRedefinedByCustomCommand(command)
        && !service.hasChannelActions(channels[0])) {
      PercentType t = (PercentType) command;

      HSBType hsb = hsbState;
      if (hsb == null) {
        hsb = new HSBType(Color.WHITE);
      }

      HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), t);
      setHSBValue(service, newHsb);
      return;
    }

    // process on/off, increase/decrease, percent type
    super.processCommand(service, command);
  }