2 * Copyright (c) 2010-2022 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.bluetooth.am43.internal.command;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.am43.internal.data.MotorSettings;
19 * The {@link SetSettingsCommand} sets the motor settings in bulk. There isn't a way to set them individually so before
20 * you can use this command you need to retrieve the existing commands with a {@link GetAllCommand}
22 * @author Connor Petty - Initial contribution
25 public class SetSettingsCommand extends AM43Command {
27 private static final byte COMMAND = (byte) 0x11;
29 public SetSettingsCommand(MotorSettings settings) {
30 super(COMMAND, createContent(settings));
33 private static byte[] createContent(MotorSettings motorSettings) {
34 @SuppressWarnings("null")
35 int direction = motorSettings.getDirection().toByte();
36 @SuppressWarnings("null")
37 int operationMode = motorSettings.getOperationMode().toByte();
38 int deviceType = motorSettings.getType();
39 int deviceLength = motorSettings.getLength();
40 int deviceSpeed = motorSettings.getSpeed();
41 int deviceDiameter = motorSettings.getDiameter();
43 int dataHead = ((direction & 1) << 1) | ((operationMode & 1) << 2) | (deviceType << 4);
45 return new byte[] { (byte) dataHead, (byte) deviceSpeed, 0, (byte) ((deviceLength & 0xFF00) >> 8),
46 (byte) (deviceLength & 0xFF), (byte) deviceDiameter };