2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-25 03:39:21 +00:00

00_OWX.pm: Bugfix globale Variablen

21_OWMULTI.pm: Neue Version, angepasst für die Funktionen des Batterie-Monitoring
21_OWTHERM.pm: Neue Version
36_Shelly.pm: Bugfix

git-svn-id: https://svn.fhem.de/fhem/trunk@20282 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
phenning 2019-09-30 17:21:29 +00:00
parent b351fbd75a
commit 36b7898726
4 changed files with 564 additions and 515 deletions

View File

@ -53,7 +53,7 @@ sub Log3($$$);
use vars qw{%owg_family %gets %sets $owx_version $owx_debug}; use vars qw{%owg_family %gets %sets $owx_version $owx_debug};
# 1-Wire devices # 1-Wire devices
# http://owfs.sourceforge.net/family.html # http://owfs.sourceforge.net/family.html
%owg_family = ( my %owg_family = (
"01" => ["DS2401/DS2411/DS1990A","OWID DS2401"], "01" => ["DS2401/DS2411/DS1990A","OWID DS2401"],
"05" => ["DS2405","OWID DS2405"], "05" => ["DS2405","OWID DS2405"],
"09" => ["DS2502","OWID DS2502"], "09" => ["DS2502","OWID DS2502"],
@ -79,7 +79,7 @@ use vars qw{%owg_family %gets %sets $owx_version $owx_debug};
); );
#-- These we may get on request #-- These we may get on request
%gets = ( my %gets = (
"alarms" => "A", "alarms" => "A",
"devices" => "D", "devices" => "D",
"version" => "V", "version" => "V",
@ -88,7 +88,7 @@ use vars qw{%owg_family %gets %sets $owx_version $owx_debug};
#-- These occur in a pulldown menu as settable values for the bus master #-- These occur in a pulldown menu as settable values for the bus master
# (expert mode: all, standard mode: only reopen) # (expert mode: all, standard mode: only reopen)
%sets = ( my %sets = (
"close" => "c", "close" => "c",
"open" => "O", "open" => "O",
"reopen" => "R", "reopen" => "R",
@ -99,7 +99,7 @@ use vars qw{%owg_family %gets %sets $owx_version $owx_debug};
); );
#-- some globals needed for the 1-Wire module #-- some globals needed for the 1-Wire module
$owx_version="7.11"; $owx_version="7.21";
#-- debugging now verbosity, this is just for backward compatibility #-- debugging now verbosity, this is just for backward compatibility
$owx_debug=0; $owx_debug=0;
@ -191,7 +191,7 @@ sub OWX_Define ($$) {
$hwdevice = OWX_I2C->new($hash); $hwdevice = OWX_I2C->new($hash);
#-- check if we have a COC/CUNO interface attached #-- check if we have a COC/CUNO interface attached
}elsif( $defs{$dev} && $defs{$dev}->{VERSION} && $defs{$dev}->{VERSION} =~ m/CSM|CUNO|MapleCUN...(4|5|6|7|C|D|E|F)/ ){ }elsif( $defs{$dev} && $defs{$dev}->{VERSION} && $defs{$dev}->{VERSION} =~ m/CSM|CUNO|CUBE|MapleCUN...(4|5|6|7|C|D|E|F)/ ){
require "$attr{global}{modpath}/FHEM/11_OWX_CCC.pm"; require "$attr{global}{modpath}/FHEM/11_OWX_CCC.pm";
$hwdevice = OWX_CCC->new($hash); $hwdevice = OWX_CCC->new($hash);
@ -1542,7 +1542,7 @@ sub OWX_PrQueue($){
if ( defined($slave->{NEXTSEND})){ if ( defined($slave->{NEXTSEND})){
if( $now < $slave->{NEXTSEND} ){ if( $now < $slave->{NEXTSEND} ){
#-- reschedule, if necessary #-- reschedule, if necessary
if( ($qlen==1) || (($qlen > 1) && ($queue->[1]{$hash} eq $slave)) ){ if( ($qlen==1) || (($qlen > 1) && $queue->[1]{$hash} && ($queue->[1]{$hash} eq $slave)) ){
#Log 1, "OWX_PrQueue: device ".$slave->{NAME}." mindelay not over, rescheduling." #Log 1, "OWX_PrQueue: device ".$slave->{NAME}." mindelay not over, rescheduling."
InternalTimer($now+$shortDelay, "OWX_PrQueue", "queue:$name", 0); InternalTimer($now+$shortDelay, "OWX_PrQueue", "queue:$name", 0);
return; return;
@ -1733,7 +1733,7 @@ sub OWX_WDBGL($$$$) {
<a name="OWX"></a> <a name="OWX"></a>
<h3>OWX</h3> <h3>OWX</h3>
<ul> <ul>
<a href="http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire">Deutsche Dokumentation im Wiki</a> vorhanden, die englische Version gibt es hier: <a href="/fhem/docs/commandref.html#OWX">OWX</a> <a href="http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire">Deutsche Dokumentation im Wiki</a> vorhanden, die englische Version gibt es hier: <a href="commandref.html#OWX">OWX</a>
</ul> </ul>
=end html_DE =end html_DE
=cut =cut

File diff suppressed because it is too large Load Diff

View File

@ -42,12 +42,11 @@ BEGIN {
}; };
}; };
use ProtoThreads;
no warnings 'deprecated'; no warnings 'deprecated';
sub Log3($$$); sub Log3($$$);
sub AttrVal($$$); sub AttrVal($$$);
my $owx_version="7.01"; my $owx_version="7.2";
my %gets = ( my %gets = (
"id" => ":noArg", "id" => ":noArg",
@ -206,8 +205,6 @@ sub OWTHERM_Define ($$) {
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){ if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
return "OWTHERM: Warning, no 1-Wire I/O device found for $name."; return "OWTHERM: Warning, no 1-Wire I/O device found for $name.";
#-- if coupled, test if ASYNC or not #-- if coupled, test if ASYNC or not
} else {
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
} }
$modules{OWTHERM}{defptr}{$id} = $hash; $modules{OWTHERM}{defptr}{$id} = $hash;
@ -446,13 +443,6 @@ sub OWTHERM_Get($@) {
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXTHERM_GetValues($hash); $ret = OWXTHERM_GetValues($hash);
#-- OWX_ASYNC interface
}elsif( $interface eq "OWX_ASYNC" ){
eval {
$ret = OWX_ASYNC_RunToCompletion($hash,OWXTHERM_PT_GetValues($hash));
};
$ret = GP_Catch($@) if $@;
#-- OWFS interface #-- OWFS interface
}elsif( $interface eq "OWServer" ){ }elsif( $interface eq "OWServer" ){
$ret = OWFSTHERM_GetValues($hash); $ret = OWFSTHERM_GetValues($hash);
@ -513,16 +503,10 @@ sub OWTHERM_GetValues($@) {
#-- Get values according to interface type #-- Get values according to interface type
my $interface= $hash->{IODev}->{TYPE}; my $interface= $hash->{IODev}->{TYPE};
#-- OWX interface
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXTHERM_GetValues($hash); $ret = OWXTHERM_GetValues($hash);
}elsif( $interface eq "OWX_ASYNC" ){ #-- OWFS interface
#-- skip, if the conversion is driven by master
unless ( defined($attr{$name}{tempConv}) && ( $attr{$name}{tempConv} eq "onkick") ){
eval {
OWX_ASYNC_Schedule( $hash, OWXTHERM_PT_GetValues($hash) );
};
$ret = GP_Catch($@) if $@;
}
}elsif( $interface eq "OWServer" ){ }elsif( $interface eq "OWServer" ){
$ret = OWFSTHERM_GetValues($hash); $ret = OWFSTHERM_GetValues($hash);
}else{ }else{
@ -616,11 +600,6 @@ sub OWTHERM_InitializeDevice($) {
#-- OWX interface #-- OWX interface
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXTHERM_SetValues($hash,$args); $ret = OWXTHERM_SetValues($hash,$args);
}elsif( $interface eq "OWX_ASYNC" ){
eval {
$ret = OWX_ASYNC_RunToCompletion($hash,OWXTHERM_PT_SetValues($hash,$args));
};
$ret = GP_Catch($@) if $@;
#-- OWFS interface #-- OWFS interface
}elsif( $interface eq "OWServer" ){ }elsif( $interface eq "OWServer" ){
$ret = OWFSTHERM_SetValues($hash,$args); $ret = OWFSTHERM_SetValues($hash,$args);
@ -712,12 +691,6 @@ sub OWTHERM_Set($@) {
#-- OWX interface #-- OWX interface
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXTHERM_SetValues($hash,$args); $ret = OWXTHERM_SetValues($hash,$args);
}elsif( $interface eq "OWX_ASYNC" ){
$args->{format} = 1;
eval {
OWX_ASYNC_Schedule( $hash, OWXTHERM_PT_SetValues($hash,$args) );
};
$ret = GP_Catch($@) if $@;
#-- OWFS interface #-- OWFS interface
}elsif( $interface eq "OWServer" ){ }elsif( $interface eq "OWServer" ){
$ret = OWFSTHERM_SetValues($hash,$args); $ret = OWFSTHERM_SetValues($hash,$args);
@ -1002,14 +975,14 @@ sub OWXTHERM_GetValues($) {
#-- issue the match ROM command \x55 and the start conversion command \x44 #-- issue the match ROM command \x55 and the start conversion command \x44
#-- conversion needs some 950 ms - but we may also do it in shorter time ! #-- conversion needs some 950 ms - but we may also do it in shorter time !
if( $con==1 ){ if( $con==1 ){
#-- OLD OWX interface #-- synchronous OWX interface
if( !$master->{ASYNCHRONOUS} ){ if( !$master->{ASYNCHRONOUS} ){
OWX_Reset($master); OWX_Reset($master);
if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){ if( OWX_Complex($master,$owx_dev,"\x44",0) eq 0 ){
return "OWTHERM: $name not accessible"; return "OWTHERM: $name not accessible";
} }
select(undef,undef,undef,$convtimes{AttrVal($name,"resolution",12)}*0.001); select(undef,undef,undef,$convtimes{AttrVal($name,"resolution",12)}*0.001);
#-- NEW OWX interface #-- asynchronous OWX interface
}else{ }else{
#### master slave context proc owx_dev data crcpart numread startread callback delay #### master slave context proc owx_dev data crcpart numread startread callback delay
OWX_Qomplex($master, $hash, "convert", 5, $owx_dev, "\x44", 0, 1, undef, undef, $convtimes{AttrVal($name,"resolution",12)}*0.001 ); OWX_Qomplex($master, $hash, "convert", 5, $owx_dev, "\x44", 0, 1, undef, undef, $convtimes{AttrVal($name,"resolution",12)}*0.001 );
@ -1019,7 +992,7 @@ sub OWXTHERM_GetValues($) {
#-- NOW ask the specific device #-- NOW ask the specific device
#-- issue the match ROM command \x55 and the read scratchpad command \xBE #-- issue the match ROM command \x55 and the read scratchpad command \xBE
#-- reading 9 + 1 + 8 data bytes and 1 CRC byte = 19 bytes #-- reading 9 + 1 + 8 data bytes and 1 CRC byte = 19 bytes
#-- OLD OWX interface #-- synchronous OWX interface
if( !$master->{ASYNCHRONOUS} ){ if( !$master->{ASYNCHRONOUS} ){
OWX_Reset($master); OWX_Reset($master);
my $res=OWX_Complex($master,$owx_dev,"\xBE",9); my $res=OWX_Complex($master,$owx_dev,"\xBE",9);
@ -1029,7 +1002,7 @@ sub OWXTHERM_GetValues($) {
if( length($res)!=19); if( length($res)!=19);
return OWXTHERM_BinValues($hash,"getsp",$owx_dev,undef,undef,9,substr($res,10,9)); return OWXTHERM_BinValues($hash,"getsp",$owx_dev,undef,undef,9,substr($res,10,9));
#-- NEW OWX interface #-- asynchronous OWX interface
}else{ }else{
#### master slave context proc owx_dev data crcpart numread startread callback delay #### master slave context proc owx_dev data crcpart numread startread callback delay
OWX_Qomplex($master, $hash, "readsp", 1, $owx_dev, "\xBE", 0, 19, 0, \&OWXTHERM_BinValues, undef); OWX_Qomplex($master, $hash, "readsp", 1, $owx_dev, "\xBE", 0, 19, 0, \&OWXTHERM_BinValues, undef);
@ -1096,127 +1069,6 @@ sub OWXTHERM_SetValues($$) {
return undef; return undef;
} }
########################################################################################
#
# OWXTHERM_GetValues - Trigger reading from one device
#
# Parameter hash = hash of device addressed
#
########################################################################################
sub OWXTHERM_PT_GetValues($) {
my ($hash) = @_;
return PT_THREAD(sub {
my ($thread) = @_;
#-- For default, perform the conversion now
my $con=1;
#-- ID of the device
my $owx_dev = $hash->{ROM_ID};
#-- hash of the busmaster
my $master = $hash->{IODev};
my $name = $hash->{NAME};
PT_BEGIN($thread);
#-- check, if the conversion has been called before for all sensors
if( defined($attr{$name}{tempConv}) && ( $attr{$name}{tempConv} eq "onkick") ){
$con=0;
}
#-- if the conversion has not been called before
if( $con==1 ){
#-- issue the match ROM command \x55 and the start conversion command \x44
my $now = gettimeofday();
my $delay = $convtimes{AttrVal($name,"resolution",12)};
$thread->{ExecuteTime} = $now + $delay*0.001;
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,"\x44",0);
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};
}
#-- NOW ask the specific device
#-- issue the match ROM command \x55 and the read scratchpad command \xBE
#-- reading 9 + 1 + 8 data bytes and 1 CRC byte = 19 bytes
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,"\xBE",9);
PT_WAIT_THREAD($thread->{pt_execute});
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
OWXTHERM_BinValues($hash,undef,1,$owx_dev,undef,9,$thread->{pt_execute}->PT_RETVAL());
PT_END;
});
}
#######################################################################################
#
# OWXTHERM_PT_SetValues - Implements SetFn function async
#
# Parameter hash = hash of device addressed
# a = argument array
#
########################################################################################
sub OWXTHERM_PT_SetValues($$) {
my ($hash,$args) = @_;
return PT_THREAD( sub {
my ($thread) = @_;
my ($i,$j,$k);
my $name = $hash->{NAME};
#-- ID of the device
my $owx_dev = $hash->{ROM_ID};
#-- hash of the busmaster
my $master = $hash->{IODev};
PT_BEGIN($thread);
unless (defined $args->{resolution} or defined $args->{tempLow} or defined $args->{tempHigh}) {
PT_EXIT;
}
#-- $owg_tl and $owg_th are preset and may be changed here
foreach my $key (keys %$args) {
$hash->{owg_tl} = $args->{$key} if( lc($key) eq "templow");
$hash->{owg_th} = $args->{$key} if( lc($key) eq "temphigh");
$hash->{owg_cf} = $args->{$key} if( lc($key) eq "resolution");
}
#-- put into 2's complement formed (signed byte)
my $tlp = $hash->{owg_tl} < 0 ? 128 - $hash->{owg_tl} : $hash->{owg_tl};
my $thp = $hash->{owg_th} < 0 ? 128 - $hash->{owg_th} : $hash->{owg_th};
#-- resolution is defined in bits 5+6 of configuration register
my $cfg = defined $hash->{owg_cf} ? (($hash->{owg_cf}-9) << 5) | 0x1f : 0x7f;
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
# followed by 3 bytes of data (alarm_temp_high, alarm_temp_low, config)
# config-byte of 0x7F means 12 bit resolution (750ms convert time)
#
# so far writing the EEPROM does not work properly.
# 1. \x48 directly appended to the write scratchpad command => command ok, no effect on EEPROM
# 2. \x48 appended to match ROM => command not ok.
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
my $select=sprintf("\x4E%c%c%c",$thp,$tlp,$cfg);
$thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,3);
PT_WAIT_THREAD($thread->{pt_execute});
die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
#-- process results
$hash->{PRESENT} = 1;
if ($args->{format}) {
OWTHERM_FormatValues($hash);
}
PT_END;
});
}
1; 1;
=pod =pod

View File

@ -39,7 +39,7 @@ use vars qw{%attr %defs};
sub Log($$); sub Log($$);
#-- globals on start #-- globals on start
my $version = "2.06"; my $version = "2.07";
#-- these we may get on request #-- these we may get on request
my %gets = ( my %gets = (
@ -1449,17 +1449,17 @@ sub Shelly_updown2($){
<code>set &lt;name&gt; on-for-timer|off-for-timer &lt;time&gt;</code> <code>set &lt;name&gt; on-for-timer|off-for-timer &lt;time&gt;</code>
<br />switches device on or off for &lt;time&gt; seconds. </li> <br />switches device on or off for &lt;time&gt; seconds. </li>
<li> <li>
<code>set &lt;name&gt; hsv &lt;hue value 0..360&gt;&lt;saturation value 0..1&gt;&lt;brightness value 0..1&gt; </code> <code>set &lt;name&gt; hsv &lt;hue value 0..360&gt;,&lt;saturation value 0..1&gt;,&lt;brightness value 0..1&gt; </code>
<br />6-digit hex string to set the color.</li> <br />comma separated list of hue, saturation and value to set the color</li>
<li> <li>
<code>set &lt;name&gt; rgb &lt;rrggbb&gt; </code> <code>set &lt;name&gt; rgb &lt;rrggbb&gt; </code>
<br />6-digit hex string to set the color.</li> <br />6-digit hex string to set the color</li>
<li> <li>
<code>set &lt;name&gt; rgbw &lt;rrggbbww&gt; </code> <code>set &lt;name&gt; rgbw &lt;rrggbbww&gt; </code>
<br />8-digit hex string to set the color and white value</li> <br />8-digit hex string to set the color and white value</li>
<li> <li>
<code>set &lt;name&gt; white &lt;integer&gt;</code> <code>set &lt;name&gt; white &lt;integer&gt;</code>
<br /> number 0..255 to set the white value </li> <br /> number 0..255 to set the white value</li>
</ul> </ul>
<a name="Shellyget" id="Shellyget"></a> <a name="Shellyget" id="Shellyget"></a>
<h4>Get</h4> <h4>Get</h4>