From 61dce302bc3dd0c89bd13375f1b65c67567692ae Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Tue, 19 Apr 2016 00:01:21 +0200
Subject: [PATCH 01/66] added ned folder for functional modules created new
 file for perl based print engine and configuration for that engine

---
 modules/printengine.cfg | 7 +++++++
 modules/printengine.pl  | 9 +++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 modules/printengine.cfg
 create mode 100644 modules/printengine.pl

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
new file mode 100644
index 0000000..fb479b1
--- /dev/null
+++ b/modules/printengine.cfg
@@ -0,0 +1,7 @@
+#Configuration file for printengine.pl to be called by SLAcer.js and other printer services
+#Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
+#http://www.fablab-leoben.at
+#http://www.github.com/fablab-leoben
+#released under the MIT License
+#this piece of software is provided with absolutely no warranty
+#use at your own risk
\ No newline at end of file
diff --git a/modules/printengine.pl b/modules/printengine.pl
new file mode 100644
index 0000000..5345496
--- /dev/null
+++ b/modules/printengine.pl
@@ -0,0 +1,9 @@
+#!/usr/bin/perl
+#print engine to be called by SLAcer.js and other printer services
+#Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
+#http://www.fablab-leoben.at
+#http://www.github.com/fablab-leoben
+#released under the MIT License
+#this piece of software is provided with absolutely no warranty
+#use at your own risk
+#configuration is stored in printengine.cfg, do not use hardcoded configuration in ths per script, that is bad practice.
\ No newline at end of file

From 4d30ff776ceb2cdc5ef73f95b158a03021c096a5 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Tue, 19 Apr 2016 01:33:13 +0200
Subject: [PATCH 02/66] configured and defined basic variables in
 configuration-module started to introduce primitive samity-checks and
 configuration evaluation to printengime untill further notice onyl Beaglebone
 black with Lightcrafter 4500 on HDMI will be supported.

---
 modules/printengine.cfg | 44 ++++++++++++++++++++++++++++++++++++++++-
 modules/printengine.pl  | 28 ++++++++++++++++++++++++--
 2 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index fb479b1..5ef2ac1 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -1,7 +1,49 @@
+#!/usr/bin/perl
 #Configuration file for printengine.pl to be called by SLAcer.js and other printer services
 #Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
 #http://www.fablab-leoben.at
 #http://www.github.com/fablab-leoben
 #released under the MIT License
 #this piece of software is provided with absolutely no warranty
-#use at your own risk
\ No newline at end of file
+#use at your own risk
+my $log_file = "../log/printengine.log";
+my $logging_enabled="TRUE";
+my $controllerboard="BBB";
+my $steps_per_mm=100; #steps needed to move the Z-Axis 1mm
+my $projector_type="Lightcrafter4500"; #default Light engine
+my $projector_usb_device="";
+my $endstop_Z_max=TRUE;
+my $endstop_Z_max_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
+my $endstop_Z_min=TRUE;
+my $endstop_Z_min_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
+my $wiper="FALSE";
+my $door_contact="true"; Defines if there is a door contact to determine if the enclosure is closed
+my $X_pixels="1192";
+my $Y_pixels="948";
+my $Z_Autocal="True"; #Automatically determine Z-travel by triggering both endstops and dividing the Distance
+my $testrun_capable="true"; Capability to run testruns with wavelengthe that do not trigger polymerisation
+my $testrun_color="RED"; #Color channel used for test run
+my $prodrun_color="BLUE"; #Color Channel used for production run
+my $vat_heatable="false";
+my $check_vat_presence="false";
+#board specific configuration for Beaglebone Black
+if ($controllerboard eq "BBB") then {
+my $virtual_terminal=1;
+my $display_software="fbi";
+my $display_device="/dev/fb0";
+#PIN asignment
+my $pin_zmin="";
+my $pin_zmax="";
+my $pin_door="";
+my $pin_step_Z="";
+my $pin_enable_Z="";
+my $pin_direction_Z="";
+my $pin_trigger_pre="";
+my $pin_trigger_post="";
+my $pin_enable_wiper="";
+my $pin_dir_wiper="";
+my $pin_step_wiper="";
+my $pin_vat_heater="";
+my $pin_vat_temperature="";
+my $pin_vat_presence="";
+}
\ No newline at end of file
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 5345496..8b69d54 100644
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -1,9 +1,33 @@
 #!/usr/bin/perl
-#print engine to be called by SLAcer.js and other printer services
+#print engine to be called by SLAcer.js and other printer services orstandalone from command line
 #Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
 #http://www.fablab-leoben.at
 #http://www.github.com/fablab-leoben
 #released under the MIT License
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
-#configuration is stored in printengine.cfg, do not use hardcoded configuration in ths per script, that is bad practice.
\ No newline at end of file
+#configuration is stored in printengine.cfg, do not use hardcoded configuration in ths per script, that is bad practice.
+use warning;
+use strict;
+use Getopt::Std;
+use Getopt::Long;
+use feature qw(say);
+
+#include configuration and settings from printengine.cfg
+use printengine.cfg
+#checked for used controller board type according to configuration.
+#activate logging to logfile
+if $logging_enabled eq "TRUE" then
+{
+open my $log_fh, ">", $log_file;
+}
+
+if $controllerboard eq "BBB" then 
+{
+
+}
+else {
+say "unknows printer type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
+;
+die "unknown board in configuration!\n";
+}
\ No newline at end of file

From ea25a17dac65d59de2b1d30dccf666afa6079c81 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 1 May 2016 18:30:41 +0200
Subject: [PATCH 03/66] Fixed code to properly import configuration from
 configuration file using Config::Simplei

---
 modules/printengine.cfg | 78 ++++++++++++++++++++---------------------
 modules/printengine.pl  | 67 +++++++++++++++++++++++++++++++----
 2 files changed, 100 insertions(+), 45 deletions(-)
 mode change 100644 => 100755 modules/printengine.pl

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 5ef2ac1..8e5f7c5 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -6,44 +6,44 @@
 #released under the MIT License
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
-my $log_file = "../log/printengine.log";
-my $logging_enabled="TRUE";
-my $controllerboard="BBB";
-my $steps_per_mm=100; #steps needed to move the Z-Axis 1mm
-my $projector_type="Lightcrafter4500"; #default Light engine
-my $projector_usb_device="";
-my $endstop_Z_max=TRUE;
-my $endstop_Z_max_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
-my $endstop_Z_min=TRUE;
-my $endstop_Z_min_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
-my $wiper="FALSE";
-my $door_contact="true"; Defines if there is a door contact to determine if the enclosure is closed
-my $X_pixels="1192";
-my $Y_pixels="948";
-my $Z_Autocal="True"; #Automatically determine Z-travel by triggering both endstops and dividing the Distance
-my $testrun_capable="true"; Capability to run testruns with wavelengthe that do not trigger polymerisation
-my $testrun_color="RED"; #Color channel used for test run
-my $prodrun_color="BLUE"; #Color Channel used for production run
-my $vat_heatable="false";
-my $check_vat_presence="false";
+log_file = "../log/printengine.log";
+logging_enabled="TRUE";
+controllerboard="BBB";
+steps_per_mm=100; #steps needed to move the Z-Axis 1mm
+projector_type="Lightcrafter4500"; #default Light engine
+projector_usb_device="";
+endstop_Z_max=TRUE;
+endstop_Z_max_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
+endstop_Z_min=TRUE;
+endstop_Z_min_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
+wiper="FALSE";
+door_contact="true"; Defines if there is a door contact to determine if the enclosure is closed
+X_pixels="1192";
+Y_pixels="948";
+Z_Autocal="True"; #Automatically determine Z-travel by triggering both endstops and dividing the Distance
+testrun_capable="true"; Capability to run testruns with wavelengthe that do not trigger polymerisation
+testrun_color="RED"; #Color channel used for test run
+prodrun_color="BLUE"; #Color Channel used for production run
+vat_heatable="false";
+vat_target_temperature="";#Vat temperature in Celsius
+check_vat_presence="false";
 #board specific configuration for Beaglebone Black
-if ($controllerboard eq "BBB") then {
-my $virtual_terminal=1;
-my $display_software="fbi";
-my $display_device="/dev/fb0";
+virtual_terminal=1;
+display_software="fbi";
+display_device="/dev/fb0";
 #PIN asignment
-my $pin_zmin="";
-my $pin_zmax="";
-my $pin_door="";
-my $pin_step_Z="";
-my $pin_enable_Z="";
-my $pin_direction_Z="";
-my $pin_trigger_pre="";
-my $pin_trigger_post="";
-my $pin_enable_wiper="";
-my $pin_dir_wiper="";
-my $pin_step_wiper="";
-my $pin_vat_heater="";
-my $pin_vat_temperature="";
-my $pin_vat_presence="";
-}
\ No newline at end of file
+pin_zmin="";
+pin_zmax="";
+pin_door="";
+pin_step_Z="";
+pin_enable_Z="";
+pin_direction_Z="";
+pin_trigger_pre="";
+pin_trigger_post="";
+pin_enable_wiper="";
+pin_dir_wiper="";
+pin_step_wiper="";
+pin_vat_heater="";
+pin_vat_temperature="";
+pin_vat_presence="";
+#end of BBB specifics
\ No newline at end of file
diff --git a/modules/printengine.pl b/modules/printengine.pl
old mode 100644
new mode 100755
index 8b69d54..3bb3561
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -6,23 +6,64 @@
 #released under the MIT License
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
-#configuration is stored in printengine.cfg, do not use hardcoded configuration in ths per script, that is bad practice.
-use warning;
+#configuration is stored in printengine.cfg, do not use hardcoded configuration in ths perl script, that is bad practice.
+use warnings;
 use strict;
 use Getopt::Std;
 use Getopt::Long;
 use feature qw(say);
+use Config::Simple;
+my $cfg = new Config::Simple('printengine.cfg');
+$cfg->read('printengine.cfg');
+#asign config values from config file to values in script
+my $log_file = $cfg->param("log_file");
+my $logging_enabled=$cfg->param("logging_enabled");
+my $controllerboard=$cfg->param("controllerboard");
+my $steps_per_mm=$cfg->param("steps_per_mm");
+my $projector_type=$cfg->param("projector_type");
+my $projector_usb_device=$cfg->param("projector_usb_device");
+my $endstop_Z_max=$cfg->param("endstop_Z_max");
+my $endstop_Z_max_type=$cfg->param("endstop_Z_max_type");
+my $endstop_Z_min=$cfg->param("endstop_Z_min");
+my $endstop_Z_min_type=$cfg->param("endstop_Z_min_type");
+my $wiper=$cfg->param("wiper");
+my $door_contact=$cfg->param("door_contact");
+my $X_pixels=$cfg->param("X_pixels");
+my $Y_pixels=$cfg->param("Y_pixels");
+my $Z_Autocal=$cfg->param("Z-Z_Autocal");
+my $testrun_capable=$cfg->param("testrun_capable");
+my $testrun_color=$cfg->param("testrun_color");
+my $prodrun_color=$cfg->param("prodrun_color");
+my $vat_heatable=$cfg->param("vat_heatable");
+my $vat_target_temperature=$cfg->param("vat_target_temperature");
+my $check_vat_presence=$cfg->param("check_vat_presence");
+my $virtual_terminal=$cfg->param("virtual_terminal");
+my $display_software=$cfg->param("display_software");
+my $display_device=$cfg->param("display_device");
+my $pin_zmin=$cfg->param("pin_zmin");
+my $pin_zmax=$cfg->param("pin_zmax");
+my $pin_door=$cfg->param("pin_door");
+my $pin_step_Z=$cfg->param("pin_step_Z");
+my $pin_enable_Z=$cfg->param("pin_enable_Z");
+my $pin_direction_Z=$cfg->param("pin_direction_Z");
+my $pin_trigger_pre=$cfg->param("pin_trigger_pre");
+my $pin_trigger_post=$cfg->param("pin_trigger_post");
+my $pin_enable_wiper=$cfg->param("pin_enable_wiper");
+my $pin_dir_wiper=$cfg->param("pin_dir_wiper");
+my $pin_step_wiper=$cfg->param("pin_step_wiper");
+my $pin_vat_heater=$cfg->param("pin_vat_heater");
+my $pin_vat_temperature=$cfg->param("pin_vat_temperature");
+my $pin_vat_presence=$cfg->param("pin_vat_presence");
+
 
