2 * Copyright (c) 2010-2021 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.bluetooth.enoceanble.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link EnoceanBlePtm215Event} class is parsing the BLE manufacturer data into an event object.
20 * @author Patrick Fink - Initial contribution
23 public class EnoceanBlePtm215Event {
25 private static final byte PRESSED = 0x1;
27 private static final byte BUTTON1_DIR1 = 0x10;
28 private static final byte BUTTON1_DIR2 = 0x8;
29 private static final byte BUTTON2_DIR1 = 0x4;
30 private static final byte BUTTON2_DIR2 = 0x2;
32 private final byte byteState;
34 public EnoceanBlePtm215Event(byte[] manufacturerData) {
35 byteState = manufacturerData[6];
38 public boolean isPressed() {
39 return checkFlag(PRESSED);
42 public boolean isButton1() {
43 return checkFlag(BUTTON1_DIR1) || checkFlag(BUTTON1_DIR2);
46 public boolean isButton2() {
47 return checkFlag(BUTTON2_DIR1) || checkFlag(BUTTON2_DIR2);
50 public boolean isDir1() {
51 return checkFlag(BUTTON1_DIR1) || checkFlag(BUTTON2_DIR1);
54 public boolean isDir2() {
55 return checkFlag(BUTTON1_DIR2) || checkFlag(BUTTON2_DIR2);
58 private boolean checkFlag(int flag) {
59 return (byteState & flag) == flag;
63 public String toString() {
64 return "Button " + (isButton1() ? 1 : 2) + " Dir " + (isDir1() ? 1 : 2) + " "
65 + (isPressed() ? "PRESSED" : "RELEASED");