2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

git-svn-id: https://svn.fhem.de/fhem/trunk@2030 2b470e98-0d58-463d-a4d8-8e2adae1ed80

This commit is contained in:
pahenning 2012-10-28 16:57:04 +00:00
parent ae8c212d93
commit cd86005034
5 changed files with 139 additions and 113 deletions

View File

@ -13,7 +13,7 @@
# Internally these interfaces are vastly different, read the corresponding Wiki pages
# http://fhemwiki.de/wiki/Interfaces_f%C3%BCr_1-Wire
#
# Version 2.24 - October, 2012
# Version 2.25 - October, 2012
#
# Prof. Dr. Peter A. Henning, 2012
#
@ -616,93 +616,100 @@ sub OWX_Discover ($) {
}
}
}
#-- Go through all devices found on this bus
foreach my $owx_dev (@owx_devs) {
#-- three pieces of the ROM ID found on the bus
my $owx_rnf = substr($owx_dev,3,12);
my $owx_f = substr($owx_dev,0,2);
my $owx_crc = substr($owx_dev,15,3);
my $id_owx = $owx_f.".".$owx_rnf;
my $match = 0;
#-- Check against all existing devices
foreach my $fhem_dev (sort keys %main::defs) {
#-- skip if busmaster
# next if( $hash->{NAME} eq $main::defs{$fhem_dev}{NAME} );
#-- all OW types start with OW
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15);
#-- skip interface device
next if( length($id_fhem) != 15 );
#-- testing if equal to the one found here
# even with improper family
# Log 1, " FHEM-Device = ".substr($id_fhem,3,12)." OWX discovered device ".substr($id_owx,3,12);
if( substr($id_fhem,3,12) eq substr($id_owx,3,12) ) {
#-- warn if improper family id
if( substr($id_fhem,0,2) ne substr($id_owx,0,2) ){
Log 1, "OWX: Warning, $fhem_dev is defined with improper family id ".substr($id_fhem,0,2).
", correcting to ".substr($id_owx,0,2);
$main::defs{$fhem_dev}{OW_FAMILY} = substr($id_owx,0,2);
}
push(@owx_names,$main::defs{$fhem_dev}{NAME});
#-- replace the ROM ID by the proper value including CRC
$main::defs{$fhem_dev}{ROM_ID}=$owx_dev;
$main::defs{$fhem_dev}{PRESENT}=1;
$match = 1;
last;
}
#
}
#-- autocreate the device
if( $match==0 ){
#-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
#-- Family 10 = Temperature sensor, assume DS1820 as default
if( $owx_f eq "10" ){
CommandDefine(undef,"$name OWTHERM DS1820 $owx_rnf");
#-- Family 12 = Switch, assume DS2406 as default
}elsif( $owx_f eq "12" ){
CommandDefine(undef,"$name OWSWITCH DS2406 $owx_rnf");
#-- Family 1D = Counter/RAM, assume DS2423 as default
}elsif( $owx_f eq "1D" ){
CommandDefine(undef,"$name OWCOUNT DS2423 $owx_rnf");
#-- Family 20 = A/D converter, assume DS2450 as default
} elsif( $owx_f eq "20" ){
CommandDefine(undef,"$name OWAD DS2450 $owx_rnf");
#-- Family 22 = Temperature sensor, assume DS1822 as default
}elsif( $owx_f eq "22" ){
CommandDefine(undef,"$name OWTHERM DS1822 $owx_rnf");
#-- Family 26 = Multisensor, assume DS2438 as default
}elsif( $owx_f eq "26" ){
CommandDefine(undef,"$name OWMULTI DS2438 $owx_rnf");
#-- Family 28 = Temperature sensor, assume DS18B20 as default
}elsif( $owx_f eq "28" ){
CommandDefine(undef,"$name OWTHERM DS18B20 $owx_rnf");
#-- Family 29 = Switch, assume DS2408 as default
}elsif( $owx_f eq "29" ){
CommandDefine(undef,"$name OWSWITCH DS2408 $owx_rnf");
#-- Family 3A = Switch, assume DS2413 as default
}elsif( $owx_f eq "3A" ){
CommandDefine(undef,"$name OWSWITCH DS2413 $owx_rnf");
#-- Family FF = LCD display
}elsif( $owx_f eq "FF" ){
CommandDefine(undef,"$name OWLCD $owx_rnf");
#-- All unknown families are ID only (ID-Chips have family id 09)
} else {
CommandDefine(undef,"$name OWID $owx_f $owx_rnf");
}
#-- yes, it is on the bus and therefore present
push(@owx_names,$name);
$main::defs{$name}{PRESENT}=1;
#-- THIS IODev, default room
CommandAttr (undef,"$name IODev $hash->{NAME}");
CommandAttr (undef,"$name room OWX");
#-- replace the ROM ID by the proper value
$main::defs{$name}{ROM_ID}=$owx_dev;
}
foreach my $owx_dev (@owx_devs) {
#-- ignore those which do not have the proper pattern
if( !($owx_dev =~ m/[0-9A-F]{2}\.[0-9A-F]{12}\.[0-9A-F]{2}/) ){
Log 3,"OWX: Invalid 1-Wire device ID $owx_dev, ignoring it";
next;
}
#-- three pieces of the ROM ID found on the bus
my $owx_rnf = substr($owx_dev,3,12);
my $owx_f = substr($owx_dev,0,2);
my $owx_crc = substr($owx_dev,15,3);
my $id_owx = $owx_f.".".$owx_rnf;
my $match = 0;
#-- Check against all existing devices
foreach my $fhem_dev (sort keys %main::defs) {
#-- skip if busmaster
# next if( $hash->{NAME} eq $main::defs{$fhem_dev}{NAME} );
#-- all OW types start with OW
next if( substr($main::defs{$fhem_dev}{TYPE},0,2) ne "OW");
my $id_fhem = substr($main::defs{$fhem_dev}{ROM_ID},0,15);
#-- skip interface device
next if( length($id_fhem) != 15 );
#-- testing if equal to the one found here
# even with improper family
# Log 1, " FHEM-Device = ".substr($id_fhem,3,12)." OWX discovered device ".substr($id_owx,3,12);
if( substr($id_fhem,3,12) eq substr($id_owx,3,12) ) {
#-- warn if improper family id
if( substr($id_fhem,0,2) ne substr($id_owx,0,2) ){
Log 1, "OWX: Warning, $fhem_dev is defined with improper family id ".substr($id_fhem,0,2).
", correcting to ".substr($id_owx,0,2);
$main::defs{$fhem_dev}{OW_FAMILY} = substr($id_owx,0,2);
}
push(@owx_names,$main::defs{$fhem_dev}{NAME});
#-- replace the ROM ID by the proper value including CRC
$main::defs{$fhem_dev}{ROM_ID}=$owx_dev;
$main::defs{$fhem_dev}{PRESENT}=1;
$match = 1;
last;
}
#
}
#-- autocreate the device
if( $match==0 ){
#-- Default name OWX_FF_XXXXXXXXXXXX, default type = OWX_FF
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
#-- Family 10 = Temperature sensor, assume DS1820 as default
if( $owx_f eq "10" ){
CommandDefine(undef,"$name OWTHERM DS1820 $owx_rnf");
#-- Family 12 = Switch, assume DS2406 as default
}elsif( $owx_f eq "12" ){
CommandDefine(undef,"$name OWSWITCH DS2406 $owx_rnf");
#-- Family 1D = Counter/RAM, assume DS2423 as default
}elsif( $owx_f eq "1D" ){
CommandDefine(undef,"$name OWCOUNT DS2423 $owx_rnf");
#-- Family 20 = A/D converter, assume DS2450 as default
} elsif( $owx_f eq "20" ){
CommandDefine(undef,"$name OWAD DS2450 $owx_rnf");
#-- Family 22 = Temperature sensor, assume DS1822 as default
}elsif( $owx_f eq "22" ){
CommandDefine(undef,"$name OWTHERM DS1822 $owx_rnf");
#-- Family 26 = Multisensor, assume DS2438 as default
}elsif( $owx_f eq "26" ){
CommandDefine(undef,"$name OWMULTI DS2438 $owx_rnf");
#-- Family 28 = Temperature sensor, assume DS18B20 as default
}elsif( $owx_f eq "28" ){
CommandDefine(undef,"$name OWTHERM DS18B20 $owx_rnf");
#-- Family 29 = Switch, assume DS2408 as default
}elsif( $owx_f eq "29" ){
CommandDefine(undef,"$name OWSWITCH DS2408 $owx_rnf");
#-- Family 3A = Switch, assume DS2413 as default
}elsif( $owx_f eq "3A" ){
CommandDefine(undef,"$name OWSWITCH DS2413 $owx_rnf");
#-- Family FF = LCD display
}elsif( $owx_f eq "FF" ){
CommandDefine(undef,"$name OWLCD $owx_rnf");
#-- All unknown families are ID only (ID-Chips have family id 09)
} else {
CommandDefine(undef,"$name OWID $owx_f $owx_rnf");
}
#-- yes, it is on the bus and therefore present
push(@owx_names,$name);
$main::defs{$name}{PRESENT}=1;
#-- THIS IODev, default room
CommandAttr (undef,"$name IODev $hash->{NAME}");
CommandAttr (undef,"$name room OWX");
#-- replace the ROM ID by the proper value
$main::defs{$name}{ROM_ID}=$owx_dev;
}
}
#-- final step: Undefine all 1-Wire devices which are not on this bus but have this IODev
foreach my $fhem_dev (sort keys %main::defs) {

View File

@ -16,7 +16,7 @@
#
# Prof. Dr. Peter A. Henning, 2012
#
# Version 2.24 - October, 2012
# Version 2.25 - October, 2012
#
# Setup bus device in fhem.cfg as
#
@ -44,10 +44,14 @@
#
# attr <name> event on-change/on-update = when to write an event (default= on-update)
#
# attr <name> stateAL0 "<string>" = character string for denoting low normal condition, default is green down triangle
# attr <name> stateAH0 "<string>" = character string for denoting high normal condition, default is green up triangle
# attr <name> stateAL1 "<string>" = character string for denoting low alarm condition, default is red down triangle
# attr <name> stateAH1 "<string>" = character string for denoting high alarm condition, default is red up triangle
# attr <name> stateAL0 "<string>" = character string for denoting low normal condition, default is empty,
# overwritten by attribute setting green down triangle
# attr <name> stateAH0 "<string>" = character string for denoting high normal condition, default is empty,
# overwritten by attribute setting green up triangle
# attr <name> stateAL1 "<string>" = character string for denoting low alarm condition, default is l,
# overwritten by attributre setting red down triangle
# attr <name> stateAH1 "<string>" = character string for denoting high alarm condition, default is h,
# overwritten by attributre setting red up triangle
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
# attr <name> <channel>Unit <string>|<string> = unit of measurement for this channel | its abbreviation
# attr <name> <channel>Offset <float> = offset added to the reading in this channel
@ -102,8 +106,6 @@ my @owg_shigh;
#-- alarm values - always the raw values committed to the device
my @owg_vlow;
my @owg_vhigh;
#-- variables for display strings
my ($stateal1,$stateah1,$stateal0,$stateah0);
my %gets = (
"id" => "",
@ -254,10 +256,11 @@ sub OWAD_InitializeDevice($) {
my $name = $hash->{NAME};
$stateal1 = defined($attr{$name}{stateAL1}) ? $attr{$name}{stateAL1} : "<span style=\"color:red\">&#x25BE;</span>";
$stateah1 = defined($attr{$name}{stateAH1}) ? $attr{$name}{stateAH1} : "<span style=\"color:red\">&#x25B4;</span>";
$stateal0 = defined($attr{$name}{stateAL0}) ? $attr{$name}{stateAL0} : "<span style=\"color:green\">&#x25BE;</span>";
$stateah0 = defined($attr{$name}{stateAH0}) ? $attr{$name}{stateAH0} : "<span style=\"color:green\">&#x25B4;</span>";
#-- more colorful alarm signatures
CommandAttr (undef,"$name stateAL1 <span style=\"color:red\">&#x25BE;</span>");
CommandAttr (undef,"$name stateAH1 <span style=\"color:red\">&#x25B4;</span>");
CommandAttr (undef,"$name stateAL0 <span style=\"color:green\">&#x25BE;</span>");
CommandAttr (undef,"$name stateAH0 <span style=\"color:green\">&#x25B4;</span>");
#-- Initial readings
@owg_val = (0.0,0.0,0.0,0.0);
@ -346,6 +349,12 @@ sub OWAD_FormatValues($) {
my $tn = TimeNow();
#-- alarm signatures
my $stateal1 = defined($attr{$name}{stateAL1}) ? $attr{$name}{stateAL1} : "l";
my $stateah1 = defined($attr{$name}{stateAH1}) ? $attr{$name}{stateAH1} : "h";
my $stateal0 = defined($attr{$name}{stateAL0}) ? $attr{$name}{stateAL0} : "";
my $stateah0 = defined($attr{$name}{stateAH0}) ? $attr{$name}{stateAH0} : "";
#-- formats for output
for (my $i=0;$i<int(@owg_fixed);$i++){
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|voltage";

View File

@ -14,7 +14,7 @@
#
# Prof. Dr. Peter A. Henning, 2012
#
# Version 2.24 - October, 2012
# Version 2.25 - October, 2012
#
# Setup bus device in fhem.cfg as
#

View File

@ -17,7 +17,7 @@
#
# Prof. Dr. Peter A. Henning, 2012
#
# Version 2.24 - October, 2012
# Version 2.25 - October, 2012
#
# Setup bus device in fhem.cfg as
#
@ -52,9 +52,11 @@
#
# attr <name> event on-change/on-update = when to write an event (default= on-update)
#
# attr <name> stateS <string> = character string denoting external shortening condition, default is (ext)
# overwritten by an attribute setting "red angled arrow downwward"
#
# attr <name> <channel>Name <string>|<string> = name for the channel | a type description for the measured value
# attr <name> <channel>Unit <string>|<string> = values to display in state variable for on|off condition
# attr <name> <channel>stateS <string> = character string denoting external shortening condition
#
########################################################################################
#
@ -138,14 +140,13 @@ sub OWSWITCH_Initialize ($) {
$hash->{SetFn} = "OWSWITCH_Set";
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2413,DS2406,DS2408 loglevel:0,1,2,3,4,5 ".
"event:on-update,on-change";
"event:on-update,on-change stateS ";
#TODO: correct number of channels
for( my $i=0;$i<8;$i++ ){
$attlist .= " ".$owg_fixed[$i]."Name";
$attlist .= " ".$owg_fixed[$i]."Unit";
$attlist .= " ".$owg_fixed[$i]."stateS";
}
$hash->{AttrList} = $attlist;
}
@ -251,6 +252,9 @@ sub OWSWITCH_InitializeDevice($) {
my $name = $hash->{NAME};
#-- more colorful shortening signature
CommandAttr (undef,"$name stateS <span style=\"color:red\">&#x2607;</span>");
#-- Set channel names, channel units
for( my $i=0;$i<$cnumber{$attr{$name}{"model"}} ;$i++) {
#-- Initial readings OFF
@ -312,9 +316,12 @@ sub OWSWITCH_FormatValues($) {
my $name = $hash->{NAME};
my ($offset,$factor,$vval,$vvax,$vstr,$cname,@cnama,@unarr);
my ($value1,$value2,$value3) = ("","","");
my $tn = TimeNow();
#-- external shortening signature
my $sname = defined($attr{$name}{"stateS"}) ? $attr{$name}{"stateS"} : "(ext)";
#-- formats for output
for (my $i=0;$i<$cnumber{$attr{$name}{"model"}};$i++){
$cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i];
@ -328,9 +335,9 @@ sub OWSWITCH_FormatValues($) {
#-- string buildup for return value and STATE
@unarr= split(/\|/,$hash->{READINGS}{"$owg_channel[$i]"}{UNIT});
$cname = defined($attr{$name}{$owg_fixed[$i]."stateS"}) ? $attr{$name}{$owg_fixed[$i]."stateS"} : "<span style=\"color:red\">&#x2607;</span>";
$vstr = $unarr[$vval];
$vstr .= $cname if( ($vval == 0) && ($vvax == 1) );
$vstr .= $sname if( ($vval == 0) && ($vvax == 1) );
$vstr = "ERR" if( ($vval == 1) && ($vvax == 0) );
$value1 .= sprintf( "%s: %s", $owg_channel[$i], $vstr);
@ -623,8 +630,8 @@ sub OWSWITCH_Set($@) {
#-- set state
}elsif( $key eq "gpio" ){
#-- check value and write to device
return "OWSWITCH: Set with wrong value for gpio port, must be 0 <= gpio <= ".(1 << $cnumber{$attr{$name}{"model"}} - 1)
if( ! ((int($value) >= 0) && (int($value) <= (1 << $cnumber{$attr{$name}{"model"}} -1 ))) );
return "OWSWITCH: Set with wrong value for gpio port, must be 0 <= gpio <= ".((1 << $cnumber{$attr{$name}{"model"}})-1)
if( ! ((int($value) >= 0) && (int($value) <= ((1 << $cnumber{$attr{$name}{"model"}})-1 ))) );
if( $interface eq "OWX" ){
$ret = OWXSWITCH_SetState($hash,int($value));

View File

@ -45,8 +45,10 @@
#
# attr <name> event on-change/on-update = when to write an event (default= on-update)
#
# attr <name> stateAL "<string>" = character string for denoting low alarm condition, default is red down triangle
# attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is red up triangle
# attr <name> stateAL "<string>" = character string for denoting low alarm condition, default is (-),
# overwritten by attribute setting red down triangle
# attr <name> stateAH "<string>" = character string for denoting high alarm condition, default is (+),
# overwritten by attribute setting red up triangle
# attr <name> tempOffset <float> = temperature offset in degree Celsius added to the raw temperature reading
# attr <name> tempUnit <string> = unit of measurement, e.g. Celsius/Kelvin/Fahrenheit or C/K/F, default is Celsius
# attr <name> tempLow <float> = value for low alarm
@ -239,8 +241,9 @@ sub OWTHERM_InitializeDevice($) {
my $name = $hash->{NAME};
my @args;
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "<span style=\"color:red\">&#x25BE;</span>";
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "<span style=\"color:red\">&#x25B4;</span>";
#-- more colorful alarm signatures
CommandAttr (undef,"$name stateAL <span style=\"color:red\">&#x25BE;</span>");
CommandAttr (undef,"$name stateAH <span style=\"color:red\">&#x25B4;</span>");
#-- unit attribute defined ?
$hash->{READINGS}{"temperature"}{UNIT} = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : "Celsius";
@ -278,8 +281,8 @@ sub OWTHERM_FormatValues($) {
my $tn = TimeNow();
#-- attributes defined ?
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "<span style=\"color:red\">&#x25BE;</span>";
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "<span style=\"color:red\">&#x25B4;</span>";
$stateal = defined($attr{$name}{stateAL}) ? $attr{$name}{stateAL} : "(-)";
$stateah = defined($attr{$name}{stateAH}) ? $attr{$name}{stateAH} : "(+)";
$unit = defined($attr{$name}{"tempUnit"}) ? $attr{$name}{"tempUnit"} : $hash->{READINGS}{"temperature"}{UNIT};
$offset = defined($attr{$name}{"tempOffset"}) ? $attr{$name}{"tempOffset"} : 0.0 ;
$factor = 1.0;