-#include configuration and settings from printengine.cfg
-use printengine.cfg
 #checked for used controller board type according to configuration.
 #activate logging to logfile
-if $logging_enabled eq "TRUE" then
+if ($logging_enabled eq "TRUE") 
 {
 open my $log_fh, ">", $log_file;
 }
 
-if $controllerboard eq "BBB" then 
+if ($controllerboard eq "BBB")  
 {
 
 }
@@ -30,4 +71,18 @@
 say "unknows printer type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
 die "unknown board in configuration!\n";
+}
+
+if ($display_software eq "fbi")  
+{
+open(whichfile,"which $display_software |") || die "Failed: $!\n";
+while ( <whichfile> )
+{
+my $display_software_path=$!;
+}
+}
+else {
+say "unknows display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
+;
+die "unknown display software in configuration!\n";
 }
\ No newline at end of file

From 006ecf36015518e2d346c17c969b2376ab64d302 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 1 May 2016 20:01:03 +0200
Subject: [PATCH 04/66] further work on importing the default configuration
 from file. possibility to overrule settings from  command line aprameters
 still pending

---
 modules/printengine.cfg |  1 -
 modules/printengine.pl  | 14 +++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 8e5f7c5..7c0e511 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 #Configuration file for printengine.pl to be called by SLAcer.js and other printer services
 #Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
 #http://www.fablab-leoben.at
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 3bb3561..ca8a05b 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -56,16 +56,16 @@
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
 
 
-#checked for used controller board type according to configuration.
 #activate logging to logfile
 if ($logging_enabled eq "TRUE") 
 {
 open my $log_fh, ">", $log_file;
 }
 
-if ($controllerboard eq "BBB")  
+#basic sanity checks to determine whether or not the configuration is complete and makes at least some sense
+if ($controllerboard eq "BBB")  #if the Board is set to be a Beagle Bone Black, we need to check if it actually is one
 {
-
+say "Beagle Bone Black selected, checking board type! - check command still missing";
 }
 else {
 say "unknows printer type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
@@ -73,16 +73,16 @@
 die "unknown board in configuration!\n";
 }
 
-if ($display_software eq "fbi")  
+if ($display_software eq "fbi")  #ckeck for configured Software to send Pictures to the projector
 {
-open(whichfile,"which $display_software |") || die "Failed: $!\n";
+open(whichfile,"which $display_software |") || die "Failed: $!\n"; #find path to the binary
 while ( <whichfile> )
 {
 my $display_software_path=$!;
 }
 }
-else {
+else { #if the configured Display software matches none of the supported packages, die
 say "unknows display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
 die "unknown display software in configuration!\n";
-}
\ No newline at end of file
+}

From 4c419f25b803aa0087566b8cb98b0ec6866c7d2a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 1 May 2016 21:35:13 +0200
Subject: [PATCH 05/66] first iteration of working config import. not much
 sanity checkoing implemented yet

---
 modules/printengine.pl | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index ca8a05b..95d4d22 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -7,14 +7,19 @@
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
 #configuration is stored in printengine.cfg, do not use hardcoded configuration in ths perl script, that is bad practice.
+#definition of libraries and modules to include
 use warnings;
 use strict;
 use Getopt::Std;
 use Getopt::Long;
 use feature qw(say);
 use Config::Simple;
-my $cfg = new Config::Simple('printengine.cfg');
-$cfg->read('printengine.cfg');
+
+
+#import configuration from configuration file
+our $cfg = new Config::Simple();
+$cfg->read("printengine.cfg");
+
 #asign config values from config file to values in script
 my $log_file = $cfg->param("log_file");
 my $logging_enabled=$cfg->param("logging_enabled");
@@ -30,7 +35,7 @@
 my $door_contact=$cfg->param("door_contact");
 my $X_pixels=$cfg->param("X_pixels");
 my $Y_pixels=$cfg->param("Y_pixels");
-my $Z_Autocal=$cfg->param("Z-Z_Autocal");
+my $Z_Autocal=$cfg->param("Z_Autocal");
 my $testrun_capable=$cfg->param("testrun_capable");
 my $testrun_color=$cfg->param("testrun_color");
 my $prodrun_color=$cfg->param("prodrun_color");
@@ -54,8 +59,11 @@
 my $pin_vat_heater=$cfg->param("pin_vat_heater");
 my $pin_vat_temperature=$cfg->param("pin_vat_temperature");
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
-
-
+say "test\n";
+#asign additional variables
+#
+#
+#
 #activate logging to logfile
 if ($logging_enabled eq "TRUE") 
 {
@@ -68,7 +76,7 @@
 say "Beagle Bone Black selected, checking board type! - check command still missing";
 }
 else {
-say "unknows printer type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
+say "unknown controller type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
 die "unknown board in configuration!\n";
 }

From 75889c76e3ee882c37b9ae6499c1eedd5b017c21 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Mon, 2 May 2016 20:10:15 +0200
Subject: [PATCH 06/66] minor fixes, mainly typos

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 95d4d22..2e02395 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -59,7 +59,7 @@
 my $pin_vat_heater=$cfg->param("pin_vat_heater");
 my $pin_vat_temperature=$cfg->param("pin_vat_temperature");
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
-say "test\n";
+
 #asign additional variables
 #
 #

From 87c91d68d5b25c45f8b8c9b7c8d994b22e52f6b1 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Tue, 3 May 2016 01:22:24 +0200
Subject: [PATCH 07/66] sanity checks implemented for base configuration

---
 modules/printengine.cfg |  91 ++++++++++++++++++--------------
 modules/printengine.pl  | 113 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 159 insertions(+), 45 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 7c0e511..97952bc 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -5,44 +5,59 @@
 #released under the MIT License
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
-log_file = "../log/printengine.log";
-logging_enabled="TRUE";
-controllerboard="BBB";
-steps_per_mm=100; #steps needed to move the Z-Axis 1mm
-projector_type="Lightcrafter4500"; #default Light engine
-projector_usb_device="";
-endstop_Z_max=TRUE;
-endstop_Z_max_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
-endstop_Z_min=TRUE;
-endstop_Z_min_type="NC";#NO="Normally Open", NC="Normally Closed". NC is preferred
-wiper="FALSE";
-door_contact="true"; Defines if there is a door contact to determine if the enclosure is closed
-X_pixels="1192";
-Y_pixels="948";
-Z_Autocal="True"; #Automatically determine Z-travel by triggering both endstops and dividing the Distance
-testrun_capable="true"; Capability to run testruns with wavelengthe that do not trigger polymerisation
-testrun_color="RED"; #Color channel used for test run
-prodrun_color="BLUE"; #Color Channel used for production run
-vat_heatable="false";
-vat_target_temperature="";#Vat temperature in Celsius
-check_vat_presence="false";
+log_file = "../log/printengine.log"
+logging_enabled="TRUE"
+controllerboard="BBB"
+steps_per_mm="100" #steps needed to move the Z-Axis 1mm
+projector_type="Lightcrafter4500"
+#default Light engine
+projector_usb_device="/dev/ttyUSB0"
+endstop_Z_max="TRUE"
+endstop_Z_max_type="NC"
+#NO="Normally Open", NC="Normally Closed". NC is preferred
+endstop_Z_min="TRUE"
+endstop_Z_min_type="NC"
+#NO="Normally Open", NC="Normally Closed". NC is preferred
+wiper="FALSE"
+door_contact="TRUE" 
+#Defines if there is a door contact to determine if the enclosure is closed
+X_pixels="1192"
+Y_pixels="948"
+Z_speed="1"
+#mm/s
+Z_max_speed="10"
+#mm/s
+Z_Autocal="True"
+#Automatically determine Z-travel by triggering both endstops and dividing the Distance
+testrun_capable="true"
+#Capability to run testruns with wavelengthe that do not trigger polymerisation
+testrun_color="RED"
+#Color channel used for test run
+prodrun_color="BLUE"
+#Color Channel used for production run
+vat_heatable="false"
+vat_target_temperature=""
+#Vat temperature in Celsius
+check_vat_presence="false" 
 #board specific configuration for Beaglebone Black
-virtual_terminal=1;
-display_software="fbi";
-display_device="/dev/fb0";
+virtual_terminal="1"
+display_software="fbi"
+display_device="/dev/fb0"
 #PIN asignment
-pin_zmin="";
-pin_zmax="";
-pin_door="";
-pin_step_Z="";
-pin_enable_Z="";
-pin_direction_Z="";
-pin_trigger_pre="";
-pin_trigger_post="";
-pin_enable_wiper="";
-pin_dir_wiper="";
-pin_step_wiper="";
-pin_vat_heater="";
-pin_vat_temperature="";
-pin_vat_presence="";
+pin_zmin="testpin"
+pin_zmax="testpin"
+pin_wiper_min="testpin"
+pin_wiper_max="testpin"
+pin_door="testpin"
+pin_step_Z="testpin"
+pin_enable_Z="testpin"
+pin_direction_Z="testpin"
+pin_trigger_pre="testpin"
+pin_trigger_post="testpin"
+pin_enable_wiper="testpin"
+pin_dir_wiper="testpin"
+pin_step_wiper="testpin"
+pin_vat_heater="testpin"
+pin_vat_temperature="testpin"
+pin_vat_presence="testpin"
 #end of BBB specifics
\ No newline at end of file
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 2e02395..696a6d4 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -14,7 +14,7 @@
 use Getopt::Long;
 use feature qw(say);
 use Config::Simple;
-
+use File::Which;
 
 #import configuration from configuration file
 our $cfg = new Config::Simple();
@@ -35,6 +35,8 @@
 my $door_contact=$cfg->param("door_contact");
 my $X_pixels=$cfg->param("X_pixels");
 my $Y_pixels=$cfg->param("Y_pixels");
