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.lifx.internal.fields;
15 import java.nio.ByteBuffer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * @author Wouter Born - Initial contribution
23 public class HSBKField extends Field<HSBK> {
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();
31 public int defaultLength() {
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);
42 return new HSBK(hue, saturation, brightness, kelvin);
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()));