-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndividualLightTest.java
More file actions
75 lines (61 loc) · 2.74 KB
/
IndividualLightTest.java
File metadata and controls
75 lines (61 loc) · 2.74 KB
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
package com.easternedgerobotics.rov.integration;
import com.easternedgerobotics.rov.config.LaunchConfig;
import com.easternedgerobotics.rov.config.MockLaunchConfig;
import com.easternedgerobotics.rov.event.BroadcastEventPublisher;
import com.easternedgerobotics.rov.event.EventPublisher;
import com.easternedgerobotics.rov.io.Light;
import com.easternedgerobotics.rov.io.pololu.Maestro;
import com.easternedgerobotics.rov.math.Range;
import com.easternedgerobotics.rov.value.SpeedValue;
import com.easternedgerobotics.rov.value.TestSpeedValue;
import com.pi4j.io.serial.Serial;
import com.pi4j.io.serial.SerialFactory;
import rx.broadcast.BasicOrder;
import rx.broadcast.UdpBroadcast;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
@SuppressWarnings({"checkstyle:magicnumber"})
public final class IndividualLightTest {
private IndividualLightTest() {
}
public static void main(final String[] args) throws
IOException,
InterruptedException,
SocketException,
UnknownHostException {
final LaunchConfig launchConfig = new MockLaunchConfig();
final byte deviceNumber = Byte.parseByte(args[0]);
final byte channel = Byte.parseByte(args[1]);
final int baudRate = launchConfig.baudRate();
final Serial serial = SerialFactory.createInstance();
serial.open(launchConfig.serialPort(), baudRate);
final InetAddress broadcastAddress = InetAddress.getByName(launchConfig.broadcast());
final int broadcastPort = launchConfig.defaultBroadcastPort();
final EventPublisher eventPublisher = new BroadcastEventPublisher(new UdpBroadcast<>(
new DatagramSocket(broadcastPort), broadcastAddress, broadcastPort, new BasicOrder<>()));
final Light light = new Light(
eventPublisher.valuesOfType(TestSpeedValue.class).cast(SpeedValue.class),
new Maestro<>(serial, deviceNumber).get(channel).setOutputRange(new Range(Light.MAX_REV, Light.MAX_FWD)));
System.out.println("Test Started");
System.out.println("Light is off");
Thread.sleep(1000);
eventPublisher.emit(new TestSpeedValue(.5f));
Thread.sleep(1000);
System.out.println("Light is at half brightness");
light.write();
eventPublisher.emit(new TestSpeedValue(0f));
Thread.sleep(1000);
System.out.println("Light is off");
light.write();
eventPublisher.emit(new TestSpeedValue(1f));
Thread.sleep(1000);
System.out.println("Light is at full brightness");
light.write();
Thread.sleep(1000);
System.out.println("Light is off");
light.writeZero();
}
}