mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
00_OWX.pm: Neue Version, kleinere Fixes
11_OWX_CCC: Neue Version, kleinere Fixes 11_OWX_FRM: Neue Version, kleinere Fixes 11_OWX_SER: Neue Version, kleinere Fixes 11_OWX_TCP: Neue Version, kleinere Fixes 21_OWAD.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWCOUNT.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWID.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWLCD.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWMULTI.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWSWITCH.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWTHERM.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes 21_OWVAR.pm: Neue Version, Support für OWX_ASYNC entfernt, kleinere Fixes git-svn-id: https://svn.fhem.de/fhem/trunk@23553 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
63224a3fbb
commit
3631929b91
@ -99,7 +99,7 @@ my %sets = (
|
||||
);
|
||||
|
||||
#-- some globals needed for the 1-Wire module
|
||||
$owx_version="7.21";
|
||||
$owx_version="7.23";
|
||||
|
||||
#-- debugging now verbosity, this is just for backward compatibility
|
||||
$owx_debug=0;
|
||||
|
@ -54,7 +54,7 @@ sub new($) {
|
||||
return bless {
|
||||
hash => $hash,
|
||||
#-- module version
|
||||
version => "7.21"
|
||||
version => "7.23"
|
||||
}, $class;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ sub new($) {
|
||||
return bless {
|
||||
hash => $hash,
|
||||
#-- module version
|
||||
version => "7.21"
|
||||
version => "7.23"
|
||||
}, $class;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ sub new($) {
|
||||
#-- OWX device
|
||||
hash => $hash,
|
||||
#-- module version
|
||||
version => "7.21",
|
||||
version => "7.23",
|
||||
#-- baud rate serial interface
|
||||
baud => 9600,
|
||||
#-- 16 byte search string
|
||||
|
@ -60,7 +60,7 @@ sub new($) {
|
||||
#-- OWX device
|
||||
hash => $hash,
|
||||
#-- module version
|
||||
version => "7.21",
|
||||
version => "7.23",
|
||||
#-- 16 byte search string
|
||||
search => [0,0,0,0 ,0,0,0,0, 0,0,0,0, 0,0,0,0],
|
||||
ROM_ID => [0,0,0,0 ,0,0,0,0],
|
||||
|
@ -1,11 +1,10 @@
|
||||
########################################################################################
|
||||
#
|
||||
# OWAD.pm
|
||||
# OWAD.pm
|
||||
#
|
||||
# FHEM module to commmunicate with 1-Wire A/D converters DS2450
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning
|
||||
# Norbert Truchsess
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -32,23 +31,10 @@ package main;
|
||||
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||
use strict;
|
||||
use warnings;
|
||||
use GPUtils qw(:all);
|
||||
use Time::HiRes qw( gettimeofday );
|
||||
|
||||
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
my $owx_version="7.23";
|
||||
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
sub Log3($$$);
|
||||
|
||||
my $owx_version="7.01";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B","C","D");
|
||||
my @owg_channel = ("A","B","C","D");
|
||||
@ -68,7 +54,7 @@ my %gets = (
|
||||
);
|
||||
|
||||
my %sets = (
|
||||
"initialize" => "",
|
||||
"initialize" => ":noArg",
|
||||
"interval" => "",
|
||||
"AAlarm" => "",
|
||||
"ALow" => "",
|
||||
@ -224,8 +210,6 @@ sub OWAD_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWAD: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$main::modules{OWAD}{defptr}{$id} = $hash;
|
||||
@ -313,7 +297,6 @@ sub OWAD_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($init_done) {
|
||||
OWAD_Init($hash);
|
||||
}
|
||||
@ -393,6 +376,8 @@ sub OWAD_FormatValues($) {
|
||||
#-- TODO $hash->{owg_val}->[..] might be undefined here?
|
||||
$vfuncall .= "\$hash->{owg_val}->[$k]=$hash->{owg_val}->[$k];";
|
||||
}
|
||||
#-- replaced this, insert numerical values directly
|
||||
|
||||
my $alarm;
|
||||
my $galarm = 0;
|
||||
my $achange = 0;
|
||||
@ -425,14 +410,17 @@ sub OWAD_FormatValues($) {
|
||||
$hash->{tempf}{$owg_fixed[$i]}{function} = $vfunc;
|
||||
|
||||
#-- replace by proper values (VA -> $hash->{owg_val}->[0] etc.)
|
||||
# careful: how to prevent {VAL} from being replaced ?
|
||||
for( my $k=0;$k<int(@owg_fixed);$k++ ){
|
||||
#--- value to be replaced
|
||||
my $sstr = "V$owg_fixed[$k]";
|
||||
#-- protect VAL
|
||||
$vfunc =~ s/VAL/WERT/g;
|
||||
$vfunc =~ s/$sstr/\$hash->{owg_val}->[$k]/g;
|
||||
#-- do the substitution
|
||||
$vfunc =~ s/$sstr/\(\$hash->{owg_val}->[$k]\)/g;
|
||||
#-- unprotect VAL
|
||||
$vfunc =~ s/WERT/VAL/g;
|
||||
}
|
||||
|
||||
|
||||
#-- determine the measured value from the function
|
||||
$vfunc = $vfuncall.$vfunc;
|
||||
$vfunc = eval($vfunc);
|
||||
@ -559,11 +547,6 @@ sub OWAD_Get($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXAD_GetPage($hash,"reading",1);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"reading",1));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSAD_GetPage($hash,"reading",1);
|
||||
@ -589,11 +572,6 @@ sub OWAD_Get($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXAD_GetPage($hash,"alarm",1);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"alarm",1));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSAD_GetPage($hash,"alarm",1);
|
||||
@ -627,11 +605,6 @@ sub OWAD_Get($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXAD_GetPage($hash,"status",1);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXAD_PT_GetPage($hash,"status",1));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSAD_GetPage($hash,"status",1);
|
||||
@ -723,13 +696,6 @@ sub OWAD_GetValues($) {
|
||||
$ret1 = OWXAD_GetPage($hash,"reading",0);
|
||||
$ret2 = OWXAD_GetPage($hash,"alarm",0);
|
||||
$ret3 = OWXAD_GetPage($hash,"status",1);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"reading",0));
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"alarm",0));
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_GetPage($hash,"status",1));
|
||||
};
|
||||
$ret .= GP_Catch($@) if $@;
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret1 = OWFSAD_GetPage($hash,"reading",0);
|
||||
$ret2 = OWFSAD_GetPage($hash,"alarm",0);
|
||||
@ -819,12 +785,6 @@ sub OWAD_InitializeDevice($) {
|
||||
if( $interface eq "OWX" ){
|
||||
$ret1 = OWXAD_SetPage($hash,"status");
|
||||
$ret2 = OWXAD_SetPage($hash,"alarm");
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"alarm"));
|
||||
};
|
||||
$ret .= GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret1 = OWFSAD_SetPage($hash,"status");
|
||||
@ -860,12 +820,14 @@ sub OWAD_Set($@) {
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
|
||||
#-- for the selector: which values are possible
|
||||
return join(" ", sort keys %sets) if(@a == 2);
|
||||
|
||||
#-- check syntax
|
||||
return "OWAD: Set needs one parameter when setting this value"
|
||||
if( int(@a)!=3 );
|
||||
my $msg = "";
|
||||
#-- for the selector: which values are possible - but only if not initialization key
|
||||
if(@a != 3){
|
||||
if( $key ne "initialize" ){
|
||||
$msg .= "$_$sets{$_} " foreach (keys%sets);
|
||||
return $msg
|
||||
}
|
||||
}
|
||||
|
||||
#-- check argument
|
||||
if( !defined($sets{$a[1]}) && !($key =~ m/.*(Alarm|Low|High)/) ){
|
||||
@ -940,11 +902,6 @@ sub OWAD_Set($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXAD_SetPage($hash,"status");
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSAD_SetPage($hash,"status");
|
||||
@ -991,11 +948,6 @@ sub OWAD_Set($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXAD_SetPage($hash,"alarm");
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXAD_PT_SetPage($hash,"status"));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSAD_SetPage($hash,"alarm");
|
||||
@ -1067,7 +1019,6 @@ sub OWFSAD_GetPage($$$) {
|
||||
if( $page eq "reading"){
|
||||
#-- get values - or should we rather use the uncached ones ?
|
||||
$rel = OWServer_Read($master,"/$owx_add/volt.ALL");
|
||||
|
||||
return "no return from OWServer"
|
||||
if( !defined($rel) );
|
||||
return "empty return from OWServer"
|
||||
@ -1079,6 +1030,7 @@ sub OWFSAD_GetPage($$$) {
|
||||
if( int(@ral) != 4);
|
||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||
$hash->{owg_val}->[$i]= int($ral[$i]*1000)/1000;
|
||||
#Log 1,"=====> ".$hash->{owg_val}->[$i];
|
||||
}
|
||||
#=============== get the alarm reading ===============================
|
||||
} elsif ( $page eq "alarm" ) {
|
||||
@ -1179,6 +1131,8 @@ sub OWFSAD_GetPage($$$) {
|
||||
#-- and now from raw to formatted values
|
||||
$hash->{PRESENT} = 1;
|
||||
if( $final==1 ){
|
||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||
}
|
||||
my $value = OWAD_FormatValues($hash);
|
||||
Log 5, $value;
|
||||
}
|
||||
@ -1314,6 +1268,13 @@ sub OWXAD_BinValues($$$$$$$) {
|
||||
for( my $i=0;$i<int(@owg_fixed);$i++){
|
||||
$hash->{owg_val}->[$i]= (ord($data[2*$i])+256*ord($data[1+2*$i]) )/(1<<$owg_resoln[$i]) * $owg_range[$i]/1000;
|
||||
}
|
||||
|
||||
2021.01.17 05:31:05 1: PERL WARNING: Use of uninitialized value within @owg_resoln in left bitshift (<<) at /opt/fhem/FHEM/21_OWAD.pm line 1270.
|
||||
2021.01.17 05:31:05 1: PERL WARNING: Use of uninitialized value in multiplication (*) at /opt/fhem/FHEM/21_OWAD.pm line 1270.
|
||||
2021.01.17 05:31:06 1: PERL WARNING: Use of uninitialized value in multiplication (*) at /opt/fhem/FHEM/21_OWAD.pm line 1276.
|
||||
2021.01.17 05:31:06 1: PERL WARNING: Use of uninitialized value in multiplication (*) at /opt/fhem/FHEM/21_OWAD.pm line 1277.
|
||||
|
||||
|
||||
#=============== get the alarm reading ===============================
|
||||
} elsif ( $context =~ /^ds2450.getalarm/ ){
|
||||
for( my $i=0;$i<int(@owg_fixed);$i++){
|
||||
@ -1545,155 +1506,6 @@ sub OWXAD_SetPage($$) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXAD_PT_GetPage - Get one memory page from device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = "reading", "alarm" or "status"
|
||||
# final= 1 if FormatValues is to be called
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXAD_PT_GetPage($$$) {
|
||||
|
||||
my ($hash,$page,$final) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
|
||||
my ($res, $res2, $res3, @data, $an, $vn);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#=============== get the voltage reading ===============================
|
||||
if( $page eq "reading") {
|
||||
#-- issue the match ROM command \x55 and the start conversion command
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, "\x3C\x0F\x00\xFF\xFF", 0 );
|
||||
$thread->{ExecuteTime} = gettimeofday() + 0.07; # was 0.02
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
PT_YIELD_UNTIL(gettimeofday() >= $thread->{ExecuteTime});
|
||||
delete $thread->{ExecuteTime};
|
||||
|
||||
#-- issue the match ROM command \x55 and the read conversion page command
|
||||
# \xAA\x00\x00
|
||||
$thread->{'select'}="\xAA\x00\x00";
|
||||
#=============== get the alarm reading ===============================
|
||||
} elsif ( $page eq "alarm" ) {
|
||||
#-- issue the match ROM command \x55 and the read alarm page command
|
||||
# \xAA\x10\x00
|
||||
$thread->{'select'}="\xAA\x10\x00";
|
||||
#=============== get the status reading ===============================
|
||||
} elsif ( $page eq "status" ) {
|
||||
#-- issue the match ROM command \x55 and the read status memory page command
|
||||
# \xAA\x08\x00 r
|
||||
$thread->{'select'}="\xAA\x08\x00";
|
||||
#=============== wrong value requested ===============================
|
||||
} else {
|
||||
die "wrong memory page requested from $owx_dev";
|
||||
}
|
||||
#-- reading 9 + 3 + 8 data bytes and 2 CRC bytes = 22 bytes
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 10 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
my $response = $thread->{pt_execute}->PT_RETVAL();
|
||||
my $res = OWXAD_BinValues($hash,"ds2450.get".$page.($final ? ".final" : ""),1,$owx_dev,$thread->{'select'},10,$response);
|
||||
if ($res) {
|
||||
die $res;
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXAD_PT_SetPage - Set one page of device
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = "alarm" or "status"
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXAD_PT_SetPage($$) {
|
||||
|
||||
my ($hash,$page) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select, $res, $res2, $res3, @data);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#=============== set the alarm values ===============================
|
||||
if ( $page eq "alarm" ) {
|
||||
#-- issue the match ROM command \x55 and the set alarm page command
|
||||
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
|
||||
$select="\x55\x10\x00";
|
||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($hash->{owg_vlow}->[$i]*256000/$owg_range[$i]);
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",int($hash->{owg_vhigh}->[$i]*256000/$owg_range[$i]);
|
||||
}
|
||||
|
||||
#++Use of uninitialized value within @owg_vlow in multiplication at
|
||||
#++/usr/share/fhem/FHEM/21_OWAD.pm line 1362.
|
||||
#=============== set the status ===============================
|
||||
} elsif ( $page eq "status" ) {
|
||||
my ($sb1,$sb2)=(0,0);
|
||||
#-- issue the match ROM command \x55 and the set status memory page command
|
||||
# \x55\x08\x00 reading 8 data bytes and 2 CRC bytes
|
||||
$select="\x55\x08\x00";
|
||||
for( $i=0;$i<int(@owg_fixed);$i++){
|
||||
#if( $owg_mode[$i] eq "input" ){
|
||||
if( 1 > 0){
|
||||
#-- resolution (TODO: check !)
|
||||
$sb1 = $owg_resoln[$i] & 15;
|
||||
#-- alarm enabled
|
||||
if( defined($hash->{owg_slow}->[$i]) ){
|
||||
$sb2 = ( $hash->{owg_slow}->[$i] ne 0 ) ? 4 : 0;
|
||||
}
|
||||
if( defined($hash->{owg_shigh}->[$i]) ){
|
||||
$sb2 += ( $hash->{owg_shigh}->[$i] ne 0 ) ? 8 : 0;
|
||||
}
|
||||
#-- range
|
||||
$sb2 |= 1
|
||||
if( $owg_range[$i] > 2560 );
|
||||
} else {
|
||||
$sb1 = 128;
|
||||
$sb2 = 0;
|
||||
}
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb1;
|
||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb2;
|
||||
}
|
||||
#=============== wrong page write attempt ===============================
|
||||
} else {
|
||||
PT_EXIT("wrong memory page write attempt");
|
||||
}
|
||||
#"setpage"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $select, 0 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
@ -1703,6 +1515,7 @@ sub OWXAD_PT_SetPage($$) {
|
||||
|
||||
<a name="OWAD"></a>
|
||||
<h3>OWAD</h3>
|
||||
<ul>
|
||||
<p>FHEM module to commmunicate with 1-Wire A/D converters<br /><br />
|
||||
<br />This 1-Wire module works with the OWX interface module or with the OWServer interface module
|
||||
(prerequisite: Add this module's name to the list of clients in OWServer).
|
||||
@ -1752,8 +1565,14 @@ sub OWXAD_PT_SetPage($$) {
|
||||
<a name="OWADset"></a>
|
||||
<h4>Set</h4>
|
||||
<ul>
|
||||
<li><a name="owad_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
<li><a name="owad_initialize">
|
||||
<code>set <name> initialize </code></a><br /> Re-initialize the sensor device (range, resolution etc.). Necessary after power loss.</li>
|
||||
<li><a name="owad_alarm">
|
||||
<code>set <name> (A|B|C|D)Alarm (none|low|high|both)</code> Set the device into alarme status if none, the high, low or both voltage limits are reached.</li>
|
||||
<li><a name="owad_alarmP">
|
||||
<code>set <name> (A|B|C|D)(Low|High) <voltage value></code> Set one of the voltage limits for alarm status</li>
|
||||
<li><a name="owad_interval">
|
||||
<code>set <name> interval <int></code></a><br /> Measurement
|
||||
interval in seconds. The default is 300 seconds, a value of 0 disables the automatic update.</li>
|
||||
</ul>
|
||||
<br />
|
||||
@ -1809,6 +1628,7 @@ sub OWXAD_PT_SetPage($$) {
|
||||
<br />measurement value for highalarm. </li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
||||
|
@ -5,7 +5,6 @@
|
||||
# FHEM module to commmunicate with 1-Wire Counter/RAM DS2423
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning
|
||||
# Norbert Truchsess
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -32,22 +31,10 @@ package main;
|
||||
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw( gettimeofday );
|
||||
|
||||
#add FHEM/lib to @INC if it's not already included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
my $owx_version="7.23";
|
||||
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
|
||||
sub Log3($$$);
|
||||
|
||||
my $owx_version="7.01";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B");
|
||||
my @owg_channel = ("A","B");
|
||||
@ -220,8 +207,6 @@ sub OWCOUNT_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWCOUNT: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWCOUNT}{defptr}{$id} = $hash;
|
||||
@ -345,7 +330,6 @@ sub OWCOUNT_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($init_done) {
|
||||
OWCOUNT_Init($hash);
|
||||
}
|
||||
@ -582,9 +566,9 @@ sub OWCOUNT_FormatValues($) {
|
||||
if( $delt > 0.0 ){
|
||||
$dt = -$delf/$delt;
|
||||
$dval = int(($vval+($vval-$oldval)*$dt)*10000+0.5)/10000;
|
||||
Log3 $name,5,"OWCOUNT: midnight exploration $name channel ".$owg_channel[$i]." with time delta $delt, dt $dt and dval=$dval";
|
||||
Log3 $name,5,"OWCOUNT: midnight extrapolation $name channel ".$owg_channel[$i]." with time delta $delt, dt $dt and dval=$dval";
|
||||
}else{
|
||||
Log3 $name,5,"OWCOUNT: midnight exploration $name channel ".$owg_channel[$i]." fails because of zero time delta. dval=$dval";
|
||||
Log3 $name,5,"OWCOUNT: midnight extrapolation $name channel ".$owg_channel[$i]." fails because of zero time delta. dval=$dval";
|
||||
}
|
||||
if( $daily == 1 ){
|
||||
$dval2 = $dval+$hash->{owg_midnight}->[$i];
|
||||
@ -896,15 +880,6 @@ sub OWCOUNT_GetPage ($$$@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXCOUNT_GetPage($hash,$page,$final);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
if ($sync) {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXCOUNT_PT_GetPage($hash,$page,$final));
|
||||
} else {
|
||||
OWX_ASYNC_Schedule( $hash, OWXCOUNT_PT_GetPage($hash,$page,$final) );
|
||||
}
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSCOUNT_GetPage($hash,$page,$final);
|
||||
@ -1310,7 +1285,7 @@ sub OWCOUNT_Set($@) {
|
||||
if( defined($ret) && ($ret ne "") ){
|
||||
return "OWCOUNT: set $name $key failed, reason: ".$ret;
|
||||
}
|
||||
#-- Took this out, not possible in asynchronoues mode
|
||||
#-- Took this out, not possible in asynchronous mode
|
||||
#OWCOUNT_GetValues($hash);
|
||||
Log3 $name,5, "OWCOUNT: set $name $key $value";
|
||||
}
|
||||
@ -1342,11 +1317,6 @@ sub OWCOUNT_SetPage ($$$) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXCOUNT_SetPage($hash,$page,$data);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXCOUNT_PT_SetPage($hash,$page,$data) );
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSCOUNT_SetPage($hash,$page,$data);
|
||||
@ -1841,179 +1811,6 @@ sub OWXCOUNT_SetPage($$$) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXCOUNT_PT_GetPage - Get one memory page + counter from device async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = 0..15
|
||||
# final= 1 if FormatValues is to be called
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXCOUNT_PT_GetPage($$$) {
|
||||
|
||||
my ($hash,$page,$final) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
my ($thread) = @_;
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#=============== wrong value requested ===============================
|
||||
if( ($page<0) || ($page>15) ){
|
||||
die("wrong memory page requested");
|
||||
}
|
||||
#=============== get memory + counter ===============================
|
||||
#-- issue the match ROM command \x55 and the read memory + counter command
|
||||
# \xA5 TA1 TA2 reading 40 data bytes and 2 CRC bytes
|
||||
my $ta2 = ($page*32) >> 8;
|
||||
my $ta1 = ($page*32) & 255;
|
||||
$thread->{'select'}=sprintf("\xA5%c%c",$ta1,$ta2);
|
||||
|
||||
#-- reading 9 + 3 + 40 data bytes (32 byte memory, 4 byte counter + 4 byte zeroes) and 2 CRC bytes = 54 bytes
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 42 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$thread->{response} = $thread->{pt_execute}->PT_RETVAL();
|
||||
|
||||
#-- reset the bus (needed to stop receiving data ?)
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,undef,undef,undef);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
if (my $ret = OWXCOUNT_BinValues($hash,"getpage.".$page.($final ? ".final" : ""),0,$owx_dev,$thread->{'select'},0,$thread->{response})) {
|
||||
die $ret;
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXCOUNT_PT_SetPage - Set one memory page of device async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = "alarm" or "status"
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXCOUNT_PT_SetPage($$$) {
|
||||
|
||||
my ($hash,$page,$data) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
my ($thread) = @_;
|
||||
|
||||
my ($res, $response);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
#=============== wrong page requested ===============================
|
||||
if( ($page<0) || ($page>15) ){
|
||||
PT_EXIT("wrong memory page write attempt");
|
||||
}
|
||||
#=============== midnight value =====================================
|
||||
if( ($page==14) || ($page==15) ){
|
||||
OWCOUNT_ParseMidnight($hash,$data,$page);
|
||||
}
|
||||
#=============== set memory =========================================
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command
|
||||
# \x0F TA1 TA2 followed by the data
|
||||
my $ta2 = ($page*32) >> 8;
|
||||
my $ta1 = ($page*32) & 255;
|
||||
#Log 1, "OWXCOUNT: setting page Nr. $ta2 $ta1 $data";
|
||||
$thread->{'select'}=sprintf("\x0F%c%c",$ta1,$ta2).$data;
|
||||
|
||||
#"setpage.1"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 0 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command
|
||||
# \xAA, receiving 2 address bytes, 1 status byte and scratchpad content
|
||||
$thread->{'select'} = "\xAA";
|
||||
#-- reading 9 + 3 + up to 32 bytes
|
||||
# TODO: sometimes much less than 28
|
||||
#"setpage.2"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 28 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
if( length($res) < 13 ){
|
||||
PT_EXIT("device $owx_dev not accessible in reading scratchpad");
|
||||
}
|
||||
|
||||
#-- issue the match ROM command \x55 and the copy scratchpad command
|
||||
# \x5A followed by 3 byte authentication code obtained in previous read
|
||||
$thread->{'select'}="\x5A".substr($res,0,3);
|
||||
#-- first command, next 2 are address, then data
|
||||
|
||||
#"setpage.3"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev, $thread->{'select'}, 6 );
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
#TODO validate whether testing '0' is appropriate with async interface
|
||||
#-- process results
|
||||
if( $res eq 0 ){
|
||||
PT_EXIT("device $owx_dev error copying scratchpad");
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
sub OWXCOUNT_PT_InitializeDevicePage($$$) {
|
||||
my ($hash,$page,$newdata) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
my ($thread) = @_;
|
||||
|
||||
my $ret;
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
$thread->{task} = OWXCOUNT_PT_GetPage($hash,$page,0);
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
if ($ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
|
||||
$thread->{olddata} = $hash->{owg_str}->[14];
|
||||
|
||||
$thread->{task} = OWXCOUNT_PT_SetPage($hash,$page,$newdata);
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
if ($ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
|
||||
$thread->{task} = OWXCOUNT_PT_GetPage($hash,$page,0);
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
if ($ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
|
||||
$thread->{task} = OWXCOUNT_PT_SetPage($hash,$page,$thread->{olddata});
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
if ($ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
@ -2023,6 +1820,7 @@ sub OWXCOUNT_PT_InitializeDevicePage($$$) {
|
||||
|
||||
<a name="OWCOUNT"></a>
|
||||
<h3>OWCOUNT</h3>
|
||||
<ul>
|
||||
<p>FHEM module to commmunicate with 1-Wire Counter/RAM DS2423 or its emulation DS2423emu <br />
|
||||
<br />This 1-Wire module works with the OWX interface module or with the OWServer interface module
|
||||
(prerequisite: Add this module's name to the list of clients in OWServer).
|
||||
@ -2166,6 +1964,7 @@ sub OWXCOUNT_PT_InitializeDevicePage($$$) {
|
||||
<br />period for rate calculation </li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
@ -5,7 +5,6 @@
|
||||
# FHEM module to commmunicate with general 1-Wire ID-ROMS
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning
|
||||
# Norbert Truchsess
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -35,21 +34,7 @@ use Time::HiRes qw(gettimeofday);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#add FHEM/lib to @INC if it is not already included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
use GPUtils qw(:all);
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
sub Log3($$$);
|
||||
|
||||
my $owx_version="7.01";
|
||||
my $owx_version="7.23";
|
||||
#-- declare variables
|
||||
my %gets = (
|
||||
"present" => ":noArg",
|
||||
@ -184,9 +169,7 @@ sub OWID_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWID: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
}
|
||||
|
||||
$modules{OWID}{defptr}{$id} = $hash;
|
||||
#--
|
||||
@ -326,13 +309,6 @@ sub OWID_Get($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$value = OWX_Verify($master,$name,$hash->{ROM_ID},0);
|
||||
#-- OWX_ASYNC interface
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_RunToCompletion($hash,OWX_ASYNC_PT_Verify($hash));
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
|
||||
#-- Unknown interface
|
||||
} else {
|
||||
return "OWID: Verification not yet implemented for interface $interface";
|
||||
@ -385,18 +361,8 @@ sub OWID_GetValues($) {
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
my $interface = $master->{TYPE};
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$value = OWX_Verify($master,$name,$hash->{ROM_ID},0);
|
||||
|
||||
#-- OWX_ASYNC interface
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_RunToCompletion($hash,OWX_ASYNC_PT_Verify($hash));
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
|
||||
$value = OWX_Verify($master,$name,$hash->{ROM_ID},0);
|
||||
|
||||
#-- process results
|
||||
if( $master->{ASYNCHRONOUS} ){
|
||||
@ -481,6 +447,7 @@ sub OWID_Undef ($) {
|
||||
|
||||
<a name="OWID"></a>
|
||||
<h3>OWID</h3>
|
||||
<ul>
|
||||
<p>FHEM module for 1-Wire devices that know only their unique ROM ID<br />
|
||||
<br />This 1-Wire module works with the OWX interface module or with the OWServer interface module
|
||||
Please define an <a href="#OWX">OWX</a> device or <a href="#OWServer">OWServer</a> device first. <br /></p>
|
||||
@ -536,6 +503,6 @@ sub OWID_Undef ($) {
|
||||
interval in seconds. The default is 300 seconds, a value of 0 disables the automatic update.</li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
=end html
|
||||
=cut
|
||||
|
@ -63,22 +63,8 @@ use Time::HiRes qw(gettimeofday);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
my $owx_version="7.23";
|
||||
|
||||
use GPUtils qw(:all);
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
|
||||
sub Log3($$$);
|
||||
|
||||
my $owx_version="7.01";
|
||||
#-- controller may be HD44780 or KS0073
|
||||
# these values can be changed by attribute for different display
|
||||
# geometries or memory maps
|
||||
@ -193,8 +179,6 @@ sub OWLCD_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWLCD: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWLCD}{defptr}{$id} = $hash;
|
||||
@ -248,17 +232,6 @@ sub OWLCD_Init($) {
|
||||
OWXLCD_SetIcon($hash,0,0);
|
||||
#-- erase alarm state
|
||||
OWXLCD_SetFunction($hash,"gpio",15);
|
||||
} elsif ( $interface eq "OWX_ASYNC" ) {
|
||||
eval {
|
||||
OWXLCD_InitializeDevice($hash);
|
||||
#-- set backlight on
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetFunction($hash,"bklon",0));
|
||||
#-- erase all icons
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetIcon($hash,0,0));
|
||||
#-- erase alarm state
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetFunction($hash,"gpio",15));
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
#-- Unknown interface
|
||||
}else{
|
||||
return "OWLCD: Wrong IODev type $interface";
|
||||
@ -287,7 +260,6 @@ sub OWLCD_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($main::init_done) {
|
||||
return OWLCD_Init($hash);
|
||||
}
|
||||
@ -368,13 +340,6 @@ sub OWLCD_Get($@) {
|
||||
}else{
|
||||
return "$name.gpio => $value";
|
||||
}
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"gpio"));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
return $ret if $ret;
|
||||
return "$name.gpio => ".main::ReadingsVal($hash->{NAME},"gpio","");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
#-- Unknown interface
|
||||
@ -395,13 +360,6 @@ sub OWLCD_Get($@) {
|
||||
}else{
|
||||
return "$name.counter => $value";
|
||||
}
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"counter"));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
return $ret if $ret;
|
||||
return "$name.counter => ".main::ReadingsVal($hash->{NAME},"counter","");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
#-- Unknown interface
|
||||
@ -422,13 +380,6 @@ sub OWLCD_Get($@) {
|
||||
}else{
|
||||
return "$name.version => $owx_version (LCD firmware $value)";
|
||||
}
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"version"));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
return $ret if $ret;
|
||||
return "$name.gpio => ".main::ReadingsVal($hash->{NAME},"version","");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
#-- Unknown interface
|
||||
@ -450,13 +401,6 @@ sub OWLCD_Get($@) {
|
||||
}else{
|
||||
return "$name $reading $page => $value";
|
||||
}
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_GetMemory($hash,$page));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
return $ret if $ret;
|
||||
return "$name $reading $page => ".main::ReadingsVal($hash->{NAME},"memory$page","");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
#-- Unknown interface
|
||||
@ -553,15 +497,8 @@ sub OWLCD_Set($@) {
|
||||
#-- check value and write to device
|
||||
return "OWLCD: Set with wrong target value for gpio port, must be 0 <= gpio <= 7"
|
||||
if( ! ((int($value) >= 0) && (int($value) <= 7)) );
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetFunction($hash, "gpio", int($value));
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", int($value)) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
|
||||
return OWXLCD_SetFunction($hash, "gpio", int($value));
|
||||
}
|
||||
|
||||
#-- set single gpio bit from all off = 1 on = 0
|
||||
@ -593,25 +530,9 @@ sub OWLCD_Set($@) {
|
||||
if($key eq "lcd") {
|
||||
#-- check value and write to device
|
||||
if( uc($value) eq "ON"){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetFunction($hash, "lcdon", 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "lcdon", 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetFunction($hash, "lcdon", 0);
|
||||
}elsif( uc($value) eq "OFF" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetFunction($hash, "lcdoff", 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "lcdoff", 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetFunction($hash, "lcdoff", 0);
|
||||
} else {
|
||||
return "OWLCD: Set with wrong value for lcd, must be on/off"
|
||||
}
|
||||
@ -621,25 +542,9 @@ sub OWLCD_Set($@) {
|
||||
if($key eq "backlight") {
|
||||
#-- check value and write to device
|
||||
if( uc($value) eq "ON"){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetFunction($hash, "bklon", 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "bklon", 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
}elsif( uc($value) eq "OFF" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetFunction($hash, "bkloff", 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "bkloff", 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetFunction($hash, "bklon", 0);
|
||||
}elsif( uc($value) eq "OFF" ){
|
||||
return OWXLCD_SetFunction($hash, "bkloff", 0);
|
||||
} else {
|
||||
return "OWLCD: Set with wrong value for backlight, must be on/off"
|
||||
}
|
||||
@ -647,19 +552,9 @@ sub OWLCD_Set($@) {
|
||||
|
||||
#-- reset
|
||||
if($key eq "reset") {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
OWXLCD_SetFunction($hash,"reset",0);
|
||||
OWXLCD_SetIcon($hash,0,0);
|
||||
OWXLCD_SetFunction($hash,"gpio",15);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "reset", 0) );
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 0, 0) );
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 15) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
OWXLCD_SetFunction($hash,"reset",0);
|
||||
OWXLCD_SetIcon($hash,0,0);
|
||||
OWXLCD_SetFunction($hash,"gpio",15);
|
||||
}
|
||||
|
||||
#-- set icon
|
||||
@ -669,68 +564,26 @@ sub OWLCD_Set($@) {
|
||||
#-- check value and write to device
|
||||
if( $icon == 16 ){
|
||||
if( uc($value) eq "OFF" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, 16, 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, 16, 0);
|
||||
|
||||
}elsif( uc($value) eq "BLINK" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, 16, 6);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, 6) );
|
||||
};
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, 16, 6);
|
||||
|
||||
}elsif( ((int($value) > 0) && (int($value) < 6)) ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, 16, int($value));
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, int($value)) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, 16, int($value));
|
||||
|
||||
} else {
|
||||
return "OWLCD: Set with wrong value for icon #16, must be 0..5/off/blink"
|
||||
}
|
||||
}else{
|
||||
if( uc($value) eq "OFF"){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, $icon, 0);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, $icon, 0) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, $icon, 0);
|
||||
|
||||
}elsif( uc($value) eq "ON" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, $icon, 1);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, $icon, 1) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, $icon, 1);
|
||||
|
||||
}elsif( uc($value) eq "BLINK" ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetIcon($hash, $icon, 2);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, &OWXLCD_PT_SetIcon($hash, $icon, 2) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetIcon($hash, $icon, 2);
|
||||
} else {
|
||||
return "OWLCD: Set with wrong value for icon $icon, must be on/off/blink"
|
||||
}
|
||||
@ -745,15 +598,7 @@ sub OWLCD_Set($@) {
|
||||
return "OWLCD: Wrong line length, must be <= ".$lcdchars
|
||||
if( length($value) > $lcdchars );
|
||||
#-- check value and write to device
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetLine($hash,$line,$value);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash, $line, $value) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetLine($hash,$line,$value);
|
||||
}
|
||||
|
||||
#-- set memory page 0..6
|
||||
@ -763,35 +608,16 @@ sub OWLCD_Set($@) {
|
||||
return "OWLCD: Wrong line length, must be <=16 "
|
||||
if( length($value) > 16 );
|
||||
#-- write to device
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
return OWXLCD_SetMemory($hash,$line,$value);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetMemory($hash, $line, $value) );
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
return OWXLCD_SetMemory($hash,$line,$value);
|
||||
}
|
||||
|
||||
#-- start test
|
||||
if($key eq "test") {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
OWXLCD_SetLine($hash,0,"Hallo Welt");
|
||||
OWXLCD_SetLine($hash,1,"Mary had a big lamb");
|
||||
OWXLCD_SetLine($hash,2,"Solar 4.322 kW ");
|
||||
OWXLCD_SetLine($hash,3,"\x5B\x5C\x5E\x7B\x7C\x7E\xBE");
|
||||
return undef;
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,0,"Hallo Welt"));
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,1,"Mary had a big lamb"));
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,2,"Solar 4.322 kW "));
|
||||
OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,3,"\x5B\x5C\x5E\x7B\x7C\x7E\xBE"));
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
OWXLCD_SetLine($hash,0,"Hallo Welt");
|
||||
OWXLCD_SetLine($hash,1,"Mary had a big lamb");
|
||||
OWXLCD_SetLine($hash,2,"Solar 4.322 kW ");
|
||||
OWXLCD_SetLine($hash,3,"\x5B\x5C\x5E\x7B\x7C\x7E\xBE");
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-- start initialize
|
||||
@ -845,32 +671,22 @@ sub OWXLCD_InitializeDevice($) {
|
||||
#-- Entry Mode Set: cursor auto increment = \x06
|
||||
#OWXLCD_Byte($hash,"register",6);
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
#-- Function Set: 4 bit data size, RE => 1, blink Enable = \x26
|
||||
OWXLCD_Byte($hash,"register",38);
|
||||
|
||||
#-- Ext. Function Set: 4 line mode = \x09
|
||||
OWXLCD_Byte($hash,"register",9);
|
||||
#-- Function Set: 4 bit data size, RE => 1, blink Enable = \x26
|
||||
OWXLCD_Byte($hash,"register",38);
|
||||
|
||||
#-- Ext. Function Set: 4 line mode = \x09
|
||||
OWXLCD_Byte($hash,"register",9);
|
||||
|
||||
#-- Function Set: 4 bit data size, RE => 0 = \x20
|
||||
OWXLCD_Byte($hash,"register",32);
|
||||
#-- Function Set: 4 bit data size, RE => 0 = \x20
|
||||
OWXLCD_Byte($hash,"register",32);
|
||||
|
||||
#-- Display ON/OFF: display on, cursor off, blink off = \x0C
|
||||
OWXLCD_Byte($hash,"register",12);
|
||||
#-- Display ON/OFF: display on, cursor off, blink off = \x0C
|
||||
OWXLCD_Byte($hash,"register",12);
|
||||
|
||||
#-- Clear Display
|
||||
OWXLCD_Byte($hash,"register",1);
|
||||
return undef;
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",38));
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register", 9));
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",32));
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",12));
|
||||
OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register", 1));
|
||||
};
|
||||
return GP_Catch($@) if $@;
|
||||
}
|
||||
#-- Clear Display
|
||||
OWXLCD_Byte($hash,"register",1);
|
||||
return undef;
|
||||
|
||||
#-- or else
|
||||
} else {
|
||||
return "OWXLCD: Wrong LCD controller type";
|
||||
@ -1557,498 +1373,6 @@ sub OWXLCD_SetMemory($$$) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_Byte - write a single byte to the LCD device async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# cmd = register or data
|
||||
# byte = byte
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_Byte($$$) {
|
||||
|
||||
my ($hash,$cmd,$byte) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
my ($thread) = @_;
|
||||
my ($select);
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
my ($i,$j,$k);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#=============== write to LCD register ===============================
|
||||
if ( $cmd eq "register" ) {
|
||||
#-- issue the read LCD register command \x10
|
||||
$select = sprintf("\x10%c",$byte);
|
||||
#=============== write to LCD data ===============================
|
||||
}elsif ( $cmd eq "data" ) {
|
||||
#-- issue the read LCD data command \x12
|
||||
$select = sprintf("\x12%c",$byte);
|
||||
#=============== wrong value requested ===============================
|
||||
} else {
|
||||
die "OWXLCD: Wrong byte write attempt";
|
||||
}
|
||||
|
||||
#"byte"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_Get - get values from the LCD device async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# cmd = command string
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_Get($$) {
|
||||
|
||||
my ($hash,$cmd) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
#=============== fill scratch with gpio ports ===============================
|
||||
if ( $cmd eq "gpio" ) {
|
||||
#-- issue the read GPIO command \x22 (1 byte)
|
||||
$select = "\x22";
|
||||
$thread->{len} = 1;
|
||||
#=============== fill scratch with gpio counters ===============================
|
||||
}elsif ( $cmd eq "counter" ) {
|
||||
#-- issue the read counter command \x23 (8 bytes)
|
||||
$select = "\x23";
|
||||
$thread->{len} = 8;
|
||||
#=============== fill scratch with version ===============================
|
||||
}elsif ( $cmd eq "version" ) {
|
||||
#-- issue the read version command \x41
|
||||
$select = "\x41";
|
||||
$thread->{len} = 16;
|
||||
} else {
|
||||
die("OWXLCD: Wrong get attempt");
|
||||
}
|
||||
#"get.prepare"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the read scratchpad command \xBE
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,"\xBE", $thread->{len});
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
OWXLCD_BinValues($hash, "get.".$cmd, 1, $owx_dev, "\xBE", $thread->{len}, $thread->{pt_execute}->PT_RETVAL());
|
||||
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_GetMemory - get memory page from LCD device async (EXPERIMENTAL)
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = memory page address
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_GetMemory($$) {
|
||||
|
||||
my ($hash,$page) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
#-- issue the match ROM command \x55 and the copy eeprom to scratchpad command \x4E
|
||||
#Log 1," page read is ".$page;
|
||||
$select = sprintf("\4E%c\x10\x37",$page);
|
||||
#"prepare"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- sleeping for some time
|
||||
$thread->{ExecuteTime} = gettimeofday()+0.5;
|
||||
PT_YIELD_UNTIL(gettimeofday() >= $thread->{ExecuteTime});
|
||||
delete $thread->{ExecuteTime};
|
||||
|
||||
#-- issue the match ROM command \x55 and the read scratchpad command \xBE
|
||||
$thread->{'select'} = "\xBE";
|
||||
#"get.memory.$page"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'},16);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
OWXLCD_BinValues($hash, "get.memory.$page", 1, $owx_dev, $thread->{'select'}, 16, $thread->{pt_execute}->PT_RETVAL());
|
||||
#-- process results (10 bytes or more have been sent)
|
||||
#$res2 = substr($res,11,16);
|
||||
#return $res2;
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_SetFunction - write state and values of the LCD device async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# cmd = command string
|
||||
# value = data value
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_SetFunction($$$) {
|
||||
|
||||
my ($hash,$cmd,$value) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#=============== set gpio ports ===============================
|
||||
if ( $cmd eq "gpio" ) {
|
||||
#-- issue the write GPIO command
|
||||
# \x21 followed by the data value (= integer 0 - 7)
|
||||
$select = sprintf("\x21%c",$value);
|
||||
#=============== switch LCD on ===============================
|
||||
}elsif ( $cmd eq "lcdon" ) {
|
||||
#-- issue the lcd on cmd
|
||||
$select = "\x03";
|
||||
#=============== switch LCD off ===============================
|
||||
}elsif ( $cmd eq "lcdoff" ) {
|
||||
#-- issue the lcd off cmd
|
||||
$select = "\x05";
|
||||
#=============== switch LCD backlight on ===============================
|
||||
}elsif ( $cmd eq "bklon" ) {
|
||||
#-- issue the backlight on cmd
|
||||
$select = "\x08";
|
||||
#=============== switch LCD backlight off ===============================
|
||||
}elsif ( $cmd eq "bkloff" ) {
|
||||
#-- issue the backlight off cmd
|
||||
$select = "\x07";
|
||||
#=============== switch LCD backlight off ===============================
|
||||
}elsif ( $cmd eq "reset" ) {
|
||||
#-- issue the clear LCD command
|
||||
$select = "\x49";
|
||||
#=============== wrong write attempt ===============================
|
||||
} else {
|
||||
die "OWXLCD: Wrong function selected '$cmd'";
|
||||
}
|
||||
#"set.function"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_SetIcon - set one of the icons async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# icon = address of the icon used = 0,1 .. 16 (0 = all off)
|
||||
# value = data value: 0 = off, 1 = on, 2 = blink
|
||||
# for battery icon 16: 0 = off, 1 = empty ... 5 = full, 6 = empty blink
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_SetIcon($$$) {
|
||||
my ($hash,$icon,$value) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($i,$data,$select, $res);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#-- only for KS0073
|
||||
if ( $lcdcontroller eq "KS0073"){
|
||||
|
||||
#-- write 16 zeros to erase all icons
|
||||
if( $icon == 0){
|
||||
#-- 4 bit data size, RE => 1, blink Enable = \x26
|
||||
$select = "\x10\x26";
|
||||
#"set.icon.1"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- SEGRAM addres to 0 = \x40,
|
||||
$select = "\x10\x40";
|
||||
#-- write 16 zeros to scratchpad
|
||||
$select .= "\x4E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
#"set.icon.2"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the copy scratchpad to LCD command \x48
|
||||
$select="\x48";
|
||||
#"set.icon.3"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
} else {
|
||||
#-- determine data value
|
||||
if( int($icon) != 16 ){
|
||||
if( $value == 0 ){
|
||||
$data = 0;
|
||||
} elsif ( $value == 1) {
|
||||
$data = 16;
|
||||
} elsif ( $value == 2) {
|
||||
$data = 80;
|
||||
} else {
|
||||
die("OWXLCD: Wrong data value $value for icon $icon");
|
||||
}
|
||||
} else {
|
||||
if( $value == 0 ){
|
||||
$data = 0;
|
||||
} elsif ( $value == 1) {
|
||||
$data = 16;
|
||||
} elsif ( $value == 2) {
|
||||
$data = 24;
|
||||
} elsif ( $value == 3) {
|
||||
$data = 28;
|
||||
} elsif ( $value == 4) {
|
||||
$data = 30;
|
||||
} elsif ( $value == 5) {
|
||||
$data = 31;
|
||||
} elsif ( $value == 6) {
|
||||
$data = 80;
|
||||
} else {
|
||||
die("OWXLCD: Wrong data value $value for icon $icon");
|
||||
}
|
||||
}
|
||||
#-- 4 bit data size, RE => 1, blink Enable = \x26
|
||||
$select = "\x10\x26";
|
||||
#"set.icon.4"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- SEGRAM addres to 0 = \x40 + icon address
|
||||
$select = sprintf("\x10%c",63+$icon);
|
||||
#"set.icon.5"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- data
|
||||
$select = sprintf("\x12%c",$data);
|
||||
#"set.icon.6"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
}
|
||||
|
||||
#-- return to normal state
|
||||
$select = "\x10\x20";
|
||||
#"set.icon.7"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
#-- or else
|
||||
} else {
|
||||
die("OWXLCD: Wrong LCD controller type");
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_SetLine - set one of the display lines async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# line = line number (0..3)
|
||||
# msg = data string to be written
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_SetLine($$$) {
|
||||
|
||||
my ($hash,$line,$msg) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select, $i, $msgA, $msgB);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
$line = int($line);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
$msg = defined($msg) ? $msg : "";
|
||||
$msg = OWXLCD_Trans($msg);
|
||||
|
||||
#-- split if longer than 16 bytes, fill each with blanks
|
||||
# has already been checked to be <= $lcdchars
|
||||
if( $lcdchars > 16 ){
|
||||
if( length($msg) > 16 ) {
|
||||
$msgA = substr($msg,0,16);
|
||||
$msgB = substr($msg,16,length($msg)-16);
|
||||
for($i = 0;$i<$lcdchars-length($msg);$i++){
|
||||
$msgB .= "\x20";
|
||||
}
|
||||
} else {
|
||||
$msgA = $msg;
|
||||
for($i = 0;$i<16-length($msg);$i++){
|
||||
$msgA .= "\x20";
|
||||
}
|
||||
for($i = 0;$i<$lcdchars-16;$i++){
|
||||
$msgB .= "\x20";
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$msgA = $msg;
|
||||
for($i = 0;$i<$lcdchars-length($msg);$i++){
|
||||
$msgA .= "\x20";
|
||||
}
|
||||
$msgB = undef;
|
||||
}
|
||||
$thread->{msgB} = $msgB;
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E
|
||||
# followed by LCD page address and the text
|
||||
$select=sprintf("\x4E%c",$lcdpage[$line]).$msgA;
|
||||
#"set.line.1"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the copy scratchpad to LCD command \x48
|
||||
$select="\x48";
|
||||
#"set.line.2"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- if second string available:
|
||||
if( defined($thread->{msgB}) ) {
|
||||
#select(undef,undef,undef,0.005);
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E
|
||||
# followed by LCD page address and the text
|
||||
$select=sprintf("\x4E%c",$lcdpage[$line]+16).$thread->{msgB};
|
||||
#"set.line.3"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the copy scratchpad to LCD command \x48
|
||||
$select="\x48";
|
||||
#"set.line.4"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXLCD_PT_SetMemory - set internal nonvolatile memory async
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# page = page number (0..14)
|
||||
# msg = data string to be written
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXLCD_PT_SetMemory($$$) {
|
||||
|
||||
my ($hash,$page,$msg) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread,$hash,$page,$msg) = @_;
|
||||
my ($select, $i, $msgA);
|
||||
|
||||
#-- ID of the device, hash of the busmaster
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
$page = int($page);
|
||||
$msg = defined($msg) ? $msg : "";
|
||||
|
||||
#-- fillup with blanks
|
||||
$msgA = $msg;
|
||||
for($i = 0;$i<16-length($msg);$i++){
|
||||
$msgA .= "\x20";
|
||||
}
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E
|
||||
# followed by LCD page address and the text
|
||||
#Log 1," page written is ".$page;
|
||||
$select=sprintf("\x4E\%c",$page).$msgA;
|
||||
#"set.memory.page"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
|
||||
#-- issue the copy scratchpad to EEPROM command \x39
|
||||
$select = "\x39";
|
||||
#"set.memory.copy"
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
@ -2058,6 +1382,7 @@ sub OWXLCD_PT_SetMemory($$$) {
|
||||
|
||||
<a name="OWLCD"></a>
|
||||
<h3>OWLCD</h3>
|
||||
<ul>
|
||||
<p>FHEM module to commmunicate with the <a
|
||||
href="http://www.louisswart.co.za/1-Wire_Overview.html">1-Wire LCD controller</a>
|
||||
from Louis Swart (1-Wire family id FF). See also the corresponding <a
|
||||
@ -2148,6 +1473,6 @@ sub OWXLCD_PT_SetMemory($$$) {
|
||||
LCD geometry, values are KS0073 (default) HD44780</li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
=end html
|
||||
=cut
|
@ -5,7 +5,6 @@
|
||||
# FHEM module to commmunicate with 1-Wire chip DS2438Z - Smart Battery Monitor
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning
|
||||
# Norbert Truchsess
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -32,18 +31,9 @@ package main;
|
||||
use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||
use strict;
|
||||
use warnings;
|
||||
#add FHEM/lib to @INC if it's not already included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub Log($$);
|
||||
my $owx_version="7.23";
|
||||
|
||||
my $owx_version="7.21";
|
||||
#-- flexible channel name
|
||||
my ($owg_channel,$owg_schannel,$owg_sichannel);
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
# FHEM module to commmunicate with 1-Wire adressable switches DS2413, DS206, DS2408
|
||||
#
|
||||
# Prof. Dr. Peter A. Henning
|
||||
# Norbert Truchsess
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
@ -33,21 +32,8 @@ use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
my $owx_version="7.23";
|
||||
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
|
||||
sub Log($$);
|
||||
|
||||
my $owx_version="7.01";
|
||||
#-- fixed raw channel name, flexible channel name
|
||||
my @owg_fixed = ("A","B","C","D","E","F","G","H");
|
||||
my @owg_channel = ("A","B","C","D","E","F","G","H");
|
||||
@ -216,9 +202,7 @@ sub OWSWITCH_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWSWITCH: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
}
|
||||
|
||||
$main::modules{OWSWITCH}{defptr}{$id} = $hash;
|
||||
#--
|
||||
@ -297,7 +281,6 @@ sub OWSWITCH_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($init_done) {
|
||||
OWSWITCH_Init($hash);
|
||||
}
|
||||
@ -487,11 +470,6 @@ sub OWSWITCH_Get($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
OWXSWITCH_GetModState($hash,"final",undef);
|
||||
}elsif( $interface eq "OWX_ASYNC") {
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXSWITCH_PT_GetState($hash));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSSWITCH_GetState($hash);
|
||||
@ -514,11 +492,6 @@ sub OWSWITCH_Get($@) {
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetModState($hash,undef,undef);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
$ret = OWX_ASYNC_RunToCompletion($hash,OWXSWITCH_PT_GetState($hash));
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSSWITCH_GetState($hash);
|
||||
}else{
|
||||
@ -569,12 +542,6 @@ sub OWSWITCH_GetValues($) {
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_GetModState($hash,"final",undef);
|
||||
return if( !defined($ret) );
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXSWITCH_PT_GetState($hash) );
|
||||
};
|
||||
return unless $@;
|
||||
$ret = GP_Catch($@);
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSSWITCH_GetState($hash);
|
||||
}else{
|
||||
@ -733,11 +700,6 @@ sub OWSWITCH_Set($@) {
|
||||
if( $interface eq "OWX" ){
|
||||
#-- all-in one needed, because return not sure
|
||||
$ret1 = OWXSWITCH_GetModState($hash,$outfnd,$outval);
|
||||
}elsif( $interface eq "OWX_ASYNC"){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXSWITCH_PT_SetOutput($hash,$outfnd,$outval) );
|
||||
};
|
||||
$ret2 = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret1 = OWFSSWITCH_GetState($hash);
|
||||
@ -773,11 +735,6 @@ sub OWSWITCH_Set($@) {
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXSWITCH_SetState($hash,int($value));
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
eval {
|
||||
OWX_ASYNC_Schedule( $hash, OWXSWITCH_PT_SetState($hash,int($value)) );
|
||||
};
|
||||
$ret = GP_Catch($@) if $@;
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret2 = OWFSSWITCH_SetState($hash,int($value));
|
||||
$ret3 = OWFSSWITCH_GetState($hash);
|
||||
@ -1400,244 +1357,6 @@ sub OWXSWITCH_SetState($$) {
|
||||
}
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXSWITCH_PT_GetState - Get gpio ports from device asynchronous
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXSWITCH_PT_GetState($) {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
return PT_THREAD( sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select, $ret, @data, $response);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
my ($i,$j,$k);
|
||||
|
||||
#-- family = 12 => DS2406
|
||||
if( $hash->{OW_FAMILY} eq "12" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the access channel command
|
||||
# \xF5 plus the two byte channel control and the value
|
||||
#-- reading 9 + 3 + 2 data bytes + 2 CRC bytes = 16 bytes
|
||||
$thread->{'select'}=sprintf("\xF5\xDD\xFF");
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'},4);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$response = $thread->{pt_execute}->PT_RETVAL();
|
||||
unless (length($response) == 4) {
|
||||
PT_EXIT("$owx_dev has returned invalid data");
|
||||
}
|
||||
$ret = OWXSWITCH_BinValues($hash,"ds2406.getstate",1,$owx_dev,$thread->{'select'},4,$response);
|
||||
if (defined $ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
#-- family = 29 => DS2408
|
||||
}elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the read PIO rtegisters command
|
||||
# \xF5 plus the two byte channel target address
|
||||
#-- reading 9 + 3 + 8 data bytes + 2 CRC bytes = 22 bytes
|
||||
$thread->{'select'}=sprintf("\xF0\x88\x00");
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'},10);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$response = $thread->{pt_execute}->PT_RETVAL();
|
||||
unless (length($response) == 10) {
|
||||
PT_EXIT("$owx_dev has returned invalid data")
|
||||
};
|
||||
$ret = OWXSWITCH_BinValues($hash,"ds2408.getstate",1,$owx_dev,$thread->{'select'},10,$response);
|
||||
if (defined $ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
#-- family = 3A => DS2413
|
||||
}elsif( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
#=============== get gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the read gpio command
|
||||
# \xF5 plus 2 empty bytes
|
||||
#-- reading 9 + 1 + 2 data bytes = 12 bytes
|
||||
$thread->{'select'}="\xF5";
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'},2);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$response = $thread->{pt_execute}->PT_RETVAL();
|
||||
unless (length($response) == 2) {
|
||||
PT_EXIT("$owx_dev has returned invalid data");
|
||||
}
|
||||
$ret = OWXSWITCH_BinValues($hash,"ds2413.getstate",1,$owx_dev,$thread->{'select'},2,$response);
|
||||
if (defined $ret) {
|
||||
PT_EXIT($ret);
|
||||
}
|
||||
} else {
|
||||
PT_EXIT("unknown device family $hash->{OW_FAMILY}\n");
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# OWXSWITCH_PT_SetState - Set gpio ports of device asynchronous
|
||||
#
|
||||
# Parameter hash = hash of device addressed
|
||||
# value = integer value for device outputs
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXSWITCH_PT_SetState($$) {
|
||||
|
||||
my ($hash,$value) = @_;
|
||||
|
||||
return PT_THREAD( sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($select,$res,@data);
|
||||
|
||||
#-- ID of the device
|
||||
my $owx_dev = $hash->{ROM_ID};
|
||||
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
#-- family = 12 => DS2406
|
||||
if( $hash->{OW_FAMILY} eq "12" ) {
|
||||
#=============== set gpio values ===============================
|
||||
# Writing the output state via the access channel command does
|
||||
# not work contrary to documentation. Using the write status command
|
||||
#-- issue the match ROM command \x55 and the read status command
|
||||
# \xAA at address TA1 = \x07 TA2 = \x00
|
||||
#-- reading 9 + 3 + 1 data bytes + 2 CRC bytes = 15 bytes
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,"\xAA\x07\x00", 3);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
|
||||
#-- first step
|
||||
my $stat = ord(substr($res,0,1));
|
||||
my $statneu = ( $stat & 159 ) | (($value<<5) & 96) ;
|
||||
#-- call the second step
|
||||
#-- issue the match ROM command \x55 and the write status command
|
||||
# \x55 at address TA1 = \x07 TA2 = \x00
|
||||
#-- reading 9 + 4 + 2 data bytes = 15 bytes
|
||||
$thread->{'select'}=sprintf("\x55\x07\x00%c",$statneu);
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'}, 2);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
|
||||
my $command = $thread->{'select'};
|
||||
|
||||
#-- second step from above
|
||||
@data=split(//,$res);
|
||||
if( int(@data) != 2){
|
||||
PT_EXIT("state could not be set for device $owx_dev");
|
||||
}
|
||||
if (OWX_CRC16($command,$data[0],$data[1]) == 0) {
|
||||
PT_EXIT("invalid CRC");
|
||||
}
|
||||
|
||||
#-- put into local buffer
|
||||
$hash->{owg_val}->[0] = $value % 2;
|
||||
$hash->{owg_vax}->[0] = $value % 2;
|
||||
$hash->{owg_val}->[1] = int($value / 2);
|
||||
$hash->{owg_vax}->[1] = int($value / 2);
|
||||
|
||||
#-- family = 29 => DS2408
|
||||
} elsif( $hash->{OW_FAMILY} eq "29" ) {
|
||||
#=============== set gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the write gpio command
|
||||
# \x5A plus the value byte and its complement
|
||||
$select=sprintf("\x5A%c%c",$value,255-$value);
|
||||
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select, 1);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
|
||||
@data=split(//,$res);
|
||||
if (@data != 1) {
|
||||
PT_EXIT("invalid data length, ".int(@data)." instead of 1 bytes");
|
||||
}
|
||||
if( $data[0] ne "\xAA") {
|
||||
PT_EXIT("state could not be set for device $owx_dev");
|
||||
}
|
||||
|
||||
#-- family = 3A => DS2413
|
||||
} elsif( $hash->{OW_FAMILY} eq "3A" ) {
|
||||
#=============== set gpio values ===============================
|
||||
#-- issue the match ROM command \x55 and the write gpio command
|
||||
# \x5A plus the value byte and its complement
|
||||
$select=sprintf("\x5A%c%c",252+$value,3-$value);
|
||||
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select, 1);
|
||||
PT_WAIT_THREAD($thread->{pt_execute});
|
||||
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
|
||||
$res = $thread->{pt_execute}->PT_RETVAL();
|
||||
|
||||
@data=split(//,$res);
|
||||
if (@data != 1) {
|
||||
PT_EXIT("invalid data length, ".int(@data)." instead of 1 bytes");
|
||||
}
|
||||
if( $data[0] ne "\xAA") {
|
||||
PT_EXIT("state could not be set for device $owx_dev");
|
||||
}
|
||||
} else {
|
||||
PT_EXIT("unknown device family $hash->{OW_FAMILY}\n");
|
||||
}
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
sub OWXSWITCH_PT_SetOutput($$$) {
|
||||
|
||||
my ($hash,$fnd,$nval) = @_;
|
||||
|
||||
return PT_THREAD(sub {
|
||||
|
||||
my ($thread) = @_;
|
||||
my ($ret,$value);
|
||||
|
||||
PT_BEGIN($thread);
|
||||
|
||||
$thread->{task} = OWXSWITCH_PT_GetState($hash);
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
die $thread->{task}->PT_CAUSE() if ($thread->{task}->PT_STATE() == PT_ERROR);
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
die $ret if $ret;
|
||||
$value = 0;
|
||||
#-- vax or val ?
|
||||
for (my $i=0;$i<$cnumber{$attr{$hash->{NAME}}{"model"}};$i++){
|
||||
$value += ($hash->{owg_vax}->[$i]<<$i)
|
||||
if( $i != $fnd );
|
||||
$value += ($nval<<$i)
|
||||
if( $i == $fnd );
|
||||
}
|
||||
$thread->{value} = $value;
|
||||
$thread->{task} = OWXSWITCH_PT_SetState($hash,$thread->{value});
|
||||
PT_WAIT_THREAD($thread->{task});
|
||||
die $thread->{task}->PT_CAUSE() if ($thread->{task}->PT_STATE() == PT_ERROR);
|
||||
$ret = $thread->{task}->PT_RETVAL();
|
||||
die $ret if $ret;
|
||||
PT_END;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
@ -1647,6 +1366,7 @@ sub OWXSWITCH_PT_SetOutput($$$) {
|
||||
|
||||
<a name="OWSWITCH"></a>
|
||||
<h3>OWSWITCH</h3>
|
||||
<ul>
|
||||
<p>FHEM module to commmunicate with 1-Wire Programmable Switches <br />
|
||||
<br />This 1-Wire module works with the OWX interface module or with the OWServer interface module
|
||||
(prerequisite: Add this module's name to the list of clients in OWServer).
|
||||
@ -1740,6 +1460,6 @@ sub OWXSWITCH_PT_SetOutput($$$) {
|
||||
<br />display for on | off condition </li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
=end html
|
||||
=cut
|
||||
|
@ -33,20 +33,7 @@ use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw( gettimeofday );
|
||||
|
||||
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
no warnings 'deprecated';
|
||||
sub Log3($$$);
|
||||
sub AttrVal($$$);
|
||||
|
||||
my $owx_version="7.2";
|
||||
my $owx_version="7.23";
|
||||
|
||||
my %gets = (
|
||||
"id" => ":noArg",
|
||||
@ -204,7 +191,6 @@ sub OWTHERM_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWTHERM: Warning, no 1-Wire I/O device found for $name.";
|
||||
#-- if coupled, test if ASYNC or not
|
||||
}
|
||||
|
||||
$modules{OWTHERM}{defptr}{$id} = $hash;
|
||||
@ -300,7 +286,6 @@ sub OWTHERM_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($init_done) {
|
||||
OWTHERM_Init($hash);
|
||||
}
|
||||
|
@ -33,21 +33,7 @@ use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw( gettimeofday );
|
||||
|
||||
#add FHEM/lib to @INC if it's not allready included. Should rather be in fhem.pl than here though...
|
||||
BEGIN {
|
||||
if (!grep(/FHEM\/lib$/,@INC)) {
|
||||
foreach my $inc (grep(/FHEM$/,@INC)) {
|
||||
push @INC,$inc."/lib";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
use ProtoThreads;
|
||||
no warnings 'deprecated';
|
||||
sub Log3($$$);
|
||||
sub AttrVal($$$);
|
||||
|
||||
my $owx_version="7.0";
|
||||
my $owx_version="7.23";
|
||||
my $owg_channel = "";
|
||||
|
||||
my %gets = (
|
||||
@ -169,8 +155,6 @@ sub OWVAR_Define ($$) {
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWVAR: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWVAR}{defptr}{$id} = $hash;
|
||||
@ -241,7 +225,6 @@ sub OWVAR_Attr(@) {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
if ($init_done) {
|
||||
OWVAR_Init($hash);
|
||||
}
|
||||
@ -390,12 +373,6 @@ sub OWVAR_Get($@) {
|
||||
if( $interface eq "OWX" ){
|
||||
#-- not different from getting all values ..
|
||||
$ret = OWXVAR_GetValues($hash);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
Log3 $name,1,"OWVAR: Get ASYNC interface not implemented";
|
||||
#eval {
|
||||
# $ret = OWX_ASYNC_RunToCompletion($hash,OWXVAR_PT_GetValues($hash));
|
||||
#};
|
||||
#$ret = GP_Catch($@) if $@;
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSVAR_GetValues($hash);
|
||||
@ -449,8 +426,6 @@ sub OWVAR_GetValues($@) {
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXVAR_GetValues($hash);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
Log3 $name, 1,"OWVAR: Get ASYNC interface not implemented";
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSVAR_GetValues($hash);
|
||||
}else{
|
||||
@ -543,8 +518,6 @@ sub OWVAR_Set($@) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
$ret = OWXVAR_SetValues($hash,$key,$value);
|
||||
}elsif( $interface eq "OWX_ASYNC" ){
|
||||
Log3 $name, 1,"OWVAR: Set ASYNC interface not implemented";
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSVAR_SetValues($hash,$key,$value);
|
||||
@ -868,8 +841,6 @@ sub OWXVAR_SetValues($$$) {
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
@ -879,6 +850,7 @@ sub OWXVAR_SetValues($$$) {
|
||||
|
||||
<a name="OWVAR"></a>
|
||||
<h3>OWVAR</h3>
|
||||
<ul>
|
||||
<p>FHEM module to commmunicate with 1-Wire bus digital potentiometer devices of type DS2890<br />
|
||||
<br />This 1-Wire module works with the OWX interface module, but not yet with the OWServer interface module.
|
||||
|
||||
@ -944,6 +916,6 @@ sub OWXVAR_SetValues($$$) {
|
||||
</li>
|
||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
=end html
|
||||
=cut
|
||||
|
Loading…
Reference in New Issue
Block a user