-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScalarCmd.java
94 lines (74 loc) · 2.75 KB
/
ScalarCmd.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package io.github.blackspherefollower.buttplug4j.protocol.messages;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.blackspherefollower.buttplug4j.util.Pair;
import io.github.blackspherefollower.buttplug4j.protocol.ButtplugConsts;
import io.github.blackspherefollower.buttplug4j.protocol.ButtplugDeviceMessage;
import java.util.ArrayList;
public final class ScalarCmd extends ButtplugDeviceMessage {
@JsonProperty(value = "Scalars", required = true)
private ScalarSubCmd[] scalars;
public ScalarCmd(final long deviceIndex, final Pair<Double, String>[] scalars, final long id) {
super(id, deviceIndex);
long i = 0;
ArrayList<ScalarSubCmd> scalarsubs = new ArrayList<>();
for (Pair<Double, String> scalar : scalars) {
if (scalar != null) {
scalarsubs.add(new ScalarSubCmd(i, scalar.getLeft(), scalar.getRight()));
}
i++;
}
this.setScalars(scalarsubs.toArray(new ScalarSubCmd[]{}));
}
@SuppressWarnings("unused")
private ScalarCmd() {
super(ButtplugConsts.DEFAULT_MSG_ID, -1);
}
public ScalarSubCmd[] getScalars() {
return scalars;
}
public void setScalars(final ScalarSubCmd[] scalars) {
this.scalars = scalars;
}
public static final class ScalarSubCmd {
@JsonProperty(value = "Index", required = true)
private long index;
@JsonProperty(value = "Scalar", required = true)
private double scalar;
@JsonProperty(value = "ActuatorType", required = true)
private String actuatorType;
public ScalarSubCmd(final long index, final double scalar, final String actuatorType) {
this.setIndex(index);
this.setActuatorType(actuatorType);
setScalar(scalar);
}
public double getScalar() {
if (scalar > 1 || scalar < 0) {
return 0;
}
return scalar;
}
public void setScalar(final double scalar) {
if (scalar > 1) {
throw new IllegalArgumentException(
"Scalar values cannot be greater than 1!");
}
if (scalar < 0) {
throw new IllegalArgumentException(
"Scalar values cannot be lower than 0!");
}
this.scalar = scalar;
}
public long getIndex() {
return index;
}
public void setIndex(final long index) {
this.index = index;
}
public String getActuatorType() {
return actuatorType;
}
public void setActuatorType(final String actuatorType) {
this.actuatorType = actuatorType;
}
}
}