]> git.basschouten.com Git - openhab-addons.git/blob
78c9a740f9bb2f6da5588bf28fd02952533e1928
[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.onewire.internal.owserver;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link OwserverPressureScale} provides the owserver protocol pressure scale flags
19  *
20  * @author Jan N. Klug - Initial contribution
21  */
22
23 @NonNullByDefault
24 public enum OwserverPressureScale {
25     MILLIBAR(0x00000000),
26     ATM(0x00040000),
27     MMHG(0x00080000),
28     INHG(0x000C0000),
29     PSI(0x00100000),
30     PASCAL(0x00140000);
31
32     private static final int CLEAR_MASK = 0x001C0000;
33     private final int flag;
34
35     OwserverPressureScale(int flag) {
36         this.flag = flag;
37     }
38
39     /**
40      * get numeric value of this flag
41      *
42      * @return
43      */
44     public int getValue() {
45         return flag;
46     }
47
48     /**
49      * set this flag in a set of given flags
50      *
51      * @param flags aggregated flags
52      * @return parameter with this flag set
53      */
54     public int setFlag(int flags) {
55         return (flags & ~CLEAR_MASK) | this.getValue();
56     }
57
58     /**
59      * get the pressure scale flag from a given set of flags
60      *
61      * @param flags set of flags
62      * @return pressure scale flag
63      * @throws IllegalArgumentException
64      */
65     public static OwserverPressureScale getFlag(int flags) throws IllegalArgumentException {
66         for (OwserverPressureScale value : values()) {
67             if (value.getValue() == (flags & CLEAR_MASK)) {
68                 return value;
69             }
70         }
71         throw new IllegalArgumentException("Pressure scale flag not found");
72     }
73 }