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.hdpowerview.internal.api;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * Shade coordinate system, as returned by the HD PowerView hub
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
25 * @author Andy Lintner - Initial contribution of the original enum called
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
33 public enum CoordinateSystem {
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
45 * The position element can take on multiple states depending on the family of
46 * shade under control.
48 * The ranges of position integer values are
52 * Shade fully up: (top-down: open, bottom-up: closed)
53 * posKind: 1 {ZERO_IS_CLOSED}
56 * Shade and vane fully down: (top-down: closed, bottom-up: open)
57 * posKind: 1 {ZERO_IS_CLOSED}
60 * ALTERNATE: Shade and vane fully down: (top-down: closed, bottom-up: open)
61 * posKind: 3 {VANE_COORDS}
64 * Shade fully down (closed) and vane fully up (open):
65 * posKind: 3 {VANE_COORDS}
68 * Dual action, secondary top-down shade fully up (closed):
69 * posKind: 2 {ZERO_IS_OPEN}
72 * Dual action, secondary top-down shade fully down (open):
73 * posKind: 2 {ZERO_IS_OPEN}
82 public static final int MAX_SHADE = 65535;
83 public static final int MAX_VANE = 32767;
86 * Converts an HD PowerView posKind integer value to a CoordinateSystem enum value
88 * @param posKind input integer value
89 * @return corresponding CoordinateSystem enum
91 public static CoordinateSystem fromPosKind(int posKind) {
94 return ZERO_IS_CLOSED;
100 return ERROR_UNKNOWN;
104 * Converts a CoordinateSystem enum to an HD PowerView posKind integer value
106 * @return the posKind integer value
108 public int toPosKind() {
109 return ordinal() + 1;