From: Michael Wiebusch Date: Thu, 27 Nov 2014 18:30:25 +0000 (+0100) Subject: better user interface X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=aa07e7fdc6c376b4ba8c05bb02f0360ef1420722;p=labtools.git better user interface --- diff --git a/peltier_controller/webGUI/index.pl b/peltier_controller/webGUI/index.pl index 7435f55..8d248e7 100755 --- a/peltier_controller/webGUI/index.pl +++ b/peltier_controller/webGUI/index.pl @@ -173,12 +173,14 @@ sub plot { my $self = shift; my %options = @_; + my $clientId = $options{clientId} || 0; my $html = $options{html}; my $shm_manager = $self->create_shm_manager(); my $plotting_tool = plotting_tool->new( columnNames => $self->{columnNames}, - dataFile => $shm_manager->{dataFile} + dataFile => $shm_manager->{dataFile}, + clientId => $clientId ); @@ -187,16 +189,20 @@ sub plot { my $changed = 0; + + # the following block of code checks, whether the data file got new entries + # since the last time my $dataFile_modificationTime = (stat($dataFile))[9]; + my $shmHash = $shm_manager->lockAndReadShm(); + my $dataFile_lastModificationTime = $shmHash->{dataFile_lastModificationTime}||""; + $shmHash->{dataFile_lastModificationTime} = $dataFile_modificationTime; + $shm_manager->writeShm($shmHash); # unlocks the shm file -# my $dataFile_lastModificationTime = $shm_manager->readShm()->{dataFile_lastModificationTime}||""; -# $shm_manager->updateShm({dataFile_lastModificationTime => $dataFile_modificationTime}); -# if( $dataFile_modificationTime ne $dataFile_lastModificationTime) { -# $plotting_tool->plot(); -# } + #only plot if data file has been modified + if( $dataFile_modificationTime ne $dataFile_lastModificationTime) { + $plotting_tool->plot(); + } - $plotting_tool->plot(); - $plotFile =~ s%/dev/%%; print header('text/html'); diff --git a/peltier_controller/webGUI/logging_tool.pm b/peltier_controller/webGUI/logging_tool.pm index 12042ac..f9ced9d 100644 --- a/peltier_controller/webGUI/logging_tool.pm +++ b/peltier_controller/webGUI/logging_tool.pm @@ -63,6 +63,9 @@ sub main { open(LOG,">> ".$dataFile); $data = $serial->communicate($setpoint); $now = sprintf "%02d.%02d.%02d_%02d:%02d:%02d",(localtime)[3],((localtime)[4] +1),((localtime)[5] -100),(localtime)[2],(localtime)[1],(localtime)[0]; + $shm_manager->updateShm({ + latest_data => $data, latest_data_timestamp => $now + }); print LOG "$now\t"; print "$now\t" if $verbose; for my $column_name (@{$self->{columnNames}}) { diff --git a/peltier_controller/webGUI/peltierControl.js b/peltier_controller/webGUI/peltierControl.js index 4058f2f..b859462 100644 --- a/peltier_controller/webGUI/peltierControl.js +++ b/peltier_controller/webGUI/peltierControl.js @@ -2,6 +2,8 @@ var timer; var acquisition = 0; +var clientId = Math.random(); + $(document).ready(function(){ @@ -22,7 +24,8 @@ function plot(){ async: false, dataType: "text", data: { - action : "plot" + action : "plot", + clientId : clientId }, success: function(result) { $("#plotContainer").html(result); @@ -122,6 +125,10 @@ function activate_components(){ } } + if(typeof shm.latest_data != 'undefined') { + $('#input_setpoint').attr("value",Math.floor(shm.latest_data.setpoint)); + } + // $("#savebutton").click(function(){ // write_file(); // set_clear_timer(); diff --git a/peltier_controller/webGUI/plotting_tool.pm b/peltier_controller/webGUI/plotting_tool.pm index 7e96a94..01f7e0e 100644 --- a/peltier_controller/webGUI/plotting_tool.pm +++ b/peltier_controller/webGUI/plotting_tool.pm @@ -14,13 +14,14 @@ sub new { title => "Peltier Cooling System Temperature", width => 640, height => 480, + clientId => "0", %options }; die "plotting tool needs to be given a dataFile" unless(defined($self->{dataFile})); die "plotting tool needs to be given a list containing colum names" unless(defined($self->{columnNames})); - $self->{plotFile} = $self->{dataFile}.".gif"; + $self->{plotFile} = $self->{dataFile}."_".$self->{clientId}.".gif"; bless($self, $class); } diff --git a/peltier_controller/webGUI/webpage.pm b/peltier_controller/webGUI/webpage.pm index b1dc8db..6454d47 100644 --- a/peltier_controller/webGUI/webpage.pm +++ b/peltier_controller/webGUI/webpage.pm @@ -5,6 +5,7 @@ use strict; use warnings; use POSIX; use CGI ':standard'; +use JSON; use CGI::Carp qw(fatalsToBrowser); sub new { @@ -95,16 +96,28 @@ sub print_device_controls { } +# sub passHashToJs { +# +# my $hashref = shift(); +# my $objname = shift(); +# $objname = 'fromPerl' unless (defined($objname)); +# print ""; +# +# } + sub passHashToJs { my $hashref = shift(); my $objname = shift(); $objname = 'fromPerl' unless (defined($objname)); print ""; }