]> git.basschouten.com Git - openhab-addons.git/blob
c9e90e3472198ae9e4b81834dc18f4e0b61e9994
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.hdpowerview.internal.api;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * Shade coordinate system, as returned by the HD PowerView hub
19  * 
20  * @param ZERO_IS_CLOSED coordinate value 0 means shade is closed
21  * @param ZERO_IS_OPEN coordinate value 0 means shade is open
22  * @param VANE_COORDS coordinate system for vanes
23  * @param ERROR_UNKNOWN unsupported coordinate system
24  *
25  * @author Andy Lintner - Initial contribution of the original enum called
26  *         ShadePositionKind
27  * 
28  * @author Andrew Fiddian-Green - Rewritten as a new enum called
29  *         CoordinateSystem to support secondary rail positions and be more
30  *         explicit on coordinate directions and ranges
31  */
32 @NonNullByDefault
33 public enum CoordinateSystem {
34     /*-
35      * Specifies the coordinate system used for the position of the shade. Top-down
36      * shades are in the same coordinate space as bottom-up shades. Shade position
37      * values for top-down shades would be reversed for bottom-up shades. For
38      * example, since 65535 is the open value for a bottom-up shade, it is the
39      * closed value for a top-down shade. The top-down/bottom-up shade is different
40      * in that instead of the top and bottom rail operating in one coordinate space
41      * like the top-down and the bottom-up, it operates in two where the top
42      * (middle) rail closed value is 0 and the bottom (primary) rail closed position
43      * is also 0 and fully open for both is 65535
44      * 
45      * The position element can take on multiple states depending on the family of
46      * shade under control.
47      *
48      * The ranges of position integer values are 
49      *      shades: 0..65535
50      *      vanes: 0..32767
51      * 
52      * Shade fully up: (top-down: open, bottom-up: closed) 
53      *      posKind: 1 {ZERO_IS_CLOSED} 
54      *      position: 65535
55      *
56      * Shade and vane fully down: (top-down: closed, bottom-up: open) 
57      *      posKind: 1 {ZERO_IS_CLOSED}
58      *      position1: 0
59      * 
60      * ALTERNATE: Shade and vane fully down: (top-down: closed, bottom-up: open)
61      *      posKind: 3 {VANE_COORDS}
62      *      position: 0
63      *
64      * Shade fully down (closed) and vane fully up (open): 
65      *      posKind: 3 {VANE_COORDS}
66      *      position: 32767
67      *
68      * Dual action, secondary top-down shade fully up (closed): 
69      *      posKind: 2 {ZERO_IS_OPEN}
70      *      position: 0
71      *      
72      * Dual action, secondary top-down shade fully down (open): 
73      *      posKind: 2 {ZERO_IS_OPEN}
74      *      position: 65535
75      *      
76      */
77     ZERO_IS_CLOSED,
78     ZERO_IS_OPEN,
79     VANE_COORDS,
80     ERROR_UNKNOWN;
81
82     public static final int MAX_SHADE = 65535;
83     public static final int MAX_VANE = 32767;
84
85     /**
86      * Converts an HD PowerView posKind integer value to a CoordinateSystem enum value
87      * 
88      * @param posKind input integer value
89      * @return corresponding CoordinateSystem enum
90      */
91     public static CoordinateSystem fromPosKind(int posKind) {
92         switch (posKind) {
93             case 1:
94                 return ZERO_IS_CLOSED;
95             case 2:
96                 return ZERO_IS_OPEN;
97             case 3:
98                 return VANE_COORDS;
99         }
100         return ERROR_UNKNOWN;
101     }
102
103     /**
104      * Converts a CoordinateSystem enum to an HD PowerView posKind integer value
105      * 
106      * @return the posKind integer value
107      */
108     public int toPosKind() {
109         return ordinal() + 1;
110     }
111 }