+my $Z_speed=$cfg->param("Z_speed");
+my $Z_max_speed=$cfg->param("Z_max_speed");
 my $Z_Autocal=$cfg->param("Z_Autocal");
 my $testrun_capable=$cfg->param("testrun_capable");
 my $testrun_color=$cfg->param("testrun_color");
@@ -56,6 +58,8 @@
 my $pin_enable_wiper=$cfg->param("pin_enable_wiper");
 my $pin_dir_wiper=$cfg->param("pin_dir_wiper");
 my $pin_step_wiper=$cfg->param("pin_step_wiper");
+my $pin_wiper_max=$cfg->param("pin_wiper_max");
+my $pin_wiper_min=$cfg->param("pin_wiper_min");
 my $pin_vat_heater=$cfg->param("pin_vat_heater");
 my $pin_vat_temperature=$cfg->param("pin_vat_temperature");
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
@@ -67,27 +71,122 @@
 #activate logging to logfile
 if ($logging_enabled eq "TRUE") 
 {
+unless (defined $log_file and length $log_file){
+die "logging enabled but no logfile defined\n";}
 open my $log_fh, ">", $log_file;
 }
-
 #basic sanity checks to determine whether or not the configuration is complete and makes at least some sense
+#check if the parameters and pins needed for the features enabled are configured
+unless (defined $steps_per_mm and length $steps_per_mm){
+die "No steps per mm for Z Axis defined\n";}
+unless (defined $controllerboard and length $controllerboard){
+die "No controllerboard defined\n";}
+unless (defined $projector_type and length $projector_type){
+die "No projector type defined\n";}
+unless (defined $display_device and length $display_device){
+die "No display device defined\n";}
+unless (defined $X_pixels and length $X_pixels){
+die "No pixels in X direction defined\n";}
+unless (defined $Y_pixels and length $Y_pixels){
+die "No pixels in Y direction defined\n";}
+unless (defined $Z_speed and length $Z_speed){
+die "No Z speed defined\n";}
+unless (defined $Z_max_speed and length $Z_max_speed){
+die "No Z max speed defined\n";}
+unless (defined $prodrun_color and length $prodrun_color){
+die "No production run color defined\n";}
+if ($check_vat_presence eq "TRUE")  
+{
+unless (defined $pin_vat_presence and length $pin_vat_presence )
+{
+die "Vat presence pin definition missing\n";}
+}
+if ($door_contact eq "TRUE")  
+{
+unless (defined $pin_door and length $pin_door )
+{
+die "door pin not defined\n";}
+}
+if ($testrun_capable eq "TRUE")  
+{
+unless (defined $testrun_color and length $testrun_color )
+{
+die "Z max endstops definition incomplete\n";}
+}
+if ($endstop_Z_max eq "TRUE")  
+{
+unless (defined $endstop_Z_max_type and length $endstop_Z_max_type and 
+defined $pin_zmax and length $pin_zmax )
+{
+die "Z max endstops definition incomplete\n";}
+}
+if ($endstop_Z_min eq "TRUE")  
+{
+unless (defined $endstop_Z_min_type and length $endstop_Z_min_type and 
+defined $pin_zmin and length $pin_zmin )
+{
+die "Z min endstops definition incomplete\n";}
+}
+if ($Z_Autocal eq "TRUE")  
+{
+unless ($endstop_Z_max eq "TRUE" and $endstop_Z_min eq "TRUE" and 
+defined $endstop_Z_max_type and length $endstop_Z_max_type and 
+defined $pin_zmax and length $pin_zmax and
+defined $endstop_Z_min_type and length $endstop_Z_min_type and 
+defined $pin_zmin and length $pin_zmin)
+{
+die "Z endstops definition incomplete for autotune of Z axis Length\n";}
+}
+if ($wiper eq "TRUE")  
+{
+unless (defined $pin_enable_wiper and length $pin_enable_wiper and 
+defined $pin_step_wiper and length $pin_step_wiper and
+defined $pin_dir_wiper and length $pin_dir_wiper and 
+defined $pin_zmin and length $pin_zmin and
+defined $pin_wiper_max and length $pin_wiper_max and
+defined $pin_wiper_min and length $pin_wiper_min
+)
+{
+die "pin definition incomplete for wiper usage\n";}
+}
+if ($vat_heatable eq "TRUE")  
+{
+unless (defined $vat_target_temperature and length $vat_target_temperature and 
+defined $pin_vat_heater and length $pin_vat_heater and
+defined $pin_vat_temperature and length $pin_vat_temperature)
+{
+die "Vat temperature or heater parameters are configured incompletely\n";}
+}
+
 if ($controllerboard eq "BBB")  #if the Board is set to be a Beagle Bone Black, we need to check if it actually is one
 {
 say "Beagle Bone Black selected, checking board type! - check command still missing";
+unless (defined $pin_trigger_post and length $pin_trigger_post and defined $pin_trigger_pre and length $pin_trigger_pre){
+die "trigger pin definition incomplete\n";}
 }
 else {
 say "unknown controller type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
 die "unknown board in configuration!\n";
 }
+if ($projector_type eq "Lightcrafter4500")  
+{
+unless (defined $projector_usb_device and length $projector_usb_device){
+die "No projector USB device defined\n";}
+}
+else {
+say "unknown projector type $projector_type , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
+;
+die "unknown projector in configuration!\n";
+}
 
 if ($display_software eq "fbi")  #ckeck for configured Software to send Pictures to the projector
 {
-open(whichfile,"which $display_software |") || die "Failed: $!\n"; #find path to the binary
-while ( <whichfile> )
-{
-my $display_software_path=$!;
-}
+my $display_software_path= which "fbi";
+unless (defined $display_software_path and length $display_software_path){
+die "configured display software not found\n";}
+unless (defined $display_software_path and length $display_software_path){
+die "configured display software not found\n";}
 }
 else { #if the configured Display software matches none of the supported packages, die
 say "unknows display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"

From 1af83595ad49124fea4e0e9b7254156fcff76018 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Tue, 3 May 2016 03:07:24 +0200
Subject: [PATCH 08/66] Started implementation of gpio access using mmap

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 696a6d4..0eb82eb 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -15,7 +15,7 @@
 use feature qw(say);
 use Config::Simple;
 use File::Which;
-
+use Sys::Mmap;
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");

From 74213b0fb8574beab0ae5c77f917cac4302bac17 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 22:46:42 +0200
Subject: [PATCH 09/66] started modification to test direct FD access instead
 of fbi

---
 modules/printengine.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 0eb82eb..d725332 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -16,6 +16,7 @@
 use Config::Simple;
 use File::Which;
 use Sys::Mmap;
+use Graphics::Framebuffer;
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");

From a9b18cf4bd88b656fca18e053d5861f4c70c7185 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 22:50:49 +0200
Subject: [PATCH 10/66] further work on testing framebuffer access

---
 modules/printengine.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index d725332..93f92bc 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -194,3 +194,14 @@
 ;
 die "unknown display software in configuration!\n";
 }
+######testcode framebuffer access
+ my $fb = Graphics::Framebuffer->new();
+
+ $fb->cls();
+ $fb->set_color({'red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 255});
+ $fb->plot({'x' => 28, 'y' => 79,'pixel_size' => 1});
+ $fb->drawto({'x' => 405,'y' => 681,'pixel_size' => 1});
+ $fb->circle({'x' => 200, 'y' => 200, 'radius' => 100, 'filled' => 1});
+ $fb->polygon({'coordinates' => [20,20,  53,3,  233,620], 'pixel_size' => 5});
+ $fb->box({'x' => 95, 'y' => 100, 'xx' => 400, 'yy' => 600, 'filled' => 1});
+ 

From 6b726a2bc639de77b3d22ef5ec2d576689dc8799 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 22:54:02 +0200
Subject: [PATCH 11/66]  framebufffer parameters

---
 modules/printengine.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 93f92bc..cd1f8ba 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -195,7 +195,9 @@
 die "unknown display software in configuration!\n";
 }
 ######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new();
+ my $fb = Graphics::Framebuffer->new(
+ FB_DEVICE=>$display_device
+ );
 
  $fb->cls();
  $fb->set_color({'red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 255});

From 31ac5fa7752c67c8109096e1d0037d57f961b5cd Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:01:18 +0200
Subject: [PATCH 12/66] more fb

---
 modules/printengine.pl | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index cd1f8ba..f839418 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -198,12 +198,24 @@
  my $fb = Graphics::Framebuffer->new(
  FB_DEVICE=>$display_device
  );
-
  $fb->cls();
- $fb->set_color({'red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 255});
- $fb->plot({'x' => 28, 'y' => 79,'pixel_size' => 1});
- $fb->drawto({'x' => 405,'y' => 681,'pixel_size' => 1});
- $fb->circle({'x' => 200, 'y' => 200, 'radius' => 100, 'filled' => 1});
- $fb->polygon({'coordinates' => [20,20,  53,3,  233,620], 'pixel_size' => 5});
- $fb->box({'x' => 95, 'y' => 100, 'xx' => 400, 'yy' => 600, 'filled' => 1});
+ $fb->blit_write(
+     $fb->load_image(
+         {
+
+             'center'     => $fb->{'CENTER_XY'},
+                                   # Three centering options are available
+                                   #  CENTER_X  = center horizontally
+                                   #  CENTER_Y  = center vertically
+                                   #  CENTER_XY = center horizontally and
+                                   #              vertically.  Placing it
+                                   #              right in the middle of
+                                   #              the screen.
+
+             'file'       => 'test1.png', # Usually needs full path
+
+         }
+     )
+ ); 
+
  

From 4a66eec1a86839c56caab103a8697dcf39eba8b6 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:07:33 +0200
Subject: [PATCH 13/66] added library for highres timer

---
 modules/printengine.pl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index f839418..78849be 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -17,6 +17,7 @@
 use File::Which;
 use Sys::Mmap;
 use Graphics::Framebuffer;
+use Time::HiRes;
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
@@ -195,9 +196,7 @@
 die "unknown display software in configuration!\n";
 }
 ######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new(
- FB_DEVICE=>$display_device
- );
+ my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device );
  $fb->cls();
  $fb->blit_write(
      $fb->load_image(
@@ -217,5 +216,6 @@
          }
      )
  ); 
-
+sleep 3;
+$fb->cls();
  

From c4400ae5449320a7e15e62975d012642a0fdd31e Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:20:42 +0200
Subject: [PATCH 14/66] sanity checks for builtin FB access

---
 modules/printengine.pl | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 78849be..df5bca9 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -187,9 +187,17 @@
 my $display_software_path= which "fbi";
 unless (defined $display_software_path and length $display_software_path){
 die "configured display software not found\n";}
-unless (defined $display_software_path and length $display_software_path){
-die "configured display software not found\n";}
+unless (defined $display_device and length $display_device){
+die "display devicde not configured\n";}
+unless (defined $virtual_terminal and length $virtual_terminal){
+die "virtual terminal not configured\n";}
+}
+elsif ($display_software eq "builtin")
+{
+unless (defined $display_device and length $display_device){
+die "display device not configured\n";}
 }
