2 * Copyright (c) 2010-2023 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.milight.internal.handler;
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;
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.
28 * @author David Graeff - Initial contribution
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);
35 public AbstractLedV3Handler(Thing thing, QueuedSend sendQueue, int typeOffset) {
36 super(thing, sendQueue, typeOffset);
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
46 public void setLedMode(int mode, MilightThingState state) {
51 public void setSaturation(int value, MilightThingState state) {
56 public void changeSaturation(int relativeSaturation, MilightThingState state) {
60 protected QueueItem createRepeatable(byte[] data) {
61 return QueueItem.createRepeatable(socket, delayTimeMS, repeatTimes, address, port, data);
64 protected QueueItem createRepeatable(int uidc, byte[] data) {
65 return new QueueItem(socket, uidc, data, true, delayTimeMS, repeatTimes, address, port);
68 protected QueueItem createNonRepeatable(byte[] data) {
69 return QueueItem.createNonRepeatable(socket, delayTimeMS, address, port, data);