]> git.basschouten.com Git - openhab-addons.git/blob
7c2c7572c6f48ce51bdd6c707a33465910c194b6
[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.VelbusBindingConstants;
17 import org.openhab.binding.velbus.internal.VelbusChannelIdentifier;
18
19 /**
20  * The {@link VelbusButtonPacket} represents a Velbus packet that can be used to
21  * simulate a pushed button.
22  *
23  * @author Daniel Rosengarten - Initial contribution
24  */
25 @NonNullByDefault
26 public class VelbusButtonPacket extends VelbusPacket {
27     private byte channel;
28     private byte[] data;
29
30     public VelbusButtonPacket(VelbusChannelIdentifier velbusChannelIdentifier) {
31         super(velbusChannelIdentifier.getAddress(), PRIO_HI, false);
32
33         this.channel = velbusChannelIdentifier.getChannelByte();
34         this.data = new byte[] { VelbusBindingConstants.COMMAND_PUSH_BUTTON_STATUS, (byte) 0x00, (byte) 0x00,
35                 (byte) 0x00 };
36     }
37
38     public void Pressed() {
39         data = new byte[] { VelbusBindingConstants.COMMAND_PUSH_BUTTON_STATUS, channel, (byte) 0x00, (byte) 0x00 };
40     }
41
42     public void LongPressed() {
43         data = new byte[] { VelbusBindingConstants.COMMAND_PUSH_BUTTON_STATUS, (byte) 0x00, (byte) 0x00, channel };
44     }
45
46     public void Released() {
47         data = new byte[] { VelbusBindingConstants.COMMAND_PUSH_BUTTON_STATUS, (byte) 0x00, channel, (byte) 0x00 };
48     }
49
50     @Override
51     protected byte[] getDataBytes() {
52         return data;
53     }
54 }