add analog clock visualization

This commit is contained in:
Felix Klenner 2021-08-11 18:53:17 +02:00
parent 286d0f8a47
commit dfa91904e0
6 changed files with 86 additions and 13 deletions

View file

@ -4,19 +4,15 @@ import de.zuim.ledcontrol.effects.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
public class EffectManager {
private boolean sweep = false;
private final LEDEffect[] effects = new LEDEffect[]{new ClockEffect(), new NetworkSpeedEffect(), new AudioVolumeEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
private final LEDEffect[] effects = new LEDEffect[]{new AnalogClockEffect(), new ClockEffect(), new NetworkSpeedEffect(), new AudioVolumeEffect(), new SineEffect(), new AudioFFTEffect(), new ColorSweepEffect()};
private int activeId = 0;
private final TrayIcon trayIcon;

View file

@ -13,12 +13,10 @@ import java.nio.charset.StandardCharsets;
public class LEDControl {
public static final int WIDTH = 32;
public static final int HEIGHT = 16;
public static final int LED_NUM = WIDTH * HEIGHT;
public static final int BAUD = 1000000;
private static final int FRAME_MS = 40;
private static final int FRAME_MS = 20;
private static final String SERIAL_NAME = "CH340";
private SerialPort port;
private final byte[][][] leds = new byte[WIDTH][HEIGHT][3];
private final EffectManager eff;

View file

@ -0,0 +1,68 @@
package de.zuim.ledcontrol.effects;
import de.zuim.ledcontrol.LEDEffect;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import static de.zuim.ledcontrol.LEDControl.HEIGHT;
import static de.zuim.ledcontrol.LEDControl.WIDTH;
public class AnalogClockEffect implements LEDEffect {
@Override
public String getDescription() {
return "Analog Clock";
}
//private int WIDTH = HEIGHT;
long ns = 0;
boolean upperPart = false;
public void render(long timeDelta, Graphics g) {
//fontSwitcher();
Calendar time = Calendar.getInstance();
double ms = time.get(Calendar.MILLISECOND) / 1000.;
double sec = time.get(Calendar.SECOND) / 60.;
double min = time.get(Calendar.MINUTE) / 60.;
double hour = time.get(Calendar.HOUR_OF_DAY) / 24.;
/*g.setColor(new Color(1,1,1));
g.setFont(new Font("Calibri", Font.BOLD, 19 * getScale()));
g.drawString(""+time.get(Calendar.SECOND),6,HEIGHT-2);*/
//g.setColor(new Color(1,0,0));
//g.fillArc(0,0,WIDTH-1,HEIGHT-1,0,360);
//g.setColor(new Color(1,1,1));
//g.drawArc(0,0,WIDTH-1,HEIGHT-1,0,360);
for(int i=0; i<12; i++){
drawHand(i/12.0, 0, new Color(1, 1, 1), g,true);
}
//drawHand(ms, 5, new Color(0, 1, 1), g,false);
drawHand(sec, 2, new Color(4, 0, 0), g,false);
drawHand(min, 3, new Color(0, 4, 0), g,false);
drawHand(hour, 4, new Color(0, 0, 4), g,false);
}
private void drawHand(double pos, int offset, Color color, Graphics g, boolean marker){
pos = (pos+0.75) * 2 * Math.PI;
int x = (int) Math.round(((WIDTH-1) / 2. - offset) * Math.cos(pos) + (WIDTH-1) / 2.);
int y = (int) Math.round(((HEIGHT-1) / 2. - offset) * Math.sin(pos) + (HEIGHT-1) / 2.);
g.setColor(color);
if(!marker) {
g.drawLine(WIDTH / 2, HEIGHT / 2, x , y);
g.setColor(color.brighter().brighter().brighter());
}
g.drawRect(x, y, 0, 0);
}
}

View file

@ -27,7 +27,7 @@ public abstract class AudioEffect implements LEDEffect {
Mixer m = AudioSystem.getMixer(mixerInfo);
Line.Info[] lines = m.getTargetLineInfo();
System.out.println(mixerInfo);
//System.out.println(mixerInfo);
for (Line.Info li : lines) {
try {
@ -46,10 +46,10 @@ public abstract class AudioEffect implements LEDEffect {
DataLine.Info targetLineInfo = (DataLine.Info) availableTargetLines.get(0);
System.out.println("SUPPORTED TARGET FORMATS: ");
//System.out.println("SUPPORTED TARGET FORMATS: ");
AudioFormat[] formats = (targetLineInfo).getFormats();
for (int i = 0; i < formats.length; i++) {
System.out.println("(" + i + ")" + formats[i]);
//System.out.println("(" + i + ")" + formats[i]);
}
AudioFormat format = formats[formats.length > 10 ? 64 : 2];

View file

@ -21,7 +21,7 @@ public class ColorSweepEffect implements LEDEffect {
if (step > 1)
step = 0;
gr.setColor(Color.getHSBColor(step, 1f, 5f / 255f));
gr.setColor(Color.getHSBColor(step, 1f, 6f / 255f));
gr.fillRect(0, 0, WIDTH, HEIGHT);
}
}

View file

@ -1,5 +1,6 @@
package de.zuim.ledcontrol.effects;
import de.zuim.ledcontrol.LEDControl;
import de.zuim.ledcontrol.LEDEffect;
import oshi.SystemInfo;
import oshi.hardware.*;
@ -16,6 +17,7 @@ public class NetworkSpeedEffect implements LEDEffect {
private static final int MAX_UPLOAD_MBIT_S = 290;
private static final int MAX_DOWNLOAD_MBIT_S = 500;
private static final long NANOS_PER_PIXEL = 1000000000;
private static final String NETWORK_NAME = "Realtek";
@Override
public String getDescription() {
@ -29,7 +31,16 @@ public class NetworkSpeedEffect implements LEDEffect {
if (network == null) {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
network = hal.getNetworkIFs().get(0);
for(NetworkIF net : hal.getNetworkIFs()){
//System.out.println(net.getDisplayName());
if(net.getDisplayName().contains(NETWORK_NAME))
network = net;
}
if(network == null)
System.err.println("Network name not configured or \""+NETWORK_NAME+"\" not found.");
else
System.out.println("Using network adapter: "+network.getDisplayName());
}
}