+
 else { #if the configured Display software matches none of the supported packages, die
 say "unknows display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
@@ -197,7 +205,8 @@
 }
 ######testcode framebuffer access
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device );
- $fb->cls();
+ #$fb->cls();
+ $fb->clear_screen('OFF');
  $fb->blit_write(
      $fb->load_image(
          {
@@ -217,5 +226,6 @@
      )
  ); 
 sleep 3;
-$fb->cls();
+$fb->clear_screen('OFF');
+
  

From a3a521d8d7816c22bb1489483f5940e7e1d2ee3f Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:23:56 +0200
Subject: [PATCH 15/66] removed splash screen

---
 modules/printengine.pl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index df5bca9..e79b4c0 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -204,8 +204,7 @@
 die "unknown display software in configuration!\n";
 }
 ######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device );
- #$fb->cls();
+ my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device SPLASH=>0 );
  $fb->clear_screen('OFF');
  $fb->blit_write(
      $fb->load_image(

From 4eed9f2c985a985c0c2e73d996021785de9a43e5 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:25:23 +0200
Subject: [PATCH 16/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index e79b4c0..7564ff1 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -204,7 +204,7 @@
 die "unknown display software in configuration!\n";
 }
 ######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device SPLASH=>0 );
+ my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device: SPLASH=>0; );
  $fb->clear_screen('OFF');
  $fb->blit_write(
      $fb->load_image(

From 0e13dcede0f1beb294aefcb84aa9b511660b434b Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:28:50 +0200
Subject: [PATCH 17/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 7564ff1..4c59c28 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -204,7 +204,7 @@
 die "unknown display software in configuration!\n";
 }
 ######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device: SPLASH=>0; );
+ my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
  $fb->clear_screen('OFF');
  $fb->blit_write(
      $fb->load_image(

From be56a196cd729f3b91c32c9786468c5614d3d2af Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:54:52 +0200
Subject: [PATCH 18/66] reading files from testfolder

---
 modules/printengine.pl | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 4c59c28..2f09996 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -203,28 +203,28 @@
 ;
 die "unknown display software in configuration!\n";
 }
-######testcode framebuffer access
- my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
- $fb->clear_screen('OFF');
- $fb->blit_write(
-     $fb->load_image(
-         {
+#read filelist from testfolder
+    my $dir = '/tmp/tst';
 
-             'center'     => $fb->{'CENTER_XY'},
-                                   # Three centering options are available
-                                   #  CENTER_X  = center horizontally
-                                   #  CENTER_Y  = center vertically
-                                   #  CENTER_XY = center horizontally and
-                                   #              vertically.  Placing it
-                                   #              right in the middle of
-                                   #              the screen.
+    opendir(DIR, $dir) or die $!;
 
-             'file'       => 'test1.png', # Usually needs full path
+    my @pics 
+        = grep { 
+            m/\.png$/             # png files only
+	    && -f "$dir/$_"   # and is a file
+	} readdir(DIR);
+    closedir(DIR);
+#builtin framebuffer access
 
+ my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
+ #$fb->clear_screen('OFF');
+ $fb->blit_write(
+ $fb->load_image(
+         {   'center'     => $fb->{'CENTER_XY'},
+             'file'       => '$pics[0]', # Usually needs full path
          }
      )
  ); 
-sleep 3;
-$fb->clear_screen('OFF');
+#$fb->clear_screen('ON');
 
  

From 03795f5c1b864db69ca22225b369f21b13c0bc86 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Thu, 5 May 2016 23:56:50 +0200
Subject: [PATCH 19/66] tests

---
 modules/printengine.pl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 2f09996..6d59644 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -217,14 +217,14 @@
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
- #$fb->clear_screen('OFF');
+$fb->clear_screen('OFF');
  $fb->blit_write(
  $fb->load_image(
          {   'center'     => $fb->{'CENTER_XY'},
-             'file'       => '$pics[0]', # Usually needs full path
+             'file'       => '$dir/$pics[0]', # Usually needs full path
          }
      )
  ); 
-#$fb->clear_screen('ON');
+$fb->clear_screen('ON');
 
  

From 853e769895c0b8a369038db49d7def205d0b8687 Mon Sep 17 00:00:00 2001
From: root <root@beaglebone.localdomain>
Date: Thu, 5 May 2016 22:05:32 +0000
Subject: [PATCH 20/66] fixes

---
 modules/printengine.pl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 6d59644..462e88e 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -221,10 +221,9 @@
  $fb->blit_write(
  $fb->load_image(
          {   'center'     => $fb->{'CENTER_XY'},
-             'file'       => '$dir/$pics[0]', # Usually needs full path
+             'file'       => "$dir/$pics[0]" # Usually needs full path
          }
      )
  ); 
 $fb->clear_screen('ON');
-
  

From 48959ea175c60233e46395ea72de1f5ce9ec187f Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 6 May 2016 00:10:28 +0200
Subject: [PATCH 21/66] sort array of pictures

---
 modules/printengine.pl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 462e88e..b0a9cf6 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -214,6 +214,9 @@
 	    && -f "$dir/$_"   # and is a file
 	} readdir(DIR);
     closedir(DIR);
+    #sort array
+    my @pics_sorted=sort @pics
+    print @pics_sorted;
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
@@ -221,7 +224,7 @@
  $fb->blit_write(
  $fb->load_image(
          {   'center'     => $fb->{'CENTER_XY'},
-             'file'       => "$dir/$pics[0]" # Usually needs full path
+             'file'       => "$dir/$pics_sorted[0]" # Usually needs full path
          }
      )
  ); 

From 54a9a6d5b56c217c59b04f23ac40950b5b36661f Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 6 May 2016 00:16:13 +0200
Subject: [PATCH 22/66] added sorting algorithm

---
 modules/printengine.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index b0a9cf6..778e58f 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -18,6 +18,7 @@
 use Sys::Mmap;
 use Graphics::Framebuffer;
 use Time::HiRes;
+use Sort::Key::Natural qw( natsort );
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
@@ -215,7 +216,7 @@
 	} readdir(DIR);
     closedir(DIR);
     #sort array
-    my @pics_sorted=sort @pics
+    my @pics_sorted=natsort @pics;
     print @pics_sorted;
 #builtin framebuffer access
 

From 10946744ccc9510119d70061bb7abcd9451c92f3 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 6 May 2016 00:28:48 +0200
Subject: [PATCH 23/66] tests

---
 modules/printengine.pl | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 778e58f..b8fde20 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -18,7 +18,7 @@
 use Sys::Mmap;
 use Graphics::Framebuffer;
 use Time::HiRes;
-use Sort::Key::Natural qw( natsort );
+#use Sort::Key::Natural qw( natsort );
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
@@ -216,8 +216,16 @@
 	} readdir(DIR);
     closedir(DIR);
     #sort array
-    my @pics_sorted=natsort @pics;
-    print @pics_sorted;
+#    my @pics_sorted=natsort @pics;
+#    print @pics_sorted;
+my @pics_sorted=sort { mask($a) <=> mask($b) } @pics;
+# where mask is a function to return digits and mask out anything else, so 
+# integer comparison will work
+sub mask {
+   s/[^0-9]//og;
+   return $_;
+}
+print @pics_sorted;
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );

From 49a9640addd9d753fc209ed5747394d67b01d056 Mon Sep 17 00:00:00 2001
From: root <root@beaglebone.localdomain>
Date: Thu, 5 May 2016 22:43:36 +0000
Subject: [PATCH 24/66] fixed sorting

---
 modules/printengine.pl | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index b8fde20..cff4d56 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -18,7 +18,6 @@
 use Sys::Mmap;
 use Graphics::Framebuffer;
 use Time::HiRes;
-#use Sort::Key::Natural qw( natsort );
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
@@ -216,16 +215,9 @@
 	} readdir(DIR);
     closedir(DIR);
     #sort array
-#    my @pics_sorted=natsort @pics;
-#    print @pics_sorted;
-my @pics_sorted=sort { mask($a) <=> mask($b) } @pics;
-# where mask is a function to return digits and mask out anything else, so 
-# integer comparison will work
-sub mask {
-   s/[^0-9]//og;
-   return $_;
-}
-print @pics_sorted;
+my @pics_sorted=sort { length $a <=> length $b||$a cmp $b } @pics;
+#print @pics_sorted;
+
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );

From 2710e41c3e61f29a98d7a389e6a3385d55bef49e Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 6 May 2016 00:50:05 +0200
Subject: [PATCH 25/66] added loop to loop through pictures

---
 modules/printengine.pl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index cff4d56..41f6675 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -221,13 +221,15 @@
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
+foreach(@pics_sorted){
 $fb->clear_screen('OFF');
  $fb->blit_write(
  $fb->load_image(
          {   'center'     => $fb->{'CENTER_XY'},
-             'file'       => "$dir/$pics_sorted[0]" # Usually needs full path
+             'file'       => "$dir/$_" # Usually needs full path
          }
      )
- ); 
+ );
+ sleep 3;
 $fb->clear_screen('ON');
- 
+} 

From 097e9f05a7a0a3d6d5d2dba9c124aef31d2d8978 Mon Sep 17 00:00:00 2001
From: root <root@beaglebone.localdomain>
Date: Fri, 6 May 2016 09:57:17 +0000
Subject: [PATCH 26/66] added debug code to display screen resolution

---
 modules/printengine.pl | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 41f6675..013395b 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -221,6 +221,9 @@
 #builtin framebuffer access
 
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
+#my ($width,$height,$bits_per_pixel) = $fb->screen_dimensions();
+#say "X=$width,Y=$height,colorbits=$bits_per_pixel"; #debug use
+sleep 10;
 foreach(@pics_sorted){
 $fb->clear_screen('OFF');
  $fb->blit_write(

From efc71d63f79417ac3c1aa6558fbc73425350e6d4 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 00:32:23 +0200
Subject: [PATCH 27/66] further work on test environment, changed default
 display software to builtin

---
 modules/printengine.cfg | 9 +++++----
 modules/printengine.pl  | 5 ++++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 97952bc..4eb72b3 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -2,7 +2,7 @@
 #Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
 #http://www.fablab-leoben.at
 #http://www.github.com/fablab-leoben
-#released under the MIT License
+#released under the GPL v2
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
 log_file = "../log/printengine.log"
@@ -21,8 +21,8 @@ endstop_Z_min_type="NC"
 wiper="FALSE"
 door_contact="TRUE" 
 #Defines if there is a door contact to determine if the enclosure is closed
-X_pixels="1192"
-Y_pixels="948"
+X_pixels="912"
+Y_pixels="1140"
 Z_speed="1"
 #mm/s
 Z_max_speed="10"
@@ -41,7 +41,8 @@ vat_target_temperature=""
 check_vat_presence="false" 
 #board specific configuration for Beaglebone Black
 virtual_terminal="1"
-display_software="fbi"
+display_software="builtin"
+#default is the builtin functionality support for other methods not implemented yet. fbi as other option planned next
 display_device="/dev/fb0"
 #PIN asignment
 pin_zmin="testpin"
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 41f6675..32239e8 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -3,7 +3,8 @@
 #Copyright 2016 Robert Koeppl, Fablab Leoben robert.koeppl@fablab-leoben.at
 #http://www.fablab-leoben.at
 #http://www.github.com/fablab-leoben
-#released under the MIT License
+#released under the GPL v2
+#unzip code based on https://gist.github.com/eqhmcow/5389877
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
 #configuration is stored in printengine.cfg, do not use hardcoded configuration in ths perl script, that is bad practice.
@@ -18,6 +19,8 @@
 use Sys::Mmap;
 use Graphics::Framebuffer;
 use Time::HiRes;
+use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError);
+use IO::File ;
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");

From 89c640ba9d962b39b089aeb9b0d19cb32321fdc8 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 02:13:39 +0200
Subject: [PATCH 28/66] got extraction to work, added cleanup of temp folder,
 added option to define if archive is from slacer or not

---
 modules/printengine.cfg |  1 +
 modules/printengine.pl  | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 4eb72b3..bdf8127 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -6,6 +6,7 @@
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
 log_file = "../log/printengine.log"
+temporary_folder="./temp"
 logging_enabled="TRUE"
 controllerboard="BBB"
 steps_per_mm="100" #steps needed to move the Z-Axis 1mm
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 7120693..02c20b6 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -4,7 +4,6 @@
 #http://www.fablab-leoben.at
 #http://www.github.com/fablab-leoben
 #released under the GPL v2
-#unzip code based on https://gist.github.com/eqhmcow/5389877
 #this piece of software is provided with absolutely no warranty
 #use at your own risk
 #configuration is stored in printengine.cfg, do not use hardcoded configuration in ths perl script, that is bad practice.
@@ -19,14 +18,18 @@
 use Sys::Mmap;
 use Graphics::Framebuffer;
 use Time::HiRes;
-use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError);
+use Archive::Zip;
 use IO::File ;
