]> git.basschouten.com Git - openhab-addons.git/blob
7c1d9f6df948c4d27bd60fef304ee0d980538933
[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.nuvo.internal.communication;
14
15 import static java.util.Map.entry;
16
17 import java.util.Map;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * Provides mapping of various Nuvo status codes to plain language meanings
23  *
24  * @author Michael Lobstein - Initial contribution
25  */
26
27 @NonNullByDefault
28 public class NuvoStatusCodes {
29     private static final String L = "L";
30     private static final String C = "C";
31     private static final String R = "R";
32     private static final String DASH = "-";
33     private static final String ZERO = "0";
34
35     // map to lookup play mode
36     public static final Map<String, String> PLAY_MODE = Map.ofEntries(entry("0", "Normal"), entry("1", "Idle"),
37             entry("2", "Playing"), entry("3", "Paused"), entry("4", "Fast Forward"), entry("5", "Rewind"),
38             entry("6", "Play Shuffle"), entry("7", "Play Repeat"), entry("8", "Play Shuffle Repeat"),
39             entry("9", "Step Tune"), entry("10", "Seek Tune"), entry("11", "Preset Tune"), entry("12", "unknown-12"));
40
41     // map to lookup button action name from NuvoNet button code
42     public static final Map<String, String> BUTTON_CODE = Map.ofEntries(entry("1", "OK"), entry("2", "PLAYPAUSE"),
43             entry("3", "PREV"), entry("4", "NEXT"), entry("5", "POWERMUTE"), // source will not receive this
44             entry("6", "UP"), // source will not receive this
45             entry("7", "DOWN"), // source will not receive this
46             entry("41", "DISCRETEPLAYPAUSE"), entry("42", "DISCRETENEXTTRACK"), entry("43", "DISCRETEPREVIOUSTRACK"),
47             entry("44", "SHUFFLETOGGLE"), entry("45", "REPEATTOGGLE"), entry("46", "TUNEUP"), entry("47", "TUNEDOWN"),
48             entry("48", "SEEKUP"), entry("49", "SEEKDOWN"), entry("50", "PRESETUP"), entry("51", "PRESETDOWN"),
49             entry("52", "DIRECTFREQUENCYENTRY"), entry("53", "DIRECTPRESETENTRY"), entry("54", "NEXTBAND"),
50             entry("55", "THUMBSUP"), entry("56", "THUMBSDOWN"));
51
52     /*
53      * This looks broken because the controller is seriously broken...
54      * On the keypad when adjusting the balance to "Left 18", the serial data reports R18 ¯\_(ツ)_/¯
55      * So on top of the weird translation, the value needs to be reversed by the binding
56      * to ensure that it will match what is displayed on the keypad.
57      * For display purposes we want -18 to be full left, 0 = center, and +18 to be full right
58      */
59     public static String getBalanceFromStr(String value) {
60         // example L2; return 2 | C; return 0 | R10; return -10
61         if (value.substring(0, 1).equals(L)) {
62             return (value.substring(1));
63         } else if (value.equals(C)) {
64             return ZERO;
65         } else if (value.substring(0, 1).equals(R)) {
66             return (DASH + value.substring(1));
67         }
68         return ZERO;
69     }
70
71     // see above comment
72     public static String getBalanceFromInt(Integer value) {
73         if (value < 0) {
74             return (L + Math.abs(value));
75         } else if (value == 0) {
76             return C;
77         } else if (value > 0) {
78             return (R + value);
79         }
80         return C;
81     }
82 }