From: Jan Michel Date: Tue, 25 Aug 2015 14:51:10 +0000 (+0200) Subject: working version of sensor display X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=6e07ab0ca01ee2da1fb830bf3c6e51af12e3770e;p=labtools.git working version of sensor display --- diff --git a/sensors/style.css b/sensors/style.css index 42a6717..2e255d4 100644 --- a/sensors/style.css +++ b/sensors/style.css @@ -52,7 +52,7 @@ h1{ height:100%; margin-left:5px; margin-top:2px; - font-size:20px; + font-size:17px; user-select: none; -moz-user-select: none; } diff --git a/sensors/update.pl b/sensors/update.pl index eb6812a..dcef996 100755 --- a/sensors/update.pl +++ b/sensors/update.pl @@ -4,6 +4,7 @@ print "Content-Type: text/html; charset=utf-8\r\n\r\n"; use warnings; use strict; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); +use CGI; use utf8; use POSIX; use List::Util qw(min max); @@ -11,10 +12,14 @@ use List::Util qw(min max); my $min = 1000; my $max = -1000; +my $query = CGI->new; +my $lines = $query->param('lines') || 50; + + sub defineScale { my $aref = shift @_; - $min = min(@{$aref}); - $max = max(@{$aref}); + $min = min(grep {defined $_} @{$aref}); + $max = max(grep {defined $_} @{$aref}); $min = floor($min/5)*5; $max = ceil($max/5)*5; @@ -79,7 +84,8 @@ sub DrawScale { } my $values; -my $tfile = "tail -n40 data/pt100.log"; +my $count; +my $tfile = "tail -n$lines data/pt100.log"; open(my $tdata, '-|', $tfile) or die "Could not open '$tfile' $!\n"; while (my $line = <$tdata>) { #AT051028a0 @@ -87,10 +93,16 @@ while (my $line = <$tdata>) { next if $2 >= 8; my $v = hex($4); $v -= 0x100000 if $v >= 0x80000; - $values->[$1*8+$2] = $v/1000.; - $values->[$1*8+$2] = undef unless $3; + $values->[$1*8+$2] += $v/1000.; + $count->[$1*8+$2]++; + $values->[$1*8+$2] = undef if $3; } } + +for (my $i = 0; $i < scalar @{$values};$i++){ + $values->[$i] = $values->[$i] / $count->[$i] if defined $values->[$i]; + } + defineScale($values); @@ -106,7 +118,7 @@ while (my $line = <$cdata>) { print "
[$f[0]*8+$f[1]],$min,$max)."\">
$val
-
$f[0]/$f[1]
+
$f[0].$f[1]/".($count->[$f[0]*8+$f[1]]||0)."
$f[4]
"; @@ -115,4 +127,4 @@ while (my $line = <$cdata>) { } print '
'.DrawScale($min,$max,50).'
'; - \ No newline at end of file +