Added 1 led and testColors().

This commit is contained in:
Mathieu 2020-10-10 10:31:55 +02:00
parent 22e688c24e
commit 29abdfc4e4

View File

@ -2,6 +2,8 @@ package ch.mathieubroillet.leds;
import ch.mathieubroillet.leds.utils.Logger;
import java.awt.*;
import java.util.ArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -11,7 +13,8 @@ public class Main {
private static final String RASPBERRY_IP = "192.168.1.136";
private static final String TOURMATHIEU_IP = "192.168.1.130";
private static final Led[] LEDS = {
new Led("192.168.1.134", TOURMATHIEU_IP, "LED_BUREAU")
new Led("192.168.1.134", TOURMATHIEU_IP, "LED_BUREAU"),
new Led("192.168.1.219", TOURMATHIEU_IP, "LED_LIT")
};
private static final int MAX_RETRY = 2;
@ -23,15 +26,15 @@ public class Main {
scheduledExecutorService.scheduleAtFixedRate(() -> {
for (Led led : LEDS) {
//if led is offline then stop.
//If led is offline then stop.
if (!led.isConnectedToNetwork()) {
return;
Logger.warn(led.getName() + " isn't connected to the network.");
break;
}
//Check if the target machine (the machine which needs to be on to power on the led) is ON.
if (led.isTargetMachineIsOn()) {
//if led is off, then turn it on
if (led.isTargetMachineOn()) {
if (!led.isOn()) {
led.turnOn();
Logger.info("Turning ON " + led.getName());
@ -54,6 +57,39 @@ public class Main {
}
}
}, 0, 20, TimeUnit.SECONDS);
}, 0, 10, TimeUnit.SECONDS);
}
public void testColors() {
ArrayList<Color> colors = new ArrayList<Color>();
colors.add(new Color(0xFFFF00));
colors.add(new Color(0xFF6700));
colors.add(new Color(0xFF0000));
colors.add(new Color(0xFF0080));
colors.add(new Color(0xFF00FF));
colors.add(new Color(0x8200FF));
colors.add(new Color(0x0031FF));
colors.add(new Color(0x0089FF));
colors.add(new Color(0x00f1ff));
colors.add(new Color(0x00FF76));
colors.add(new Color(0x00C700));
colors.add(new Color(0x00FF00));
new Thread(() -> {
while (true) {
colors.forEach(color -> {
LedsUtils.setColor(LEDS[0].getIp(), color);
LedsUtils.setColor(LEDS[1].getIp(), color);
try {
TimeUnit.SECONDS.sleep((long) 0.5);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
}).start();
}
}