mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
98_Arducounter.pm: new version to better support monitoring of analog levels for reflective light barrier
git-svn-id: https://svn.fhem.de/fhem/trunk@19977 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
adee750682
commit
afad22090a
@ -81,10 +81,14 @@
|
|||||||
# 2019-02-24 added documentation and better return value when get history has no data, option to pass a pinName to get history
|
# 2019-02-24 added documentation and better return value when get history has no data, option to pass a pinName to get history
|
||||||
# query new running config after configuring device
|
# query new running config after configuring device
|
||||||
# 2019-06-17 fix log messages and expose logRetries attribute
|
# 2019-06-17 fix log messages and expose logRetries attribute
|
||||||
|
# 2019-07-20 add clearLevels, parese more verbose level output at 25v
|
||||||
|
# 2019-08-10 fix parsing of levels at devVerbose >= 25
|
||||||
|
#
|
||||||
#
|
#
|
||||||
# ideas / todo:
|
# ideas / todo:
|
||||||
#
|
#
|
||||||
# - max time for interpolation as attribute
|
# - max time for interpolation as attribute
|
||||||
|
# - detect level threasholds automatically for analog input, track drift
|
||||||
#
|
#
|
||||||
# - convert module to package
|
# - convert module to package
|
||||||
#
|
#
|
||||||
@ -104,7 +108,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
|
|
||||||
my $ArduCounter_Version = '6.15 - 17.6.2019';
|
my $ArduCounter_Version = '6.17 - 10.8.2019';
|
||||||
|
|
||||||
|
|
||||||
my %ArduCounter_sets = (
|
my %ArduCounter_sets = (
|
||||||
@ -113,7 +117,8 @@ my %ArduCounter_sets = (
|
|||||||
"raw" => "",
|
"raw" => "",
|
||||||
"reset" => "",
|
"reset" => "",
|
||||||
"flash" => "",
|
"flash" => "",
|
||||||
"saveConfig" => "",
|
"saveConfig" => "",
|
||||||
|
"clearLevels" => "",
|
||||||
"reconnect" => ""
|
"reconnect" => ""
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1001,6 +1006,10 @@ sub ArduCounter_Set($@)
|
|||||||
ArduCounter_Open($hash);
|
ArduCounter_Open($hash);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} elsif ($attr eq "clearLevels") {
|
||||||
|
delete $hash->{analogLevels};
|
||||||
|
return;
|
||||||
|
|
||||||
} elsif ($attr eq "flash") {
|
} elsif ($attr eq "flash") {
|
||||||
return ArduCounter_Flash($hash, @a);
|
return ArduCounter_Flash($hash, @a);
|
||||||
}
|
}
|
||||||
@ -1050,6 +1059,14 @@ sub ArduCounter_Get($@)
|
|||||||
return "Unknown argument $attr, choose one of " . join(" ", @cList);
|
return "Unknown argument $attr, choose one of " . join(" ", @cList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($attr eq "levels") {
|
||||||
|
my $msg = "";
|
||||||
|
foreach my $level (sort {$a <=> $b} keys %{$hash->{analogLevels}}) {
|
||||||
|
$msg .= "$level: $hash->{analogLevels}{$level}\n";
|
||||||
|
}
|
||||||
|
return "observed levels from analog input:\n$msg\n";
|
||||||
|
}
|
||||||
|
|
||||||
if(!$hash->{FD}) {
|
if(!$hash->{FD}) {
|
||||||
Log3 $name, 4, "$name: Get called but device is disconnected";
|
Log3 $name, 4, "$name: Get called but device is disconnected";
|
||||||
return ("Get called but device is disconnected", undef);
|
return ("Get called but device is disconnected", undef);
|
||||||
@ -1089,13 +1106,6 @@ sub ArduCounter_Get($@)
|
|||||||
$ret;
|
$ret;
|
||||||
}
|
}
|
||||||
return ($ret ? $ret : "no history data so far");
|
return ($ret ? $ret : "no history data so far");
|
||||||
|
|
||||||
} elsif ($attr eq "levels") {
|
|
||||||
my $msg = "";
|
|
||||||
foreach my $level (sort {$a <=> $b} keys %{$hash->{analogLevels}}) {
|
|
||||||
$msg .= "$level: $hash->{analogLevels}{$level}\n";
|
|
||||||
}
|
|
||||||
return "observed levels from analog input:\n$msg\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -1600,7 +1610,13 @@ sub ArduCounter_Parse($)
|
|||||||
$retStr .= ($retStr ? "\n" : "") . $line;
|
$retStr .= ($retStr ? "\n" : "") . $line;
|
||||||
Log3 $name, 4, "$name: device: $1";
|
Log3 $name, 4, "$name: device: $1";
|
||||||
|
|
||||||
} elsif ($line =~ /^L([\d]+)/) { # analog level difference reported
|
} elsif ($line =~ /^L *([\d]+) ?, ?([\d]+) ?, ?-> *([\d]+)/) { # analog level difference reported with details
|
||||||
|
if ($hash->{analogLevels}{$3}) {
|
||||||
|
$hash->{analogLevels}{$3}++;
|
||||||
|
} else {
|
||||||
|
$hash->{analogLevels}{$3} = 1;
|
||||||
|
}
|
||||||
|
} elsif ($line =~ /^L *([\d]+)/) { # analog level difference reported
|
||||||
if ($hash->{analogLevels}{$1}) {
|
if ($hash->{analogLevels}{$1}) {
|
||||||
$hash->{analogLevels}{$1}++;
|
$hash->{analogLevels}{$1}++;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user