+use File::Spec::Functions qw(splitpath);
+use File::Path qw(mkpath);
+use File::Path 'rmtree';
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
 
 #asign config values from config file to values in script
 my $log_file = $cfg->param("log_file");
+my $temporary_folder=$cfg->param("temporary_folder");
 my $logging_enabled=$cfg->param("logging_enabled");
 my $controllerboard=$cfg->param("controllerboard");
 my $steps_per_mm=$cfg->param("steps_per_mm");
@@ -70,7 +73,10 @@
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
 
 #asign additional variables
-#
+my $picturesarchive;
+my $archivesource;
+GetOptions("picturesarchive=s"=>\$picturesarchive, "archivesource=s"=>\$archivesource);#read pictures archive from command line option
+
 #
 #
 #activate logging to logfile
@@ -84,6 +90,8 @@
 #check if the parameters and pins needed for the features enabled are configured
 unless (defined $steps_per_mm and length $steps_per_mm){
 die "No steps per mm for Z Axis defined\n";}
+unless (defined $temporary_folder and length $temporary_folder){
+die "No temporary folder defined\n";}
 unless (defined $controllerboard and length $controllerboard){
 die "No controllerboard defined\n";}
 unless (defined $projector_type and length $projector_type){
@@ -206,11 +214,27 @@
 ;
 die "unknown display software in configuration!\n";
 }
-#read filelist from testfolder
-    my $dir = '/tmp/tst';
+#uncompresse archive to temporary folder
+unless (defined $temporary_folder and length $temporary_folder){
+die "No temporary folder defined\n";}
+rmtree([ "$temporary_folder"]) or die "$!: for directory $temporary_folder\n"; 
+unless (-d $temporary_folder) {
+            mkpath($temporary_folder) or die "Couldn't mkdir $temporary_folder: $!";}
+            
 
-    opendir(DIR, $dir) or die $!;
+my $zip = Archive::Zip->new($picturesarchive);
+$zip->extractTree('',$temporary_folder);
 
+
+
+#read filelist from testfolder
+    my $dir = $temporary_folder;
+    if ($archivesource eq "slacer") {
+     $dir = "$temporary_folder/slices";}
+    else {
+     $dir = $temporary_folder;
+    }
+   opendir(DIR, $dir) or die $!;
     my @pics 
         = grep { 
             m/\.png$/             # png files only

From 92eb46f0fb73ca2cf4a262e1384748b4c2347298 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 02:36:14 +0200
Subject: [PATCH 29/66] cleanups

---
 modules/printengine.pl | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 02c20b6..6a2dd18 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -250,16 +250,25 @@
  my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
 #my ($width,$height,$bits_per_pixel) = $fb->screen_dimensions();
 #say "X=$width,Y=$height,colorbits=$bits_per_pixel"; #debug use
-sleep 10;
+#sleep 10;
 foreach(@pics_sorted){
 $fb->clear_screen('OFF');
  $fb->blit_write(
  $fb->load_image(
-         {   'center'     => $fb->{'CENTER_XY'},
+         {   
+         
+             'width'      => $X_pixels, # Optional. Resizes to this maximum
+                                   # width.  It fits the image to this
+                                   # size.
+
+             'height'     => $Y_pixels, # Optional. Resizes to this maximum
+                                   # height.  It fits the image to this
+                                   # size
+             'center'     => $fb->{'CENTER_XY'},
              'file'       => "$dir/$_" # Usually needs full path
          }
      )
  );
- sleep 3;
+ sleep 1;
 $fb->clear_screen('ON');
 } 

From 0fd8e18fe750bef4bb2e642301bf0189e1b7e159 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 02:41:50 +0200
Subject: [PATCH 30/66] cleanup

---
 modules/printengine.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 6a2dd18..02abe91 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -264,6 +264,7 @@
              'height'     => $Y_pixels, # Optional. Resizes to this maximum
                                    # height.  It fits the image to this
                                    # size
+             'scale_type' => 'max',
              'center'     => $fb->{'CENTER_XY'},
              'file'       => "$dir/$_" # Usually needs full path
          }

From 3595f04a34ee510f0151c47c1bcde5e61c4cd697 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 16:02:21 +0200
Subject: [PATCH 31/66] read layer height, exposure time and settling time from
 slacer README.txt in zip archive read overshoot from config file defined
 overshoot default in config file soem debugcode for new variables - will be
 removed later on

---
 modules/printengine.cfg |  2 ++
 modules/printengine.pl  | 25 +++++++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index bdf8127..d3217e7 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -30,6 +30,8 @@ Z_max_speed="10"
 #mm/s
 Z_Autocal="True"
 #Automatically determine Z-travel by triggering both endstops and dividing the Distance
+overshoot="2"
+#overshoot in mm to make sure the whole area is covered in resin correctly
 testrun_capable="true"
 #Capability to run testruns with wavelengthe that do not trigger polymerisation
 testrun_color="RED"
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 02abe91..f9c04f7 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -46,6 +46,7 @@
 my $Z_speed=$cfg->param("Z_speed");
 my $Z_max_speed=$cfg->param("Z_max_speed");
 my $Z_Autocal=$cfg->param("Z_Autocal");
+my $overshoot=$cfg->param("overshoot");
 my $testrun_capable=$cfg->param("testrun_capable");
 my $testrun_color=$cfg->param("testrun_color");
 my $prodrun_color=$cfg->param("prodrun_color");
@@ -76,7 +77,10 @@
 my $picturesarchive;
 my $archivesource;
 GetOptions("picturesarchive=s"=>\$picturesarchive, "archivesource=s"=>\$archivesource);#read pictures archive from command line option
-
+my $layer_height;
+my $exposure_time;
+my $resin_settling_time;
+my $cfg2;
 #
 #
 #activate logging to logfile
@@ -90,6 +94,8 @@
 #check if the parameters and pins needed for the features enabled are configured
 unless (defined $steps_per_mm and length $steps_per_mm){
 die "No steps per mm for Z Axis defined\n";}
+unless (defined $overshoot and length $overshoot){
+die "No overshoot for Z Axis defined\n";}
 unless (defined $temporary_folder and length $temporary_folder){
 die "No temporary folder defined\n";}
 unless (defined $controllerboard and length $controllerboard){
@@ -230,7 +236,12 @@
 #read filelist from testfolder
     my $dir = $temporary_folder;
     if ($archivesource eq "slacer") {
-     $dir = "$temporary_folder/slices";}
+     $dir = "$temporary_folder/slices";
+         $cfg2 = new Config::Simple();
+         $cfg2->read("$temporary_folder/README.txt");
+         $layer_height=$cfg2->param("layer_height");
+         $exposure_time=$cfg2->param("exposure_time");
+         $resin_settling_time=$cfg2->param("resin_settling_time");}
     else {
      $dir = $temporary_folder;
     }
@@ -243,6 +254,11 @@
     closedir(DIR);
     #sort array
 my @pics_sorted=sort { length $a <=> length $b||$a cmp $b } @pics;
+say "layer_height=$layer_height µm, exposure_time=$exposure_time ms,resin_settling_time=$resin_settling_time ms\n";
+my $exposure_time_us=1000*$exposure_time;#conversion to microseconds
+my $resin_settling_time_us=1000*$resin_settling_time;#conversion to microseconds
+sleep 10;
+
 #print @pics_sorted;
 
 #builtin framebuffer access
@@ -254,6 +270,7 @@
 foreach(@pics_sorted){
 $fb->clear_screen('OFF');
  $fb->blit_write(
+ Time::HiRes::usleep("$resin_settling_time_us");
  $fb->load_image(
          {   
          
@@ -270,6 +287,6 @@
          }
      )
  );
- sleep 1;
-$fb->clear_screen('ON');
+ Time::HiRes::usleep("$exposure_time_us");
 } 
+$fb->clear_screen('ON');
\ No newline at end of file

From d3e6d2ebd0abc0c6be1e8b0007ad2ae24bd62d0f Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sat, 7 May 2016 16:06:25 +0200
Subject: [PATCH 32/66] bugfixes

---
 modules/printengine.pl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index f9c04f7..9428b40 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -269,9 +269,9 @@
 #sleep 10;
 foreach(@pics_sorted){
 $fb->clear_screen('OFF');
- $fb->blit_write(
  Time::HiRes::usleep("$resin_settling_time_us");
- $fb->load_image(
+ $fb->blit_write(
+  $fb->load_image(
          {   
          
              'width'      => $X_pixels, # Optional. Resizes to this maximum
@@ -287,6 +287,7 @@
          }
      )
  );
+
+}
  Time::HiRes::usleep("$exposure_time_us");
-} 
 $fb->clear_screen('ON');
\ No newline at end of file

From 9e13ecdc621248ba9fd25c5637242e841be0753b Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 8 May 2016 02:52:43 +0200
Subject: [PATCH 33/66] modified to write layer and exposure settings to Readme
 in zip file

---
 js/main.js | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/js/main.js b/js/main.js
index 339ed16..ce82c66 100644
--- a/js/main.js
+++ b/js/main.js
@@ -454,7 +454,15 @@ function startSlicing() {
     if (settings.get('slicer.zip')) {
         zipFile   = new JSZip();
         zipFolder = zipFile.folder('slices');
-        zipFile.file("README.txt", 'Generated by SLAcer.js\r\nhttp://lautr3k.github.io/SLAcer.js/\r\n');
+	ontime = parseInt(times.on);
+	offtime = parseInt(times.off);
+	layerheight=settings.get('slicer.layers.height');
+	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height= '+layerheight;
+	ziptext2='\r\nexposure_time= '+ontime;
+	ziptext3= '\r\nresin_settling_time= '+offtime;
+	ziptext= ziptext1+ziptext2+ziptext3;
+	
+        zipFile.file("README.txt",ziptext);
     }
 
     slicesNumber && slice();

From 953dd374a9ff7d752ce51680219b1833c202e61a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 8 May 2016 03:09:08 +0200
Subject: [PATCH 34/66] cleanup

---
 modules/printengine.pl | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 9428b40..ac18ecd 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -259,14 +259,9 @@
 my $resin_settling_time_us=1000*$resin_settling_time;#conversion to microseconds
 sleep 10;
 
-#print @pics_sorted;
-
 #builtin framebuffer access
 
- my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
-#my ($width,$height,$bits_per_pixel) = $fb->screen_dimensions();
-#say "X=$width,Y=$height,colorbits=$bits_per_pixel"; #debug use
-#sleep 10;
+my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
 foreach(@pics_sorted){
 $fb->clear_screen('OFF');
  Time::HiRes::usleep("$resin_settling_time_us");
@@ -287,7 +282,8 @@
          }
      )
  );
-
+Time::HiRes::usleep("$exposure_time_us");
+$fb->clear_screen('OFF');
 }
