]> git.basschouten.com Git - openhab-addons.git/blob
30e4c9c798b0494b1c16b40a891848972a028cfd
[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.milight.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.milight.internal.MilightThingState;
17 import org.openhab.binding.milight.internal.protocol.QueueItem;
18 import org.openhab.binding.milight.internal.protocol.QueuedSend;
19 import org.openhab.core.thing.Thing;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * This class implements common functionality for Milight/Easybulb bulbs of protocol version 3.
25  * Most of the implementation is found in the specific bulb classes though.
26  * The class is state-less, use {@link MilightThingState} instead.
27  *
28  * @author David Graeff - Initial contribution
29  */
30 @NonNullByDefault
31 public abstract class AbstractLedV3Handler extends AbstractLedHandler {
32     public static final int MAX_ANIM_MODES = 10;
33     protected final Logger logger = LoggerFactory.getLogger(AbstractLedV3Handler.class);
34
35     public AbstractLedV3Handler(Thing thing, QueuedSend sendQueue, int typeOffset) {
36         super(thing, sendQueue, typeOffset);
37     }
38
39     // we have to map [0,360] to [0,0xFF], where red equals hue=0 and the milight color 0xB0 (=176)
40     public static byte makeColor(int hue) {
41         int mHue = (360 + 248 - hue) % 360; // invert and shift
42         return (byte) (mHue * 255 / 360); // map to 256 values
43     }
44
45     @Override
46     public void setLedMode(int mode, MilightThingState state) {
47         // Not supported
48     }
49
50     @Override
51     public void setSaturation(int value, MilightThingState state) {
52         // Not supported
53     }
54
55     @Override
56     public void changeSaturation(int relativeSaturation, MilightThingState state) {
57         // Not supported
58     }
59
60     protected QueueItem createRepeatable(byte[] data) {
61         return QueueItem.createRepeatable(socket, delayTimeMS, repeatTimes, address, port, data);
62     }
63
64     protected QueueItem createRepeatable(int uidc, byte[] data) {
65         return new QueueItem(socket, uidc, data, true, delayTimeMS, repeatTimes, address, port);
66     }
67
68     protected QueueItem createNonRepeatable(byte[] data) {
69         return QueueItem.createNonRepeatable(socket, delayTimeMS, address, port, data);
70     }
71 }