displaying data

This commit is contained in:
Dani The Skunk 2022-10-24 22:59:17 +00:00
parent d79f599108
commit 4e1268445a
3 changed files with 112 additions and 0 deletions

BIN
fonts/ega-16x28.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -0,0 +1,25 @@
package com.skunkworks;
public class Parameter {
private final String identifier;
private final String name;
private final double value;
public Parameter(String identifier, String name, double value) {
this.identifier = identifier;
this.name = name;
this.value = value;
}
public String getIdentifier() {
return identifier;
}
public String getName() {
return name;
}
public double getValue() {
return value;
}
}

View File

@ -2,10 +2,97 @@ package com.skunkworks;
import com.danitheskunk.skunkworks.BaseGame;
import com.danitheskunk.skunkworks.Vec2i;
import com.danitheskunk.skunkworks.gfx.Color;
import com.danitheskunk.skunkworks.gfx.IRenderContext;
import com.danitheskunk.skunkworks.gfx.vt.Terminal;
import java.awt.image.renderable.RenderContext;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
public class SkunkMeter extends BaseGame {
Terminal term;
double nextSecond;
public SkunkMeter() {
super(new Vec2i(1280, 720), "SkunkMeter v0.0");
term = new Terminal(new Vec2i(80, 25),
window.loadFontTileset("fonts/ega-16x28.png")
);
System.out.println(getData());
var data = processData(getData());
nextSecond = 0.0;
}
public static String getData() {
var pb = new ProcessBuilder("powershell.exe",
"-Command",
"Get-CimInstance -namespace root\\LibreHardwareMonitor -class " +
"Sensor | Out-String -Stream -Width 1000"
);
try {
var p = pb.start();
var bis = new BufferedInputStream(p.getInputStream());
var buf = new ByteArrayOutputStream();
for(int result = bis.read(); result != -1; result = bis.read()) {
buf.write((byte) result);
}
return buf.toString(StandardCharsets.UTF_8);
} catch(IOException e) {
throw new RuntimeException(e);
}
}
public HashMap<String, Parameter> processData(String in) {
var elems = in.split("\r\n\r\n");
//skip first empty element
var elemsParsed = new HashMap<String, Parameter>();
for(int i = 1; i < elems.length; ++i) {
var elem = elems[i].split("\r\n");
String identifier = "";
String name = "";
double value = 0.0;
for(var par : elem) {
var kv = par.split("\s*:\s*");
switch(kv[0]) {
case "Identifier":
identifier = kv[1];
break;
case "Name":
name = kv[1];
break;
case "Value":
value = Double.parseDouble(kv[1]);
break;
}
}
elemsParsed.put(identifier, new Parameter(identifier, name, value));
}
return elemsParsed;
}
@Override
protected void render(IRenderContext rc) {
rc.drawTerminal(term);
}
@Override
protected void update(double delta) {
nextSecond -= delta;
if(nextSecond <= 0.0) {
var data = processData(getData());
term.clear(Color.BLACK);
var cpuPackage = data.get("/intelcpu/0/temperature/4");
term.drawString(new Vec2i(0, 0), cpuPackage.getName() + ":");
term.drawString(new Vec2i(15, 0),
String.valueOf(cpuPackage.getValue()) + "C");
nextSecond += 1.0;
}
super.update(delta);
}
public static void main(String[] args) {