]> git.basschouten.com Git - openhab-addons.git/blob
4f44b4ba60c7b5e2081083d64170fb17f41c84d5
[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.bluetooth.bluegiga.internal.enumeration;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * Class to implement the BlueGiga Enumeration <b>GapConnectableMode</b>.
20  * <p>
21  * GAP connectable modes
22  * <p>
23  * Note that this code is autogenerated. Manual changes may be overwritten.
24  *
25  * @author Chris Jackson - Initial contribution of Java code generator
26  */
27 public enum GapConnectableMode {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Not connectable
35      */
36     GAP_NON_CONNECTABLE(0x0000),
37
38     /**
39      * [1] Directed Connectable
40      */
41     GAP_DIRECTED_CONNECTABLE(0x0001),
42
43     /**
44      * [2] Undirected connectable
45      */
46     GAP_UNDIRECTED_CONNECTABLE(0x0002),
47
48     /**
49      * [3] Same as non-connectable, but also supports ADV_SCAN_IND packets. Device accepts scan
50      * requests (active scanning) but is not connectable.
51      */
52     GAP_SCANNABLE_NON_CONNECTABLE(0x0003);
53
54     /**
55      * A mapping between the integer code and its corresponding type to
56      * facilitate lookup by code.
57      */
58     private static Map<Integer, GapConnectableMode> codeMapping;
59
60     private int key;
61
62     private GapConnectableMode(int key) {
63         this.key = key;
64     }
65
66     private static void initMapping() {
67         codeMapping = new HashMap<>();
68         for (GapConnectableMode s : values()) {
69             codeMapping.put(s.key, s);
70         }
71     }
72
73     /**
74      * Lookup function based on the type code. Returns null if the code does not exist.
75      *
76      * @param gapConnectableMode
77      *            the code to lookup
78      * @return enumeration value.
79      */
80     public static GapConnectableMode getGapConnectableMode(int gapConnectableMode) {
81         if (codeMapping == null) {
82             initMapping();
83         }
84
85         if (codeMapping.get(gapConnectableMode) == null) {
86             return UNKNOWN;
87         }
88
89         return codeMapping.get(gapConnectableMode);
90     }
91
92     /**
93      * Returns the BlueGiga protocol defined value for this enum
94      *
95      * @return the BGAPI enumeration key
96      */
97     public int getKey() {
98         return key;
99     }
100 }