]> git.basschouten.com Git - openhab-addons.git/blob
d715279196bd7367fbdbcb25403e7d79c7d4ae44
[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.lifx.internal.fields;
14
15 import java.nio.ByteBuffer;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * @author Wouter Born - Initial contribution
21  */
22 @NonNullByDefault
23 public class HSBKField extends Field<HSBK> {
24
25     public static final Field<Integer> FIELD_HUE = new UInt16Field().little();
26     public static final Field<Integer> FIELD_SATURATION = new UInt16Field().little();
27     public static final Field<Integer> FIELD_BRIGHTNESS = new UInt16Field().little();
28     public static final Field<Integer> FIELD_KELVIN = new UInt16Field().little();
29
30     @Override
31     public int defaultLength() {
32         return 8;
33     }
34
35     @Override
36     public HSBK value(ByteBuffer bytes) {
37         int hue = FIELD_HUE.value(bytes);
38         int saturation = FIELD_SATURATION.value(bytes);
39         int brightness = FIELD_BRIGHTNESS.value(bytes);
40         int kelvin = FIELD_KELVIN.value(bytes);
41
42         return new HSBK(hue, saturation, brightness, kelvin);
43     }
44
45     @Override
46     protected ByteBuffer bytesInternal(HSBK value) {
47         return ByteBuffer.allocate(defaultLength()).put(FIELD_HUE.bytes(value.getHue()))
48                 .put(FIELD_SATURATION.bytes(value.getSaturation())).put(FIELD_BRIGHTNESS.bytes(value.getBrightness()))
49                 .put(FIELD_KELVIN.bytes(value.getKelvin()));
50     }
51 }