From 374de96dc440d798988e542ffecc7d7e01885eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Barreras=20Almarcha?= Date: Sun, 3 Jul 2016 13:27:43 +0200 Subject: [PATCH] Puppeteer communication, configuration and monitoring now supported. --- dub.json | 5 +- dub.selections.json | 4 +- resources/puppeteer_gui.glade | 426 ++++++++++--------- source/app.d | 472 +++++++++++++++++++++- source/puppeteer_controller.d | 89 ++++ source/puppeteer_gui/gui/gtkd/wrapper.d | 17 + source/puppeteer_gui/gui/igui.d | 13 +- source/puppeteer_gui/puppeteer_listener.d | 14 + 8 files changed, 847 insertions(+), 193 deletions(-) create mode 100644 source/puppeteer_controller.d create mode 100644 source/puppeteer_gui/puppeteer_listener.d diff --git a/dub.json b/dub.json index 956ca1d..57c9c34 100644 --- a/dub.json +++ b/dub.json @@ -6,13 +6,12 @@ "license": "GPL-3.0", "dependencies" : { - "puppeteer" : "~>0.6.0", - "gtk-d": "~>3.3.1", + "puppeteer" : "~>0.7.0", "ggplotd": "~>0.9.4" }, "subConfigurations": { - + "ggplotd": "ggplotd-gtk" }, "targetPath" : "out" diff --git a/dub.selections.json b/dub.selections.json index dae6cbf..947efff 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -4,10 +4,10 @@ "arith-eval": "0.4.0", "painlesstraits": "0.2.0", "cairod": "0.0.1-alpha.3+1.10.2", - "gtk-d": "3.3.1", + "gtk-d": "3.2.3", "x11": "1.0.14", "derelict-ft": "1.0.2", - "puppeteer": "0.6.0", + "puppeteer": "0.7.0", "ggplotd": "0.9.4", "pegged": "0.3.2", "derelict-util": "2.0.6", diff --git a/resources/puppeteer_gui.glade b/resources/puppeteer_gui.glade index 13e3879..0932296 100644 --- a/resources/puppeteer_gui.glade +++ b/resources/puppeteer_gui.glade @@ -2,14 +2,9 @@ - - 255 - 1 - 10 - False - Puppeteer GUI + Puppeteer True @@ -20,71 +15,6 @@ True False - - - True - False - _File - True - - - True - False - - - gtk-new - True - False - True - True - - - - - gtk-open - True - False - True - True - - - - - gtk-save - True - False - True - True - - - - - gtk-save-as - True - False - True - True - - - - - True - False - - - - - gtk-quit - True - False - True - True - - - - - - True @@ -96,53 +26,16 @@ True False - - gtk-cut - True - False - True - True - - - - - gtk-copy - True - False - True - True - - - - - gtk-paste + True False - True - True - - - - - gtk-delete - True - False - True - True + Configuration - - - True - False - _View - True - - True @@ -154,7 +47,7 @@ True False - + gtk-about True False @@ -174,7 +67,7 @@ - + True False @@ -207,7 +100,10 @@ False 93 False + False + False Select Puppeteer device file + 10 True @@ -227,32 +123,19 @@ True False + center - - True - False + Load Puppeteer configuration - - - False - True - 2 - 0 - - - - True - False - False - Select Puppeteer configuration file - 3 + True + True + False False True - 2 - 1 + 0 @@ -263,35 +146,21 @@ - + True False + center - - True - False + Save Puppeteer configuration - - - False - True - 2 - 0 - - - - True - False - save - True - Save Puppeteer configuration + True + True False True - 2 - 1 + 0 @@ -302,7 +171,7 @@ - + Configure Puppeteer True True @@ -337,22 +206,6 @@ 0 - - - True - False - end - center - True - - - False - False - 5 - end - 1 - - False @@ -398,18 +251,18 @@ - + True False - + 100 80 True True center - + True False 2 @@ -418,7 +271,7 @@ 2 4 - + True False PWM 1 @@ -430,18 +283,13 @@ - + True True - 3 + 3 + 0 False - 0 digits - pwmSpinButtonAdjustment - True - True - if-valid - 1 False @@ -497,7 +345,7 @@ - + True False @@ -507,7 +355,7 @@ True True - + AI 0 True True @@ -583,7 +431,7 @@ - + True False @@ -629,4 +477,216 @@ + + False + Load Puppeteer configuration + True + dialog + False + MainWindow + False + False + False + + + False + vertical + 2 + + + False + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + Load + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + + False + Configure Puppeteer + False + True + False + MainWindow + + + True + False + vertical + + + True + False + 10 + + + True + False + Value adapter + + + False + True + 0 + + + + + True + False + end + 5 + + + True + False + AI + + + False + True + 0 + + + + + True + True + False + digits + + + False + True + 1 + + + + + True + True + 1 + + + + + True + True + f(x) + + + False + True + 2 + + + + + False + True + 0 + + + + + + + + + + False + Save Puppeteer configuration + True + dialog + False + MainWindow + save + True + + + False + vertical + 2 + + + False + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + Save + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + + 255 + 1 + 10 + diff --git a/source/app.d b/source/app.d index 8115bcd..1aa29d9 100644 --- a/source/app.d +++ b/source/app.d @@ -1,12 +1,476 @@ import std.stdio; -import puppeteer_gui.gui.igui; +import std.conv; +import std.meta; + +import puppeteer_controller; + +import gtk.Builder; +import gtk.Main; +import gtk.Button; +import gtk.ApplicationWindow; +import gtk.FileChooserButton; +import gtk.FileChooserDialog; +import gtk.Window; +import gtk.ListBox; +import gtk.Box; +import gtk.ListBoxRow; +import gtk.Label; +import gtk.Entry; +import gtk.SpinButton; + +PuppeteerController controller; + +ApplicationWindow mainWindow; + +Window puppeteerConfigWindow; +Box puppeteerConfigMainBox; +Box AIValueAdapterBox; +Box AIValueAdapterInnerBox; +SpinButton AIValueAdapterSpinButton; +Entry AIValueAdapterEntry; + +FileChooserButton devFileChooserButton; + +FileChooserDialog loadPuppeteerConfigDialog; +FileChooserDialog savePuppeteerConfigDialog; + +ListBox PWMOutputListBox; +ListBoxRow samplePWMOutputListBoxRow; +Box samplePWMOutputBox; +Label samplePWMOutputLabel; +Entry samplePWMOutputEntry; + +ListBox AIMonitorsListBox; +ListBox varMonitorsListBox; + +Button configPuppeteerButton; +Button loadPuppeteerConfigButton; +Button acceptLoadConfigButton; +Button cancelLoadConfigButton; +Button savePuppeteerConfigButton; +Button acceptSaveConfigButton; +Button cancelSaveConfigButton; +Button start_stopCommunicationButton; void main(string[] args) { - IGUI gui = IGUI.getInstance(args); + Main.init(args); + + controller = new PuppeteerController; + + initUI(); + configureUI(); - IWindow mainWindow = gui.createMainWindow("Main"); mainWindow.show(); + Main.run(); +} + +void initUI() +{ + debug writeln("Loading UI"); + + Builder builder = new Builder("resources/puppeteer_gui.glade"); + + void mapUI(T)(ref T UIElement, string name) + { + debug writefln("Mapping %s to type %s", name, T.stringof); + UIElement = to!T(builder.getObject(name)); + + //Check for correct mapping + debug writefln("Name is %s", UIElement.getName()); + } + + mapUI(mainWindow, "MainWindow"); + + mapUI(puppeteerConfigWindow, "puppeteerConfigWindow"); + mapUI(puppeteerConfigMainBox, "puppeteerConfigMainBox"); + mapUI(AIValueAdapterBox, "AIValueAdapterBox"); + mapUI(AIValueAdapterInnerBox, "AIValueAdapterInnerBox"); + mapUI(AIValueAdapterEntry, "AIValueAdapterEntry"); + mapUI(AIValueAdapterSpinButton, "AIValueAdapterSpinButton"); + + mapUI(PWMOutputListBox, "PWMOutputListBox"); + mapUI(samplePWMOutputListBoxRow, "samplePWMOutputListBoxRow"); + mapUI(samplePWMOutputBox, "samplePWMOutputBox"); + mapUI(samplePWMOutputLabel, "samplePWMOutputLabel"); + mapUI(samplePWMOutputEntry, "samplePWMOutputEntry"); + + mapUI(AIMonitorsListBox, "AIMonitorsListBox"); + mapUI(varMonitorsListBox, "varMonitorsListBox"); + + mapUI(devFileChooserButton, "devFileChooserButton"); + + mapUI(loadPuppeteerConfigDialog, "loadPuppeteerConfigDialog"); + mapUI(savePuppeteerConfigDialog, "savePuppeteerConfigDialog"); + + mapUI(configPuppeteerButton, "configPuppeteerButton"); + + mapUI(loadPuppeteerConfigButton, "loadPuppeteerConfigButton"); + mapUI(acceptLoadConfigButton, "acceptLoadConfigButton"); + mapUI(cancelLoadConfigButton, "cancelLoadConfigButton"); + + mapUI(savePuppeteerConfigButton, "savePuppeteerConfigButton"); + mapUI(acceptSaveConfigButton, "acceptSaveConfigButton"); + mapUI(cancelSaveConfigButton, "cancelSaveConfigButton"); + + mapUI(start_stopCommunicationButton, "start_stopCommunicationButton"); + + debug writeln("Done loading UI"); +} + +void configureUI() +{ + debug writeln("Configuring UI"); + + loadPuppeteerConfigDialog.hideOnDelete(); + + devFileChooserButton.addOnFileSet( + (FileChooserButton btn) + { + checkSelectedDevFile(); + } + ); + + configPuppeteerButton.addOnClicked( + (Button btn) + { + puppeteerConfigWindow.show(); + } + ); + + loadPuppeteerConfigButton.addOnClicked( + (Button btn) + { + loadPuppeteerConfigDialog.show(); + } + ); + + acceptLoadConfigButton.addOnClicked( + (Button btn) + { + loadPuppeteerConfigDialog.hide(); + controller.loadConfiguration(loadPuppeteerConfigDialog.getFilename()); + } + ); + + cancelLoadConfigButton.addOnClicked( + (Button btn) + { + loadPuppeteerConfigDialog.hide(); + } + ); + + savePuppeteerConfigButton.addOnClicked( + (Button btn) + { + savePuppeteerConfigDialog.show(); + } + ); + + acceptSaveConfigButton.addOnClicked( + (Button btn) + { + savePuppeteerConfigDialog.hide(); + controller.saveConfiguration(savePuppeteerConfigDialog.getFilename()); + } + ); + + cancelSaveConfigButton.addOnClicked( + (Button btn) + { + savePuppeteerConfigDialog.hide(); + } + ); + + start_stopCommunicationButton.addOnClicked( + (Button btn) + { + btn.setSensitive(false); + + if(!controller.isPuppeteerConnected) + controller.connect(devFileChooserButton.getFilename()); + else + controller.disconnect(); + + checkPuppeteerConnection(); + + btn.setSensitive(true); + } + ); + + configurePuppeteerConfigWindow(); + //TODO: these default values will have to do by now + configurePWMOutputListBox(10); + configureAIMonitorsListBox(10); + configureVarMonitorsListBox([10]); + + checkSelectedDevFile(); + checkPuppeteerConnection(); + + debug writeln("Done configuring UI"); +} + +void configurePWMOutputListBox(int entries) +{ + PWMOutputListBox.removeAll(); + + for(int i=0; i ubyte.max) + { + debug writeln("Wrapping value to 255"); + entry.setText("255"); + value = ubyte.max; + } + else + { + value = to!ubyte(aux); + } + } + catch(ConvException e) + { + debug writeln("User wrote a non-convertible value. Setting to 0"); + entry.setText("0"); + } + + controller.setPWM(pwmPin, value); + } + ); + } + + setAction(to!ubyte(i)); + + listBoxRow.add(box); + + box.add(label); + box.add(entry); + + PWMOutputListBox.insert(listBoxRow, i); + } +} + +void configureAIMonitorsListBox(int entries) +{ + AIMonitorsListBox.removeAll(); + + for(int i=0; i