Skip to content

Commit

Permalink
Committing so I can work remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
Héctor Barreras Almarcha committed Jul 3, 2016
1 parent 374de96 commit 81bc267
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 15 deletions.
27 changes: 27 additions & 0 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ void main(string[] args)

mainWindow.show();
Main.run();

controller.disconnect();
}

void initUI()
Expand Down Expand Up @@ -198,6 +200,7 @@ void configureUI()
}
);

configureWindows();
configurePuppeteerConfigWindow();
//TODO: these default values will have to do by now
configurePWMOutputListBox(10);
Expand All @@ -210,6 +213,30 @@ void configureUI()
debug writeln("Done configuring UI");
}

void configureWindows()
{
import gdk.Event;
import gtk.Widget;

mainWindow.addOnDelete(
(Event e, Widget w)
{
Main.quit();
return false;
}
);

auto hideWindowDelegate = delegate bool(Event e, Widget w)
{
w.hide();
return true;
};

puppeteerConfigWindow.addOnDelete(hideWindowDelegate);
loadPuppeteerConfigDialog.addOnDelete(hideWindowDelegate);
savePuppeteerConfigDialog.addOnDelete(hideWindowDelegate);
}

void configurePWMOutputListBox(int entries)
{
PWMOutputListBox.removeAll();
Expand Down
51 changes: 51 additions & 0 deletions source/plotter.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module plotter;

import ggplotd.ggplotd;
import ggplotd.aes;
import ggplotd.geom;

import std.stdio;


class Plotter
{
private GGPlotD receivedPlot;
private GGPlotD adaptedPlot;

enum plotWidth = 1000;
enum plotHeight = 800;

this()
{

}

void savePlots()
{
writeln("Saving plots...");

receivedPlot.save("received.png", plotWidth, plotHeight);
adaptedPlot.save("adapted.png", plotWidth, plotHeight);

writeln("Plots have been saved");
}

void addAIRead(ubyte pin, float receivedValue, float adaptedValue, long readTimeMSecs)
{
enum pinColors = ["a", "b", "c", "d", "e", "f"];

auto receivedAes = Aes!(long[], "x", float[], "y", string, "colour")
([readTimeMSecs], [receivedValue], pinColors[pin]);

auto adaptedAes = Aes!(long[], "x", float[], "y", string, "colour")
([readTimeMSecs], [adaptedValue], pinColors[pin]);

receivedPlot.put(geomPoint(receivedAes));
adaptedPlot.put(geomPoint(adaptedAes));
}

void addVarMonitorRead(T)(ubyte varIndex, T receivedValue, T adaptedValue, long mSecs)
{

}
}
6 changes: 5 additions & 1 deletion source/puppeteer_controller.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public class PuppeteerController

void disconnect()
{
puppeteer.endCommunication();
if(isPuppeteerConnected)
{
puppeteer.endCommunication();
listener.finish();
}
}

void setPWM(ubyte pin, ubyte value)
Expand Down
14 changes: 0 additions & 14 deletions source/puppeteer_gui/puppeteer_listener.d

This file was deleted.

56 changes: 56 additions & 0 deletions source/puppeteer_listener.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module puppeteer_listener;

import plotter;

import std.concurrency;
import std.stdio;

public shared class PuppeteerListener
{
__gshared Tid drawer;

this()
{
drawer = spawn(&drawLoop);
}

public void finish()
{
drawer.send(cast(int)0);
}

public void AIListener(ubyte pin, float realValue, float adaptedValue, long mSecs)
{
drawer.send(DrawAIMessage(pin, realValue, adaptedValue, mSecs));
}

public void varListener(T)(ubyte varIndex, T realValue, T adaptedValue, long mSecs)
{

}
}

void drawLoop()
{
Plotter plotter = new Plotter();

bool shouldLoop = true;
while(shouldLoop)
{
receive(
(DrawAIMessage msg) {plotter.addAIRead(msg.pin, msg.realValue, msg.adaptedValue, msg.mSecs);},
(int i) {if (i==0) shouldLoop = false;}
);
}

writeln("Finishing drawLoop");
plotter.savePlots();
}

private struct DrawAIMessage
{
ubyte pin;
float realValue;
float adaptedValue;
long mSecs;
}

0 comments on commit 81bc267

Please sign in to comment.