-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RotateCmd.java
73 lines (57 loc) · 2.09 KB
/
RotateCmd.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
package io.github.blackspherefollower.buttplug4j.protocol.messages;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.blackspherefollower.buttplug4j.protocol.ButtplugConsts;
import io.github.blackspherefollower.buttplug4j.protocol.ButtplugDeviceMessage;
public final class RotateCmd extends ButtplugDeviceMessage {
@JsonProperty(value = "Rotations", required = true)
private RotateSubCmd[] rotations;
public RotateCmd(final long deviceIndex, final RotateSubCmd[] rotations, final long id) {
super(id, deviceIndex);
this.setRotations(rotations);
}
@SuppressWarnings("unused")
private RotateCmd() {
super(ButtplugConsts.DEFAULT_MSG_ID, -1);
}
public RotateSubCmd[] getRotations() {
return rotations;
}
public void setRotations(final RotateSubCmd[] rotations) {
this.rotations = rotations;
}
public static final class RotateSubCmd {
@JsonProperty(value = "Index", required = true)
private long index;
@JsonProperty(value = "Speed", required = true)
private double speed;
@JsonProperty(value = "Clockwise", required = true)
private boolean clockwise;
public RotateSubCmd(final long index, final double speed, final boolean clockwise) {
this.index = index;
this.clockwise = clockwise;
setSpeed(speed);
}
public RotateSubCmd() {
this.index = -1;
this.clockwise = true;
this.speed = 0;
}
public double getPosition() {
if (speed > 1 || speed < 0) {
return 0;
}
return speed;
}
public void setSpeed(final double speed) {
if (speed > 1) {
throw new IllegalArgumentException(
"Rotation speed cannot be greater than 1!");
}
if (speed < 0) {
throw new IllegalArgumentException(
"Rotation speed cannot be lower than 0!");
}
this.speed = speed;
}
}
}