- Time::HiRes::usleep("$exposure_time_us");
+
 $fb->clear_screen('ON');
\ No newline at end of file

From cf094c86b0b67cb521af71621ba9f3583e56d833 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 8 May 2016 03:14:18 +0200
Subject: [PATCH 35/66] debugs

---
 modules/printengine.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index ac18ecd..ac383cf 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -257,6 +257,7 @@
 say "layer_height=$layer_height µm, exposure_time=$exposure_time ms,resin_settling_time=$resin_settling_time ms\n";
 my $exposure_time_us=1000*$exposure_time;#conversion to microseconds
 my $resin_settling_time_us=1000*$resin_settling_time;#conversion to microseconds
+say "layer_height=$layer_height µm, exposure_time=$exposure_time_us µs,resin_settling_time=$resin_settling_time_us µs\n";
 sleep 10;
 
 #builtin framebuffer access

From a8d506385d9cd021bb0d00391ced7640620822cd Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 14:38:42 +0200
Subject: [PATCH 36/66] disabled serial send for now

---
 modules/printengine.pl | 63 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 57 insertions(+), 6 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index ac383cf..45d5811 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -72,7 +72,8 @@
 my $pin_vat_heater=$cfg->param("pin_vat_heater");
 my $pin_vat_temperature=$cfg->param("pin_vat_temperature");
 my $pin_vat_presence=$cfg->param("pin_vat_presence");
-
+my $arduinotty=$cfg->param("arduinotty");
+my $arduinottybaudrate=$cfg->param("arduinottybaudrate");
 #asign additional variables
 my $picturesarchive;
 my $archivesource;
@@ -183,6 +184,9 @@
 unless (defined $pin_trigger_post and length $pin_trigger_post and defined $pin_trigger_pre and length $pin_trigger_pre){
 die "trigger pin definition incomplete\n";}
 }
