Skip to content

Commit

Permalink
Graphics working and everything. So cool.
Browse files Browse the repository at this point in the history
  • Loading branch information
Héctor Barreras Almarcha committed Jul 4, 2016
1 parent 81bc267 commit 153efe5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
36 changes: 23 additions & 13 deletions source/plotter.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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));
}
}
13 changes: 11 additions & 2 deletions source/puppeteer_listener.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
);
}
Expand All @@ -54,3 +55,11 @@ private struct DrawAIMessage
float adaptedValue;
long mSecs;
}

private struct DrawVarMonitorMessage(T)
{
ubyte varIndex;
T realValue;
T adaptedValue;
long mSecs;
}

0 comments on commit 153efe5

Please sign in to comment.