2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.velbus.internal.packets;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velbus.internal.VelbusChannelIdentifier;
19 * The {@link VelbusDimmerPacket} represents a Velbus packet that can be used to
20 * dim a light to a given percentage.
22 * @author Cedric Boon - Initial contribution
25 public class VelbusDimmerPacket extends VelbusPacket {
26 private static final byte FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_HIGH_BYTE = (byte) 0xFF;
27 private static final byte FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_LOW_BYTE = (byte) 0xFF;
29 private Boolean isFirstGenerationDevice;
32 private byte percentage;
35 public VelbusDimmerPacket(VelbusChannelIdentifier velbusChannelIdentifier, byte command, byte percentage,
36 int dimspeed, Boolean isFirstGenerationDevice) {
37 super(velbusChannelIdentifier.getAddress(), PRIO_HI);
39 this.channel = velbusChannelIdentifier.getChannelByte();
40 this.command = command;
41 this.percentage = percentage;
42 this.dimspeed = dimspeed;
43 this.isFirstGenerationDevice = isFirstGenerationDevice;
47 protected byte[] getDataBytes() {
48 byte dimspeedHighByte = (byte) ((dimspeed & 0xFF00) / 0x100);
49 byte dimspeedLowByte = (byte) (dimspeed & 0xFF);
51 if (dimspeed == 0 && isFirstGenerationDevice) {
52 dimspeedHighByte = FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_HIGH_BYTE;
53 dimspeedLowByte = FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_LOW_BYTE;
56 return new byte[] { command, channel, percentage, dimspeedHighByte, dimspeedLowByte };