From 153efe59e1e90d35783ed9a2d324a3f5b5f1a7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?He=CC=81ctor=20Barreras=20Almarcha?= Date: Mon, 4 Jul 2016 15:24:52 +0200 Subject: [PATCH] Graphics working and everything. So cool. --- source/plotter.d | 36 +++++++++++++++++++++++------------- source/puppeteer_listener.d | 13 +++++++++++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/source/plotter.d b/source/plotter.d index 2b9c58f..379e2ce 100644 --- a/source/plotter.d +++ b/source/plotter.d @@ -7,25 +7,26 @@ import ggplotd.geom; import std.stdio; -class Plotter +struct Plotter { - private GGPlotD receivedPlot; - private GGPlotD adaptedPlot; + private GGPlotD receivedAIPlot; + private GGPlotD adaptedAIPlot; + + private GGPlotD receivedVarMonitorsPlot; + private GGPlotD adaptedVarMonitorsPlot; enum plotWidth = 1000; enum plotHeight = 800; - this() - { - - } - void savePlots() { writeln("Saving plots..."); - receivedPlot.save("received.png", plotWidth, plotHeight); - adaptedPlot.save("adapted.png", plotWidth, plotHeight); + receivedAIPlot.save("receivedAI.png", plotWidth, plotHeight); + adaptedAIPlot.save("adaptedAI.png", plotWidth, plotHeight); + + receivedVarMonitorsPlot.save("receivedVarMonitors.png", plotWidth, plotHeight); + adaptedVarMonitorsPlot.save("adaptedVarMonitors.png", plotWidth, plotHeight); writeln("Plots have been saved"); } @@ -40,12 +41,21 @@ class Plotter auto adaptedAes = Aes!(long[], "x", float[], "y", string, "colour") ([readTimeMSecs], [adaptedValue], pinColors[pin]); - receivedPlot.put(geomPoint(receivedAes)); - adaptedPlot.put(geomPoint(adaptedAes)); + receivedAIPlot.put(geomPoint(receivedAes)); + adaptedAIPlot.put(geomPoint(adaptedAes)); } - void addVarMonitorRead(T)(ubyte varIndex, T receivedValue, T adaptedValue, long mSecs) + void addVarMonitorRead(T : short)(ubyte varIndex, T receivedValue, T adaptedValue, long readTimeMSecs) { + enum pinColors = ["a", "b", "c", "d", "e", "f"]; + + auto receivedAes = Aes!(long[], "x", T[], "y", string, "colour") + ([readTimeMSecs], [receivedValue], pinColors[varIndex]); + + auto adaptedAes = Aes!(long[], "x", T[], "y", string, "colour") + ([readTimeMSecs], [adaptedValue], pinColors[varIndex]); + receivedVarMonitorsPlot.put(geomPoint(receivedAes)); + adaptedVarMonitorsPlot.put(geomPoint(adaptedAes)); } } diff --git a/source/puppeteer_listener.d b/source/puppeteer_listener.d index f0ab337..3c14697 100644 --- a/source/puppeteer_listener.d +++ b/source/puppeteer_listener.d @@ -26,19 +26,20 @@ public shared class PuppeteerListener public void varListener(T)(ubyte varIndex, T realValue, T adaptedValue, long mSecs) { - + drawer.send(DrawVarMonitorMessage!T(varIndex, realValue, adaptedValue, mSecs)); } } void drawLoop() { - Plotter plotter = new Plotter(); + Plotter plotter; bool shouldLoop = true; while(shouldLoop) { receive( (DrawAIMessage msg) {plotter.addAIRead(msg.pin, msg.realValue, msg.adaptedValue, msg.mSecs);}, + (DrawVarMonitorMessage!short msg) {plotter.addVarMonitorRead(msg.varIndex, msg.realValue, msg.adaptedValue, msg.mSecs);}, (int i) {if (i==0) shouldLoop = false;} ); } @@ -54,3 +55,11 @@ private struct DrawAIMessage float adaptedValue; long mSecs; } + +private struct DrawVarMonitorMessage(T) +{ + ubyte varIndex; + T realValue; + T adaptedValue; + long mSecs; +}