+elsif ($controllerboard eq "raspiarduinoramps")
+unless (defined $arduinotty and length $arduinotty and defined $arduinottybaudrate and length $arduinottybaudrate){
+die "trigger pin definition incomplete\n";
 else {
 say "unknown controller type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
@@ -263,9 +267,8 @@
 #builtin framebuffer access
 
 my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
-foreach(@pics_sorted){
 $fb->clear_screen('OFF');
- Time::HiRes::usleep("$resin_settling_time_us");
+foreach(@pics_sorted){
  $fb->blit_write(
   $fb->load_image(
          {   
@@ -284,7 +287,55 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
-$fb->clear_screen('OFF');
+$fb->clear_screen('OFF')
+Time::HiRes::usleep("$resin_settling_time_us");
 }
-
-$fb->clear_screen('ON');
\ No newline at end of file
+$fb->clear_screen('ON');
+##sendcode- to be adapted/rewritten taken from http://www.contraptor.org/about
+#use Device::SerialPort;
+#use Time::HiRes qw/sleep/;
+#use Slurp;
+ 
+#Slup each file into a command list
+#my @command_list;
+#for my $file ( @ARGV ){
+#    push @command_list, split('\n',slurp $file);
+#}
+ 
+#If your board autoresets when talked to ( like a Sanguino ), you can uncomment the line bellow to get the machine to home position before sending the actual gcode
+#send_commands('G21','G91','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150');
+ 
+#send_commands(@command_list);
+ 
+#sub send_commands{
+#    my @command_list = @_;
+ 
+    #Open port
+#    my $port = Device::SerialPort->new("/dev/ttyUSB0");
+ 
+    # 19200, 81N on the USB ftdi driver
+#    $port->baudrate(38400);
+#    $port->databits(8);
+#    $port->parity("none");
+#    $port->stopbits(1);
+ 
+#    while (1) {
+        # Poll to see if any data is coming in
+#        if ( my $char = $port->lookfor() ) {
+#            $char =~ s/\r//;
+#            print "$char\n";
+#            if( $char =~ m/^(ok|start)$/){
+#                #Send next command
+#                my $next_command = shift @command_list;
+#                print "$next_command\n";
+#                $port->write("$next_command\n");
+#            }else{
+#                print "unknown: $char\n";
+#            }
+#        }
+ #       sleep 0.01;
+ #       unless(@command_list){last; }
+ #   }
+#}
+###end sendcode
+exit 0;
\ No newline at end of file

From 14f5c56e86cc6ee203e5ec2d57d4aa05458a5849 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 14:41:30 +0200
Subject: [PATCH 37/66] modified output for readme  in zip archive to allow
 config parsing

---
 js/main.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/js/main.js b/js/main.js
index ce82c66..0ec8ae6 100644
--- a/js/main.js
+++ b/js/main.js
@@ -457,9 +457,9 @@ function startSlicing() {
 	ontime = parseInt(times.on);
 	offtime = parseInt(times.off);
 	layerheight=settings.get('slicer.layers.height');
-	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height= '+layerheight;
-	ziptext2='\r\nexposure_time= '+ontime;
-	ziptext3= '\r\nresin_settling_time= '+offtime;
+	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height='\"+layerheight\";
+	ziptext2='\r\nexposure_time='\"+ontime\";
+	ziptext3= '\r\nresin_settling_time='\"+offtime\";
 	ziptext= ziptext1+ziptext2+ziptext3;
 	
         zipFile.file("README.txt",ziptext);

From f745aae4fce574976a17bacb76cf9354d8a44e9e Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 14:56:14 +0200
Subject: [PATCH 38/66] fixes

---
 js/main.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/js/main.js b/js/main.js
index 0ec8ae6..495e62d 100644
--- a/js/main.js
+++ b/js/main.js
@@ -457,9 +457,9 @@ function startSlicing() {
 	ontime = parseInt(times.on);
 	offtime = parseInt(times.off);
 	layerheight=settings.get('slicer.layers.height');
-	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height='\"+layerheight\";
-	ziptext2='\r\nexposure_time='\"+ontime\";
-	ziptext3= '\r\nresin_settling_time='\"+offtime\";
+	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height='+layerheight;
+	ziptext2='\r\nexposure_time='+ontime;
+	ziptext3= '\r\nresin_settling_time='+offtime;
 	ziptext= ziptext1+ziptext2+ziptext3;
 	
         zipFile.file("README.txt",ziptext);

From cce7062bd7f4db8fdcd0735f8222279d2075c602 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 15:03:28 +0200
Subject: [PATCH 39/66] fixes

---
 modules/printengine.cfg | 7 ++++++-
 modules/printengine.pl  | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index d3217e7..96c52ca 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -8,7 +8,12 @@
 log_file = "../log/printengine.log"
 temporary_folder="./temp"
 logging_enabled="TRUE"
-controllerboard="BBB"
+#controllerboard="BBB"
+controllerboard="raspiarduinoramps"
+arduinotty="/dev/ttyACM0"
+
+arduinottybaudrate="115500"
+
 steps_per_mm="100" #steps needed to move the Z-Axis 1mm
 projector_type="Lightcrafter4500"
 #default Light engine
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 45d5811..7500747 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -287,7 +287,7 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
-$fb->clear_screen('OFF')
+$fb->clear_screen('OFF');
 Time::HiRes::usleep("$resin_settling_time_us");
 }
 $fb->clear_screen('ON');

From aef4e0b57eb318077e2996586f386675a8a33fb9 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 15:45:10 +0200
Subject: [PATCH 40/66] fixes

---
 modules/printengine.pl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 7500747..6e7874f 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -184,9 +184,11 @@
 unless (defined $pin_trigger_post and length $pin_trigger_post and defined $pin_trigger_pre and length $pin_trigger_pre){
 die "trigger pin definition incomplete\n";}
 }
-elsif ($controllerboard eq "raspiarduinoramps")
+elsif ($controllerboard eq "raspiarduinoramps"){
+say "Raspberry PI with Arduino selected, checking board type! - check command still missing";
 unless (defined $arduinotty and length $arduinotty and defined $arduinottybaudrate and length $arduinottybaudrate){
-die "trigger pin definition incomplete\n";
+die "trigger pin definition incomplete\n";}
+}
 else {
 say "unknown controller type $controllerboard , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;

From a946c698fc64d14a7ae9b3aef6ca4d283a340e20 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 15:52:30 +0200
Subject: [PATCH 41/66] fixes

---
 js/main.js | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/js/main.js b/js/main.js
index 495e62d..0daa2be 100644
--- a/js/main.js
+++ b/js/main.js
@@ -457,10 +457,11 @@ function startSlicing() {
 	ontime = parseInt(times.on);
 	offtime = parseInt(times.off);
 	layerheight=settings.get('slicer.layers.height');
-	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height='+layerheight;
-	ziptext2='\r\nexposure_time='+ontime;
-	ziptext3= '\r\nresin_settling_time='+offtime;
-	ziptext= ziptext1+ziptext2+ziptext3;
+	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height=\"'+layerheight;
+	ziptext2='\r\nexposure_time=\"'+ontime;
+	ziptext3= '\r\nresin_settling_time=\"'+offtime;
+	zipdelimiter='\"'
+	ziptext= ziptext1+zipdelimiter+ziptext2+zipdelimiter+ziptext3+zipdelimiter;
 	
         zipFile.file("README.txt",ziptext);
     }

From 45fd1c25cab1e5b2f29bc7b114b3779a7b6e7526 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 16:21:16 +0200
Subject: [PATCH 42/66] fixes

---
 js/main.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/js/main.js b/js/main.js
index 0daa2be..e1216c5 100644
--- a/js/main.js
+++ b/js/main.js
@@ -457,10 +457,10 @@ function startSlicing() {
 	ontime = parseInt(times.on);
 	offtime = parseInt(times.off);
 	layerheight=settings.get('slicer.layers.height');
-	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height=\"'+layerheight;
-	ziptext2='\r\nexposure_time=\"'+ontime;
-	ziptext3= '\r\nresin_settling_time=\"'+offtime;
 	zipdelimiter='\"'
+	ziptext1= '#Generated by SLAcer.js\r\n#http://lautr3k.github.io/SLAcer.js/\r\nlayer_height='+zipdelimiter+layerheight;
+	ziptext2='\r\nexposure_time='+zipdelimiter+ontime;
+	ziptext3= '\r\nresin_settling_time='+zipdelimiter+offtime;
 	ziptext= ziptext1+zipdelimiter+ziptext2+zipdelimiter+ziptext3+zipdelimiter;
 	
         zipFile.file("README.txt",ziptext);

From f810d99a61ac5f5c5e6696f98bbfd70237ff568c Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 17:53:06 +0200
Subject: [PATCH 43/66] endconde iteration 1

---
 modules/printengine.cfg |  1 -
 modules/printengine.pl  | 56 +++++++++++++++++++++++------------------
 2 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 96c52ca..e8cc258 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -11,7 +11,6 @@ logging_enabled="TRUE"
 #controllerboard="BBB"
 controllerboard="raspiarduinoramps"
 arduinotty="/dev/ttyACM0"
-
 arduinottybaudrate="115500"
 
 steps_per_mm="100" #steps needed to move the Z-Axis 1mm
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 6e7874f..666a0d8 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -23,6 +23,8 @@
 use File::Spec::Functions qw(splitpath);
 use File::Path qw(mkpath);
 use File::Path 'rmtree';
+use Device::SerialPort;
+use Slurp;
 #import configuration from configuration file
 our $cfg = new Config::Simple();
 $cfg->read("printengine.cfg");
@@ -265,7 +267,11 @@
 my $resin_settling_time_us=1000*$resin_settling_time;#conversion to microseconds
 say "layer_height=$layer_height µm, exposure_time=$exposure_time_us µs,resin_settling_time=$resin_settling_time_us µs\n";
 sleep 10;
-
+# Home Z-Axis
+my@command_list=('G21','G28 Z')
+send_commands(@command_list);
+sleep 20;
+#
 #builtin framebuffer access
 
 my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
@@ -309,35 +315,35 @@
  
 #send_commands(@command_list);
  
-#sub send_commands{
-#    my @command_list = @_;
+sub send_commands{
+    my @command_list = @_;
  
     #Open port
-#    my $port = Device::SerialPort->new("/dev/ttyUSB0");
+    my $port = Device::SerialPort->new($arduinotty);
  
     # 19200, 81N on the USB ftdi driver
-#    $port->baudrate(38400);
-#    $port->databits(8);
-#    $port->parity("none");
-#    $port->stopbits(1);
+    $port->baudrate(arduinottybaudrate);
+    $port->databits(8);
+    $port->parity("none");
+    $port->stopbits(1);
  
-#    while (1) {
+    while (1) {
         # Poll to see if any data is coming in
-#        if ( my $char = $port->lookfor() ) {
-#            $char =~ s/\r//;
-#            print "$char\n";
-#            if( $char =~ m/^(ok|start)$/){
-#                #Send next command
-#                my $next_command = shift @command_list;
-#                print "$next_command\n";
-#                $port->write("$next_command\n");
-#            }else{
-#                print "unknown: $char\n";
-#            }
-#        }
- #       sleep 0.01;
- #       unless(@command_list){last; }
- #   }
-#}
+        if ( my $char = $port->lookfor() ) {
+            $char =~ s/\r//;
+            print "$char\n";
+            if( $char =~ m/^(ok|start)$/){
+                #Send next command
+                my $next_command = shift @command_list;
+                print "$next_command\n";
+                $port->write("$next_command\n");
+            }else{
+                print "unknown: $char\n";
+            }
+        }
+       sleep 0.01;
+       unless(@command_list){last; }
+   }
+}
 ###end sendcode
 exit 0;
\ No newline at end of file

From 5723bb53c6de65039850be8005b3857d54e4c4fe Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 18:00:33 +0200
Subject: [PATCH 44/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 666a0d8..9a8c282 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -268,7 +268,7 @@
 say "layer_height=$layer_height µm, exposure_time=$exposure_time_us µs,resin_settling_time=$resin_settling_time_us µs\n";
 sleep 10;
 # Home Z-Axis
-my@command_list=('G21','G28 Z')
+my @command_list=('G21','G28 Z')
 send_commands(@command_list);
 sleep 20;
 #

From f67732c99ee94bf83eab18134ba21dc23febb6ce Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 18:01:52 +0200
Subject: [PATCH 45/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 9a8c282..d8f888f 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -268,7 +268,7 @@
 say "layer_height=$layer_height µm, exposure_time=$exposure_time_us µs,resin_settling_time=$resin_settling_time_us µs\n";
 sleep 10;
 # Home Z-Axis
-my @command_list=('G21','G28 Z')
+my @command_list=('G21','G28 Z');
 send_commands(@command_list);
 sleep 20;
 #

From 75887374872c5aad6c06bbd798aaea3486ed6eee Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 18:02:56 +0200
Subject: [PATCH 46/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index d8f888f..8e0cbc6 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -322,7 +322,7 @@ sub send_commands{
     my $port = Device::SerialPort->new($arduinotty);
  
     # 19200, 81N on the USB ftdi driver
-    $port->baudrate(arduinottybaudrate);
+    $port->baudrate($arduinottybaudrate);
     $port->databits(8);
     $port->parity("none");
     $port->stopbits(1);

From 04d4d1c80608caa722791e4723c4a508308203c8 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 18:50:59 +0200
Subject: [PATCH 47/66] fixes

---
 modules/printengine.cfg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index e8cc258..976d621 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -11,7 +11,7 @@ logging_enabled="TRUE"
 #controllerboard="BBB"
 controllerboard="raspiarduinoramps"
 arduinotty="/dev/ttyACM0"
-arduinottybaudrate="115500"
+arduinottybaudrate="115200"
 
 steps_per_mm="100" #steps needed to move the Z-Axis 1mm
 projector_type="Lightcrafter4500"

From 60a463e8d2fd237d7c9fd1704ef60788311a3c9a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:05:43 +0200
Subject: [PATCH 48/66] send layersteps

---
 modules/printengine.pl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 8e0cbc6..408f29e 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -270,7 +270,9 @@
 # Home Z-Axis
 my @command_list=('G21','G28 Z');
 send_commands(@command_list);
-sleep 20;
+sleep 10;
+my $z=0;
+my $zdelta=$layer_height/1000;
 #
 #builtin framebuffer access
 
@@ -295,6 +297,9 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
+$z=$z+$zdelta;
+my @command_list=('G1 Z $z');
+send_commands(@command_list);
 $fb->clear_screen('OFF');
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From 100298993ef3dd1ff15375704ea80ac09374901a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:10:21 +0200
Subject: [PATCH 49/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 408f29e..0e3a027 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -298,7 +298,7 @@
  );
 Time::HiRes::usleep("$exposure_time_us");
 $z=$z+$zdelta;
-my @command_list=('G1 Z $z');
+my @command_list=("G1 Z $z F1");
 send_commands(@command_list);
 $fb->clear_screen('OFF');
 Time::HiRes::usleep("$resin_settling_time_us");

From 4348687e0506ea9d9af1e0ad23916895ab4c6e71 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:29:22 +0200
Subject: [PATCH 50/66] fixes

---
 modules/printengine.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 0e3a027..7eb34c4 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -297,10 +297,11 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
+$fb->clear_screen('OFF');
 $z=$z+$zdelta;
 my @command_list=("G1 Z $z F1");
 send_commands(@command_list);
-$fb->clear_screen('OFF');
+
 Time::HiRes::usleep("$resin_settling_time_us");
 }
 $fb->clear_screen('ON');

From 5be5730cd98e6b09d9c15cdef6252682c9d33028 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:42:31 +0200
Subject: [PATCH 51/66] fixes

---
 modules/printengine.pl | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 7eb34c4..d9cd87b 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -234,7 +234,13 @@
 rmtree([ "$temporary_folder"]) or die "$!: for directory $temporary_folder\n"; 
 unless (-d $temporary_folder) {
             mkpath($temporary_folder) or die "Couldn't mkdir $temporary_folder: $!";}
-            
+my $port = Device::SerialPort->new($arduinotty);
+ 
+    # 19200, 81N on the USB ftdi driver
+    $port->baudrate($arduinottybaudrate);
+    $port->databits(8);
+    $port->parity("none");
+    $port->stopbits(1);            
 
 my $zip = Archive::Zip->new($picturesarchive);
 $zip->extractTree('',$temporary_folder);
@@ -325,13 +331,7 @@ sub send_commands{
     my @command_list = @_;
  
     #Open port
-    my $port = Device::SerialPort->new($arduinotty);
- 
-    # 19200, 81N on the USB ftdi driver
-    $port->baudrate($arduinottybaudrate);
-    $port->databits(8);
-    $port->parity("none");
-    $port->stopbits(1);
+
  
     while (1) {
         # Poll to see if any data is coming in

From 363d2043fe9be81610699bfd895996be9359de64 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:54:12 +0200
Subject: [PATCH 52/66] fixes

---
 modules/printengine.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index d9cd87b..cdef1ee 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -307,7 +307,8 @@
 $z=$z+$zdelta;
 my @command_list=("G1 Z $z F1");
 send_commands(@command_list);
-
+my $zsleep=$zdelta*$Z_speed*1000000 #microseconds
+Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }
 $fb->clear_screen('ON');

From 08f7f018c7e2b61910ca571903700181c42710a5 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:55:10 +0200
Subject: [PATCH 53/66] fixes

---
 modules/printengine.cfg | 4 ++--
 modules/printengine.pl  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 976d621..8867dec 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -12,8 +12,8 @@ logging_enabled="TRUE"
 controllerboard="raspiarduinoramps"
 arduinotty="/dev/ttyACM0"
 arduinottybaudrate="115200"
-
-steps_per_mm="100" #steps needed to move the Z-Axis 1mm
+steps_per_mm="100"
+#steps needed to move the Z-Axis 1mm
 projector_type="Lightcrafter4500"
 #default Light engine
 projector_usb_device="/dev/ttyUSB0"
diff --git a/modules/printengine.pl b/modules/printengine.pl
index cdef1ee..da1f918 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -307,7 +307,7 @@
 $z=$z+$zdelta;
 my @command_list=("G1 Z $z F1");
 send_commands(@command_list);
-my $zsleep=$zdelta*$Z_speed*1000000 #microseconds
+my $zsleep=$zdelta*$Z_speed*1000000; #microseconds
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From 07cbb8430d08de82e30be823e888880c816cf012 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 19:58:42 +0200
Subject: [PATCH 54/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index da1f918..465454b 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -307,7 +307,7 @@
 $z=$z+$zdelta;
 my @command_list=("G1 Z $z F1");
 send_commands(@command_list);
-my $zsleep=$zdelta*$Z_speed*1000000; #microseconds
+my $zsleep=$zdelta*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From c9ce51ae413673010a188064bb9ebc485b889318 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Sun, 26 Jun 2016 20:01:31 +0200
Subject: [PATCH 55/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 465454b..a38893f 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -305,7 +305,7 @@
 Time::HiRes::usleep("$exposure_time_us");
 $fb->clear_screen('OFF');
 $z=$z+$zdelta;
-my @command_list=("G1 Z $z F1");
+my @command_list=("G1 Z $z F $Z_speed");
 send_commands(@command_list);
 my $zsleep=$zdelta*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");

From 3ee6c28de2820d839d8db3877dbc052c4d731c1a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Mon, 4 Jul 2016 13:48:35 +0200
Subject: [PATCH 56/66] better handling of time needed for movement,
 implemented overshoot handling

---
 modules/printengine.pl | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index a38893f..07c445c 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -276,7 +276,7 @@
 # Home Z-Axis
 my @command_list=('G21','G28 Z');
 send_commands(@command_list);
-sleep 10;
+sleep 30;
 my $z=0;
 my $zdelta=$layer_height/1000;
 #
@@ -305,28 +305,16 @@
 Time::HiRes::usleep("$exposure_time_us");
 $fb->clear_screen('OFF');
 $z=$z+$zdelta;
-my @command_list=("G1 Z $z F $Z_speed");
+my $ztemp=$z+$overshoot;
+my @command_list=("G1 Z $ztemp F $zspeed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
-my $zsleep=$zdelta*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
+my $zsleep=$zdelta*$Z_speed*60*1000000+$overshoot*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }
 $fb->clear_screen('ON');
-##sendcode- to be adapted/rewritten taken from http://www.contraptor.org/about
-#use Device::SerialPort;
-#use Time::HiRes qw/sleep/;
-#use Slurp;
- 
-#Slup each file into a command list
-#my @command_list;
-#for my $file ( @ARGV ){
-#    push @command_list, split('\n',slurp $file);
-#}
- 
-#If your board autoresets when talked to ( like a Sanguino ), you can uncomment the line bellow to get the machine to home position before sending the actual gcode
-#send_commands('G21','G91','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150');
- 
-#send_commands(@command_list);
+##sendcode- adapted and partially rewritten, inspiration taken from http://www.contraptor.org/about
+
  
 sub send_commands{
     my @command_list = @_;

From 69810a114af1e1ae5a3fc2f9f6ea2a7a40b11a97 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:15:11 +0200
Subject: [PATCH 57/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 07c445c..3806d58 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -306,7 +306,7 @@
 $fb->clear_screen('OFF');
 $z=$z+$zdelta;
 my $ztemp=$z+$overshoot;
-my @command_list=("G1 Z $ztemp F $zspeed","G1 Z $z F $Z_speed");
+my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
 my $zsleep=$zdelta*$Z_speed*60*1000000+$overshoot*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");

From 374cef213a88e7583b05b60be1be7d71e7fa754e Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:33:41 +0200
Subject: [PATCH 58/66] tuning of parameters for Z drive

---
 modules/printengine.cfg | 2 +-
 modules/printengine.pl  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/printengine.cfg b/modules/printengine.cfg
index 8867dec..a7c06b7 100644
--- a/modules/printengine.cfg
+++ b/modules/printengine.cfg
@@ -28,7 +28,7 @@ door_contact="TRUE"
 #Defines if there is a door contact to determine if the enclosure is closed
 X_pixels="912"
 Y_pixels="1140"
-Z_speed="1"
+Z_speed="5"
 #mm/s
 Z_max_speed="10"
 #mm/s
diff --git a/modules/printengine.pl b/modules/printengine.pl
index 3806d58..8916562 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -303,7 +303,7 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
-$fb->clear_screen('OFF');
+#$fb->clear_screen('OFF');
 $z=$z+$zdelta;
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");

From 7dd4087239a954b1282efcb74e5a5650ccc2c3e7 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:36:30 +0200
Subject: [PATCH 59/66] fixes

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 8916562..3806d58 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -303,7 +303,7 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
-#$fb->clear_screen('OFF');
+$fb->clear_screen('OFF');
 $z=$z+$zdelta;
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");

From 7c55f968773e57a1d56a4ad37d0c41ad565fd70a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:42:57 +0200
Subject: [PATCH 60/66] fixed wait for movement

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 3806d58..ceaded5 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -308,7 +308,7 @@
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
-my $zsleep=$zdelta*$Z_speed*60*1000000+$overshoot*$Z_speed*60*1000000; #microseconds, conversion from mm/min to mm/s
+my $zsleep=$zdelta*$Z_speed/60*1000000+$overshoot*$Z_speed/60*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From 8737798ab130a9fa98f516da0ccf2c7797fb80a7 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:48:25 +0200
Subject: [PATCH 61/66] fixes - should have checked the maths first

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index ceaded5..796631d 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -308,7 +308,7 @@
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
-my $zsleep=$zdelta*$Z_speed/60*1000000+$overshoot*$Z_speed/60*1000000; #microseconds, conversion from mm/min to mm/s
+my $zsleep=60*$zdelta/$Z_speed*1000000+60*$overshoot/$Z_speed*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From 9a92ac9ee3c5adae1c739ea772829ee5937a1b95 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:52:38 +0200
Subject: [PATCH 62/66] more readable and correctted

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 796631d..1f5737f 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -308,7 +308,7 @@
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
-my $zsleep=60*$zdelta/$Z_speed*1000000+60*$overshoot/$Z_speed*1000000; #microseconds, conversion from mm/min to mm/s
+my $zsleep=60*(*$zdelta+2*$overshoot)/$Z_speed*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From 88c7e2bc4ed762d25b8cc0463ff40fe620837b81 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Wed, 13 Jul 2016 19:56:35 +0200
Subject: [PATCH 63/66] fexed typo

---
 modules/printengine.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 1f5737f..b09bba8 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -308,7 +308,7 @@
 my $ztemp=$z+$overshoot;
 my @command_list=("G1 Z $ztemp F $Z_speed","G1 Z $z F $Z_speed");
 send_commands(@command_list);
-my $zsleep=60*(*$zdelta+2*$overshoot)/$Z_speed*1000000; #microseconds, conversion from mm/min to mm/s
+my $zsleep=60*($zdelta+2*$overshoot)/$Z_speed*1000000; #microseconds, conversion from mm/min to mm/s
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }

From af4ea72770dee4d74b2600634e0ef03b9eb13db9 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 22 Jul 2016 14:16:51 +0200
Subject: [PATCH 64/66] added code to turn LED off and on using the RAMPS Pin

---
 modules/printengine.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index b09bba8..1662109 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -224,7 +224,7 @@
 }
 
 else { #if the configured Display software matches none of the supported packages, die
-say "unknows display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
+say "unknown display software $display_software , please review your configuration, get in touch with developers or fork the code on Github and contribute the code to use the new printer"
 ;
 die "unknown display software in configuration!\n";
 }
@@ -277,6 +277,7 @@
 my @command_list=('G21','G28 Z');
 send_commands(@command_list);
 sleep 30;
+
 my $z=0;
 my $zdelta=$layer_height/1000;
 #
@@ -285,6 +286,9 @@
 my $fb = Graphics::Framebuffer->new( FB_DEVICE=>$display_device, SPLASH=>0 );
 $fb->clear_screen('OFF');
 foreach(@pics_sorted){
+#turn on LED  -LED is mapped to the Fan, Fan Pin in Firmware has been set to a PWM pin.
+my @command_list=('M106 S255');
+send_commands(@command_list);
  $fb->blit_write(
   $fb->load_image(
          {   
@@ -303,6 +307,8 @@
      )
  );
 Time::HiRes::usleep("$exposure_time_us");
+my @command_list=('M107');
+send_commands(@command_list);
 $fb->clear_screen('OFF');
 $z=$z+$zdelta;
 my $ztemp=$z+$overshoot;
@@ -312,6 +318,7 @@
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }
+
 $fb->clear_screen('ON');
 ##sendcode- adapted and partially rewritten, inspiration taken from http://www.contraptor.org/about
 

From 52918c91564577c56a4a490156268c8329a37b8a Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 18 Nov 2016 18:45:12 +0100
Subject: [PATCH 65/66] added homing at end of print for easier retrieval of
 printed parts

---
 modules/printengine.pl | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/modules/printengine.pl b/modules/printengine.pl
index 1662109..6e909ed 100755
--- a/modules/printengine.pl
+++ b/modules/printengine.pl
@@ -318,6 +318,9 @@
 Time::HiRes::usleep("$zsleep");
 Time::HiRes::usleep("$resin_settling_time_us");
 }
+#home Z axis to retrieve printed parts
+my @command_list=('G28 Z');
+send_commands(@command_list);
 
 $fb->clear_screen('ON');
 ##sendcode- adapted and partially rewritten, inspiration taken from http://www.contraptor.org/about

From 18a3c6872d2f8c8a4928221351fcd889debcb769 Mon Sep 17 00:00:00 2001
From: Robert Koeppl <rkoeppl@gmx.at>
Date: Fri, 18 Nov 2016 18:53:36 +0100
Subject: [PATCH 66/66] added script to send gcode to controller and example
 gcode

---
 modules/g1.gcode |  2 ++
 modules/send.pl  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 modules/g1.gcode
 create mode 100755 modules/send.pl

diff --git a/modules/g1.gcode b/modules/g1.gcode
new file mode 100644
index 0000000..a87fbb5
--- /dev/null
+++ b/modules/g1.gcode
@@ -0,0 +1,2 @@
+G28 Z
+G1 Z30 F30
diff --git a/modules/send.pl b/modules/send.pl
new file mode 100755
index 0000000..46ceab5
--- /dev/null
+++ b/modules/send.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+use Device::SerialPort;
+use Time::HiRes qw/sleep/;
+use Slurp;
+ 
+#Slup each file into a command list
+my @command_list;
+for my $file ( @ARGV ){
+    push @command_list, split('\n',slurp $file);
+}
+ 
+#If your board autoresets when talked to ( like a Sanguino ), you can uncomment the line bellow to get the machine to home position before sending the actual gcode
+#send_commands('G21','G91','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150','G1 X-150 Y-150');
+ 
+send_commands(@command_list);
+ 
+sub send_commands{
+    my @command_list = @_;
+ 
+    #Open port
+    my $port = Device::SerialPort->new("/dev/ttyACM0");
+ 
+    # 19200, 81N on the USB ftdi driver
+    $port->baudrate(115200);
+    $port->databits(8);
+    $port->parity("none");
+    $port->stopbits(1);
+ 
+    while (1) {
+        # Poll to see if any data is coming in
+        if ( my $char = $port->lookfor() ) {
+            $char =~ s/\r//;
+            print "$char\n";
+            if( $char =~ m/^(ok|start)$/){
+                #Send next command
+                my $next_command = shift @command_list;
+                print "$next_command\n";
+                $port->write("$next_command\n");
+            }else{
+                print "unknown: $char\n";
+            }
+        }
+        sleep 0.01;
+        unless(@command_list){last; }
+    }
+}
+
