]> git.basschouten.com Git - openhab-addons.git/blob
f26f536c57cd1e3c9948f198c6a81bf37b9995e9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.velbus.internal.packets;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velbus.internal.VelbusChannelIdentifier;
17
18 /**
19  * The {@link VelbusDimmerPacket} represents a Velbus packet that can be used to
20  * dim a light to a given percentage.
21  *
22  * @author Cedric Boon - Initial contribution
23  */
24 @NonNullByDefault
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;
28
29     private Boolean isFirstGenerationDevice;
30     private byte command;
31     private byte channel;
32     private byte percentage;
33     private int dimspeed;
34
35     public VelbusDimmerPacket(VelbusChannelIdentifier velbusChannelIdentifier, byte command, byte percentage,
36             int dimspeed, Boolean isFirstGenerationDevice) {
37         super(velbusChannelIdentifier.getAddress(), PRIO_HI);
38
39         this.channel = velbusChannelIdentifier.getChannelByte();
40         this.command = command;
41         this.percentage = percentage;
42         this.dimspeed = dimspeed;
43         this.isFirstGenerationDevice = isFirstGenerationDevice;
44     }
45
46     @Override
47     protected byte[] getDataBytes() {
48         byte dimspeedHighByte = (byte) ((dimspeed & 0xFF00) / 0x100);
49         byte dimspeedLowByte = (byte) (dimspeed & 0xFF);
50
51         if (dimspeed == 0 && isFirstGenerationDevice) {
52             dimspeedHighByte = FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_HIGH_BYTE;
53             dimspeedLowByte = FIRST_GENERATION_DEVICE_FASTEST_DIMSPEED_LOW_BYTE;
54         }
55
56         return new byte[] { command, channel, percentage, dimspeedHighByte, dimspeedLowByte };
57     }
58 }