mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@1408 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
cb8e092ae8
commit
ba1d2c867f
@ -6,7 +6,7 @@
|
|||||||
# via an active DS2480/DS2490/DS9097U bus master interface or
|
# via an active DS2480/DS2490/DS9097U bus master interface or
|
||||||
# via a passive DS9097 interface
|
# via a passive DS9097 interface
|
||||||
#
|
#
|
||||||
# Version 1.10 - March, 2012
|
# Version 1.11 - March, 2012
|
||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
@ -118,7 +118,7 @@ sub OWX_Initialize ($) {
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
#-- Provider
|
#-- Provider
|
||||||
#$hash->{Clients} = ":OWCOUNT:OWHUB:OWLCD:OWMULTI:OWSWITCH:OWTEMP:";
|
#$hash->{Clients} = ":OWCOUNT:OWHUB:OWLCD:OWMULTI:OWSWITCH:OWTEMP:";
|
||||||
$hash->{Clients} = ":OWAD:OWID:OWLCD:OWTEMP:";
|
$hash->{Clients} = ":OWAD:OWCOUNT:OWID:OWLCD:OWTEMP:";
|
||||||
|
|
||||||
#-- Normal Devices
|
#-- Normal Devices
|
||||||
$hash->{DefFn} = "OWX_Define";
|
$hash->{DefFn} = "OWX_Define";
|
||||||
@ -516,7 +516,10 @@ sub OWX_Discover ($) {
|
|||||||
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
|
my $name = sprintf "OWX_%s_%s",$owx_f,$owx_rnf;
|
||||||
#-- Family 10 = Temperature sensor, assume DS1820 as default
|
#-- Family 10 = Temperature sensor, assume DS1820 as default
|
||||||
if( $owx_f eq "10" ){
|
if( $owx_f eq "10" ){
|
||||||
CommandDefine(undef,"$name OWTEMP DS1820 $owx_rnf");
|
CommandDefine(undef,"$name OWTEMP DS1820 $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
|
#-- Family 20 = A/D converter, assume DS2450 as default
|
||||||
} elsif( $owx_f eq "20" ){
|
} elsif( $owx_f eq "20" ){
|
||||||
CommandDefine(undef,"$name OWAD DS2450 $owx_rnf");
|
CommandDefine(undef,"$name OWAD DS2450 $owx_rnf");
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# OWAD.pm
|
# OWAD.pm
|
||||||
#
|
#
|
||||||
# FHEM module to commmunicate with 1-Wire A/D converters
|
# FHEM module to commmunicate with 1-Wire A/D converters DS2450
|
||||||
#
|
#
|
||||||
# Attention: This module may communicate with the OWX module,
|
# Attention: This module may communicate with the OWX module,
|
||||||
# but currently not with the 1-Wire File System OWFS
|
# but currently not with the 1-Wire File System OWFS
|
||||||
@ -14,7 +14,7 @@
|
|||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 1.10 - March, 2012
|
# Version 1.11 - March, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
@ -948,7 +948,7 @@ sub OWXAD_GetPage($$) {
|
|||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
#
|
#
|
||||||
# OWXAD_SetPage - Setup one memory page of device
|
# OWXAD_SetPage - Set one page of device
|
||||||
#
|
#
|
||||||
# Parameter hash = hash of device addressed
|
# Parameter hash = hash of device addressed
|
||||||
# page = "alarm" or "status"
|
# page = "alarm" or "status"
|
||||||
@ -1014,7 +1014,7 @@ sub OWXAD_SetPage($$) {
|
|||||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb1;
|
$select .= sprintf "%c\xFF\xFF\xFF",$sb1;
|
||||||
$select .= sprintf "%c\xFF\xFF\xFF",$sb2;
|
$select .= sprintf "%c\xFF\xFF\xFF",$sb2;
|
||||||
}
|
}
|
||||||
#=============== wrong pag ewrit eattempt ===============================
|
#=============== wrong page write attempt ===============================
|
||||||
} else {
|
} else {
|
||||||
return "OWXAD: Wrong memory page write attempt";
|
return "OWXAD: Wrong memory page write attempt";
|
||||||
}
|
}
|
||||||
|
744
fhem/contrib/1-Wire/21_OWCOUNT.pm
Normal file
744
fhem/contrib/1-Wire/21_OWCOUNT.pm
Normal file
@ -0,0 +1,744 @@
|
|||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT.pm BETA Version
|
||||||
|
#
|
||||||
|
# FHEM module to commmunicate with 1-Wire Counter/RAM DS2423
|
||||||
|
#
|
||||||
|
# Attention: This module may communicate with the OWX module,
|
||||||
|
# but currently not with the 1-Wire File System OWFS
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# SO FAR ONLY external counter inputs A,B are available ! Neither memory content, nor internal counters are questioned.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Prefixes for subroutines of this module:
|
||||||
|
# OW = General 1-Wire routines Peter Henning)
|
||||||
|
# OWX = 1-Wire bus master interface (Peter Henning)
|
||||||
|
# OWFS = 1-Wire file system (??)
|
||||||
|
#
|
||||||
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
|
#
|
||||||
|
# Version 1.11 - March, 2012
|
||||||
|
#
|
||||||
|
# Setup bus device in fhem.cfg as
|
||||||
|
#
|
||||||
|
# define <name> OWCOUNT [<model>] <ROM_ID> [interval]
|
||||||
|
#
|
||||||
|
# where <name> may be replaced by any name string
|
||||||
|
#
|
||||||
|
# <model> is a 1-Wire device type. If omitted, we assume this to be an
|
||||||
|
# DS2423 Counter/RAM
|
||||||
|
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||||
|
# without Family ID, e.g. A2D90D000800
|
||||||
|
# [interval] is an optional query interval in seconds
|
||||||
|
#
|
||||||
|
# get <name> id => FAM_ID.ROM_ID.CRC
|
||||||
|
# get <name> present => 1 if device present, 0 if not
|
||||||
|
# get <name> interval => query interval
|
||||||
|
# get <name> counter A,B => value for counter
|
||||||
|
#
|
||||||
|
# set <name> interval => set period for measurement
|
||||||
|
#
|
||||||
|
# Additional attributes are defined in fhem.cfg, in some cases per channel, where <channel>=A,B
|
||||||
|
# Note: attributes are read only during initialization procedure - later changes are not used.
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
# attr <name> <channel>Factor <float> = factor multiplied to (reading+offset) in this channel
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# This programm is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# The GNU General Public License can be found at
|
||||||
|
# http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||||
|
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||||
|
#
|
||||||
|
# This script is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
package main;
|
||||||
|
|
||||||
|
#-- Prototypes to make komodo happy
|
||||||
|
use vars qw{%attr %defs};
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
sub Log($$);
|
||||||
|
|
||||||
|
#-- value globals
|
||||||
|
my @owg_status;
|
||||||
|
my $owg_state;
|
||||||
|
#-- channel name - fixed is the first array, variable the second
|
||||||
|
my @owg_fixed = ("A","B");
|
||||||
|
my @owg_channel;
|
||||||
|
#-- channel values - always the raw values from the device
|
||||||
|
my @owg_val;
|
||||||
|
|
||||||
|
my %gets = (
|
||||||
|
"id" => "",
|
||||||
|
"present" => "",
|
||||||
|
"interval" => "",
|
||||||
|
#"page" => "",
|
||||||
|
"counter" => "",
|
||||||
|
);
|
||||||
|
|
||||||
|
my %sets = (
|
||||||
|
"interval" => ""
|
||||||
|
#"page" => ""
|
||||||
|
);
|
||||||
|
|
||||||
|
my %updates = (
|
||||||
|
"present" => "",
|
||||||
|
"counter" => ""
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# The following subroutines are independent of the bus interface
|
||||||
|
#
|
||||||
|
# Prefix = OWCOUNT
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_Initialize
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_Initialize ($) {
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
$hash->{DefFn} = "OWCOUNT_Define";
|
||||||
|
$hash->{UndefFn} = "OWCOUNT_Undef";
|
||||||
|
$hash->{GetFn} = "OWCOUNT_Get";
|
||||||
|
$hash->{SetFn} = "OWCOUNT_Set";
|
||||||
|
#Name = channel name
|
||||||
|
#Offset = an offset added to the reading
|
||||||
|
#Factor = a factor multiplied with (reading+offset)
|
||||||
|
#Unit = a unit of measure
|
||||||
|
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model:DS2450 loglevel:0,1,2,3,4,5 ";
|
||||||
|
|
||||||
|
for( my $i=0;$i<int(@owg_fixed);$i++ ){
|
||||||
|
$attlist .= " ".$owg_fixed[$i]."Name";
|
||||||
|
$attlist .= " ".$owg_fixed[$i]."Offset";
|
||||||
|
$attlist .= " ".$owg_fixed[$i]."Factor";
|
||||||
|
$attlist .= " ".$owg_fixed[$i]."Unit";
|
||||||
|
}
|
||||||
|
$hash->{AttrList} = $attlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
#########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_Define - Implements DefFn function
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed, def = definition string
|
||||||
|
#
|
||||||
|
#########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_Define ($$) {
|
||||||
|
my ($hash, $def) = @_;
|
||||||
|
|
||||||
|
# define <name> OWCOUNT [<model>] <id> [interval]
|
||||||
|
# e.g.: define flow OWCOUNT 525715020000 300
|
||||||
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
|
my ($name,$model,$fam,$id,$crc,$interval,$scale,$ret);
|
||||||
|
|
||||||
|
#-- default
|
||||||
|
$name = $a[0];
|
||||||
|
$interval = 300;
|
||||||
|
$scale = "";
|
||||||
|
$ret = "";
|
||||||
|
|
||||||
|
#-- check syntax
|
||||||
|
return "OWCOUNT: Wrong syntax, must be define <name> OWCOUNT [<model>] <id> [interval]"
|
||||||
|
if(int(@a) < 2 || int(@a) > 5);
|
||||||
|
|
||||||
|
#-- check if this is an old style definition, e.g. <model> is missing
|
||||||
|
my $a2 = $a[2];
|
||||||
|
my $a3 = defined($a[3]) ? $a[3] : "";
|
||||||
|
if( $a2 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||||
|
$model = "DS2423";
|
||||||
|
$id = $a[2];
|
||||||
|
if(int(@a)>=4) { $interval = $a[3]; }
|
||||||
|
} elsif( $a3 =~ m/^[0-9|a-f|A-F]{12}$/ ) {
|
||||||
|
$model = $a[2];
|
||||||
|
return "OWCOUNT: Wrong 1-Wire device model $model"
|
||||||
|
if( $model ne "DS2423");
|
||||||
|
$id = $a[3];
|
||||||
|
} else {
|
||||||
|
return "OWCOUNT: $a[0] ID $a[2] invalid, specify a 12 digit value";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- 1-Wire ROM identifier in the form "FF.XXXXXXXXXXXX.YY"
|
||||||
|
# determine CRC Code - only if this is a direct interface
|
||||||
|
$crc = defined($hash->{IODev}->{INTERFACE}) ? sprintf("%02x",OWX_CRC("1D.".$id."00")) : "00";
|
||||||
|
|
||||||
|
#-- Define device internals
|
||||||
|
$hash->{ROM_ID} = "1D.".$id.$crc;
|
||||||
|
$hash->{OW_ID} = $id;
|
||||||
|
$hash->{OW_FAMILY} = "1D";
|
||||||
|
$hash->{PRESENT} = 0;
|
||||||
|
$hash->{INTERVAL} = $interval;
|
||||||
|
|
||||||
|
#-- Couple to I/O device
|
||||||
|
AssignIoPort($hash);
|
||||||
|
Log 3, "OWCOUNT: Warning, no 1-Wire I/O device found for $name."
|
||||||
|
if(!defined($hash->{IODev}->{NAME}));
|
||||||
|
$modules{OWCOUNT}{defptr}{$id} = $hash;
|
||||||
|
$hash->{STATE} = "Defined";
|
||||||
|
Log 3, "OWCOUNT: Device $name defined.";
|
||||||
|
|
||||||
|
#-- Initialization reading according to interface type
|
||||||
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
|
||||||
|
#-- Start timer for initialization in a few seconds
|
||||||
|
InternalTimer(time()+1, "OWCOUNT_InitializeDevice", $hash, 0);
|
||||||
|
|
||||||
|
#-- Start timer for updates
|
||||||
|
InternalTimer(time()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 0);
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_InitializeDevice - delayed setting of initial readings and channel names
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_InitializeDevice($) {
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
#-- Initial readings
|
||||||
|
@owg_val = (0.0,0.0,0.0,0.0);
|
||||||
|
|
||||||
|
#-- Set channel names, channel units and alarm values
|
||||||
|
for( my $i=0;$i<int(@owg_fixed);$i++) {
|
||||||
|
#-- name
|
||||||
|
my $cname = defined($attr{$name}{$owg_fixed[$i]."Name"}) ? $attr{$name}{$owg_fixed[$i]."Name"} : $owg_fixed[$i]."|event";
|
||||||
|
my @cnama = split(/\|/,$cname);
|
||||||
|
Log 1, "OWCOUNT: InitializeDevice with insufficient name specification $cname"
|
||||||
|
if( int(@cnama)!=2 );
|
||||||
|
$owg_channel[$i] = $cnama[0];
|
||||||
|
#-- unit
|
||||||
|
my $unit = defined($attr{$name}{$owg_fixed[$i]."Unit"}) ? $attr{$name}{$owg_fixed[$i]."Unit"} : "counts|";
|
||||||
|
my @unarr= split(/\|/,$unit);
|
||||||
|
#Log 1, "OWCOUNT: InitializeDevice with insufficient unit specification $unit"
|
||||||
|
# if( int(@unarr)!=2 );
|
||||||
|
#-- offset and scale factor
|
||||||
|
my $offset = defined($attr{$name}{$owg_fixed[$i]."Offset"}) ? $attr{$name}{$owg_fixed[$i]."Offset"} : 0;
|
||||||
|
my $factor = defined($attr{$name}{$owg_fixed[$i]."Factor"}) ? $attr{$name}{$owg_fixed[$i]."Factor"} : 1;
|
||||||
|
#-- put into readings
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{TYPE} = defined($cnama[1]) ? $cnama[1] : "unknown";
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{UNIT} = $unarr[0];
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR} = defined($unarr[1]) ? $unarr[1] : "?";
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{OFFSET} = $offset;
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{FACTOR} = $factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- set status according to interface type
|
||||||
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
|
||||||
|
#-- OWX interface
|
||||||
|
if( !defined($interface) ){
|
||||||
|
return "OWCOUNT: Interface missing";
|
||||||
|
} elsif( $interface eq "OWX" ){
|
||||||
|
#-- OWFS interface
|
||||||
|
#}elsif( $interface eq "OWFS" ){
|
||||||
|
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||||
|
#-- Unknown interface
|
||||||
|
}else{
|
||||||
|
return "OWCOUNT: InitializeDevice with wrong IODev type $interface";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- Initialize all the display stuff
|
||||||
|
OWCOUNT_FormatValues($hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_FormatValues - put together various format strings
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed, fs = format string
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_FormatValues($) {
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my ($offset,$factor,$vval);
|
||||||
|
my ($value1,$value2,$value3) = ("","","");
|
||||||
|
my $galarm = 0;
|
||||||
|
|
||||||
|
my $tn = TimeNow();
|
||||||
|
|
||||||
|
#-- formats for output
|
||||||
|
for (my $i=0;$i<int(@owg_fixed);$i++){
|
||||||
|
$offset = $hash->{READINGS}{"$owg_channel[$i]"}{OFFSET};
|
||||||
|
$factor = $hash->{READINGS}{"$owg_channel[$i]"}{FACTOR};
|
||||||
|
#-- correct values for proper offset, factor
|
||||||
|
$vval = int(($owg_val[$i] + $offset)*$factor*1000)/1000;;
|
||||||
|
#-- put into READINGS
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{VAL} = $vval;
|
||||||
|
$hash->{READINGS}{"$owg_channel[$i]"}{TIME} = $tn;
|
||||||
|
|
||||||
|
#-- string buildup for return value and STATE
|
||||||
|
$value1 .= sprintf( "%s: %5.3f %s", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
|
||||||
|
$value2 .= sprintf( "%s: %5.2f %s ", $owg_channel[$i], $vval,$hash->{READINGS}{"$owg_channel[$i]"}{UNITABBR});
|
||||||
|
$value3 .= sprintf( "%s: " , $owg_channel[$i]);
|
||||||
|
|
||||||
|
#-- insert comma
|
||||||
|
if( $i<3 ){
|
||||||
|
$value1 .= " ";
|
||||||
|
$value2 .= ", ";
|
||||||
|
$value3 .= ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#-- STATE
|
||||||
|
$hash->{STATE} = $value2;
|
||||||
|
|
||||||
|
return $value1;
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_Get - Implements GetFn function
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed, a = argument array
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_Get($@) {
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
my $reading = $a[1];
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $model = $hash->{OW_MODEL};
|
||||||
|
my ($value,$value2,$value3) = (undef,undef,undef);
|
||||||
|
my $ret = "";
|
||||||
|
my $offset;
|
||||||
|
my $factor;
|
||||||
|
|
||||||
|
#-- check syntax
|
||||||
|
return "OWCOUNT: Get argument is missing @a"
|
||||||
|
if(int(@a) < 2);
|
||||||
|
|
||||||
|
#-- check argument
|
||||||
|
return "OWCOUNT: Get with unknown argument $a[1], choose one of ".join(",", sort keys %gets)
|
||||||
|
if(!defined($gets{$a[1]}));
|
||||||
|
|
||||||
|
#-- get id
|
||||||
|
if($a[1] eq "id") {
|
||||||
|
$value = $hash->{ROM_ID};
|
||||||
|
return "$a[0] $reading => $value";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- get present
|
||||||
|
if($a[1] eq "present") {
|
||||||
|
#-- hash of the busmaster
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||||
|
$hash->{PRESENT} = $value;
|
||||||
|
return "$a[0] $reading => $value";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- get interval
|
||||||
|
if($a[1] eq "interval") {
|
||||||
|
$value = $hash->{INTERVAL};
|
||||||
|
return "$a[0] $reading => $value";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- reset presence
|
||||||
|
$hash->{PRESENT} = 0;
|
||||||
|
|
||||||
|
#-- get memory page/counter according to interface type
|
||||||
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
|
||||||
|
#-- check syntax for getting counter
|
||||||
|
if( $reading eq "counter" ){
|
||||||
|
return "OWCOUNT: get needs parameter when reading counter: <channel>"
|
||||||
|
if( int(@a)<2 );
|
||||||
|
#-- channle may be addressed by bare channel name (A..D) or by defined channel name
|
||||||
|
return "OWCOUNT: invalid counter address, must be A or B"
|
||||||
|
if( !($a[2] =~ m/[AB]/) );
|
||||||
|
my $page = ($a[2] eq "A") ? 14 : 15;
|
||||||
|
|
||||||
|
#-- OWX interface
|
||||||
|
if( $interface eq "OWX" ){
|
||||||
|
$ret = OWXCOUNT_GetPage($hash,$page);
|
||||||
|
#-- OWFS interface
|
||||||
|
#}elsif( $interface eq "OWFS" ){
|
||||||
|
# $ret = OWFSAD_GetPage($hash,"reading");
|
||||||
|
#-- Unknown interface
|
||||||
|
}else{
|
||||||
|
return "OWCOUNT: Get with wrong IODev type $interface";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
if( defined($ret) ){
|
||||||
|
return "OWCOUNT: Could not get values from device $name";
|
||||||
|
}
|
||||||
|
$hash->{PRESENT} = 1;
|
||||||
|
return "OWCOUNT: $name.$reading => ".OWCOUNT_FormatValues($hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_GetValues - Updates the reading from one device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_GetValues($) {
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $model = $hash->{OW_MODEL};
|
||||||
|
my $value = "";
|
||||||
|
my $ret = "";
|
||||||
|
my $offset;
|
||||||
|
my $factor;
|
||||||
|
|
||||||
|
#-- define warnings
|
||||||
|
my $warn = "none";
|
||||||
|
$hash->{ALARM} = "0";
|
||||||
|
|
||||||
|
#-- restart timer for updates
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(time()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 1);
|
||||||
|
|
||||||
|
#-- reset presence
|
||||||
|
$hash->{PRESENT} = 0;
|
||||||
|
|
||||||
|
#-- Get readings, alarms and stati according to interface type
|
||||||
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
if( $interface eq "OWX" ){
|
||||||
|
$ret = OWXAD_GetPage($hash,"reading");
|
||||||
|
$ret = OWXAD_GetPage($hash,"status");
|
||||||
|
#}elsif( $interface eq "OWFS" ){
|
||||||
|
# $ret = OWFSAD_GetValues($hash);
|
||||||
|
}else{
|
||||||
|
return "OWCOUNT: GetValues with wrong IODev type $interface";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
if( defined($ret) ){
|
||||||
|
return "OWCOUNT: Could not get values from device $name";
|
||||||
|
}
|
||||||
|
$hash->{PRESENT} = 1;
|
||||||
|
$value=OWCOUNT_FormatValues($hash);
|
||||||
|
#--logging
|
||||||
|
Log 5, $value;
|
||||||
|
$hash->{CHANGED}[0] = $value;
|
||||||
|
|
||||||
|
DoTrigger($name, undef);
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_Set - Set one value for device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# a = argument array
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_Set($@) {
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
my $key = $a[1];
|
||||||
|
my $value = $a[2];
|
||||||
|
|
||||||
|
#-- for the selector: which values are possible
|
||||||
|
if (@a == 2){
|
||||||
|
my $newkeys = join(" ", sort keys %sets);
|
||||||
|
for( my $i=0;$i<4;$i++ ){
|
||||||
|
$newkeys .= " ".$owg_channel[$i]."Alarm";
|
||||||
|
$newkeys .= " ".$owg_channel[$i]."Low";
|
||||||
|
$newkeys .= " ".$owg_channel[$i]."High";
|
||||||
|
}
|
||||||
|
return $newkeys ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- check syntax
|
||||||
|
return "OWCOUNT: Set needs one parameter when setting this value"
|
||||||
|
if( int(@a)!=3 );
|
||||||
|
|
||||||
|
#-- check argument
|
||||||
|
if( !defined($sets{$a[1]}) && !($key =~ m/.*(Alarm|Low|High)/) ){
|
||||||
|
return "OWCOUNT: Set with unknown argument $a[1]";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- define vars
|
||||||
|
my $ret = undef;
|
||||||
|
my $channel = undef;
|
||||||
|
my $channo = undef;
|
||||||
|
my $factor;
|
||||||
|
my $offset;
|
||||||
|
my $condx;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $model = $hash->{OW_MODEL};
|
||||||
|
|
||||||
|
#-- set new timer interval
|
||||||
|
if($key eq "interval") {
|
||||||
|
# check value
|
||||||
|
return "OWCOUNT: Set with short interval, must be > 1"
|
||||||
|
if(int($value) < 1);
|
||||||
|
# update timer
|
||||||
|
$hash->{INTERVAL} = $value;
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 1);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- find out which channel we have
|
||||||
|
my $tc =$key;
|
||||||
|
if( $tc =~ s/(.*)(Alarm|Low|High)/$channel=$1/se ) {
|
||||||
|
for (my $i=0;$i<4;$i++){
|
||||||
|
if( $tc eq $owg_channel[$i] ){
|
||||||
|
$channo = $i;
|
||||||
|
$channel = $tc;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "OWCOUNT: Cannot determine channel from parameter $a[1]"
|
||||||
|
if( !(defined($channo)));
|
||||||
|
|
||||||
|
#-- set these values depending on interface type
|
||||||
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
|
||||||
|
#-- OWX interface
|
||||||
|
if( $interface eq "OWX" ){
|
||||||
|
$ret = OWXAD_SetPage($hash,"status");
|
||||||
|
return $ret
|
||||||
|
if(defined($ret));
|
||||||
|
#-- OWFS interface
|
||||||
|
#}elsif( $interface eq "OWFS" ){
|
||||||
|
# $ret = OWFSAD_SetValues($hash,@a);
|
||||||
|
# return $ret
|
||||||
|
# if(defined($ret));
|
||||||
|
} else {
|
||||||
|
return "OWCOUNT: Set with wrong IODev type $interface";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
|
||||||
|
$hash->{PRESENT} = 1;
|
||||||
|
OWCOUNT_FormatValues($hash);
|
||||||
|
|
||||||
|
Log 4, "OWCOUNT: Set $hash->{NAME} $key $value";
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWCOUNT_Undef - Implements UndefFn function
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWCOUNT_Undef ($) {
|
||||||
|
my ($hash) = @_;
|
||||||
|
delete($modules{OWCOUNT}{defptr}{$hash->{OW_ID}});
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||||
|
# via OWFS
|
||||||
|
#
|
||||||
|
# Prefix = OWFSCOUNT
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# The following subroutines in alphabetical order are only for a 1-Wire bus connected
|
||||||
|
# directly to the FHEM server
|
||||||
|
#
|
||||||
|
# Prefix = OWXAD
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWXAD_GetPage - Get one memory page + counter from device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# page = "reading", "alarm" or "status"
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWXCOUNT_GetPage($$) {
|
||||||
|
|
||||||
|
my ($hash,$page) = @_;
|
||||||
|
|
||||||
|
#-- For now, switch on conversion command
|
||||||
|
my $con=1;
|
||||||
|
|
||||||
|
my ($select, $res, $res2, $res3, @data);
|
||||||
|
|
||||||
|
#-- ID of the device
|
||||||
|
my $owx_dev = $hash->{ROM_ID};
|
||||||
|
my $owx_rnf = substr($owx_dev,3,12);
|
||||||
|
my $owx_f = substr($owx_dev,0,2);
|
||||||
|
|
||||||
|
#-- hash of the busmaster
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
|
||||||
|
my ($i,$j,$k);
|
||||||
|
|
||||||
|
#-- 8 byte 1-Wire device address
|
||||||
|
my @owx_ROM_ID =(0,0,0,0 ,0,0,0,0);
|
||||||
|
#-- from search string to byte id
|
||||||
|
my $devs=$owx_dev;
|
||||||
|
$devs=~s/\.//g;
|
||||||
|
for($i=0;$i<8;$i++){
|
||||||
|
$owx_ROM_ID[$i]=hex(substr($devs,2*$i,2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#=============== wrong value requested ===============================
|
||||||
|
if( ($page<0) || ($page>15) ){
|
||||||
|
return "OWXCOUNT: 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;
|
||||||
|
print "getting page Nr. $ta2 $ ta1\n";
|
||||||
|
$select=sprintf("\x55%c%c%c%c%c%c%c%c\xA5%c%c",
|
||||||
|
@owx_ROM_ID,$ta1,$ta2);
|
||||||
|
#-- reset the bus
|
||||||
|
OWX_Reset($master);
|
||||||
|
#-- read the data
|
||||||
|
$res=OWX_Block($master,$select);
|
||||||
|
if( $res eq 0 ){
|
||||||
|
return "OWX: Device $owx_dev not accessible in reading $page page";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
print "Have received ".length($res)." bytes\n";
|
||||||
|
|
||||||
|
#-- get 32 bytes
|
||||||
|
$select="";
|
||||||
|
for( $i=0;$i<42;$i++){
|
||||||
|
$select .= "\xFF";
|
||||||
|
}
|
||||||
|
#-- read the data
|
||||||
|
$res=OWX_Block($master,$select);
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
print "Have received ".length($res)." bytes\n";
|
||||||
|
|
||||||
|
#-- get 10 bytes
|
||||||
|
$select="";
|
||||||
|
for( $i=0;$i<10;$i++){
|
||||||
|
$select .= "\xFF";
|
||||||
|
}
|
||||||
|
#-- read the data
|
||||||
|
$res=OWX_Block($master,$select);
|
||||||
|
|
||||||
|
#-- reset the bus
|
||||||
|
OWX_Reset($master);
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
print "Have received ".length($res)." bytes\n";
|
||||||
|
@data=split(//,$res);
|
||||||
|
if ( ($data[4] | $data[5] | $data[6] | $data[7]) ne "\x00" ){
|
||||||
|
return "OWXCOUNT: Device $owx_dev returns invalid data";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- for now ignore memory and only use counter
|
||||||
|
|
||||||
|
my $value = ord($data[3])*4096 + ord($data[2])*256 +ord($data[1])*16 + ord($data[0]);
|
||||||
|
print "Value received = $value\n";
|
||||||
|
return undef
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWXCOUNT_SetPage - Set one memory page of device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# page = "alarm" or "status"
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWXCOUNT_SetPage($$) {
|
||||||
|
|
||||||
|
my ($hash,$page) = @_;
|
||||||
|
|
||||||
|
my ($select, $res, $res2, $res3, @data);
|
||||||
|
|
||||||
|
#-- ID of the device
|
||||||
|
my $owx_dev = $hash->{ROM_ID};
|
||||||
|
my $owx_rnf = substr($owx_dev,3,12);
|
||||||
|
my $owx_f = substr($owx_dev,0,2);
|
||||||
|
|
||||||
|
#-- hash of the busmaster
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
|
||||||
|
my ($i,$j,$k);
|
||||||
|
|
||||||
|
#-- 8 byte 1-Wire device address
|
||||||
|
my @owx_ROM_ID =(0,0,0,0 ,0,0,0,0);
|
||||||
|
#-- from search string to byte id
|
||||||
|
my $devs=$owx_dev;
|
||||||
|
$devs=~s/\.//g;
|
||||||
|
for($i=0;$i<8;$i++){
|
||||||
|
$owx_ROM_ID[$i]=hex(substr($devs,2*$i,2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#=============== set the alarm values ===============================
|
||||||
|
if ( $page eq "test" ) {
|
||||||
|
#-- issue the match ROM command \x55 and the set alarm page command
|
||||||
|
# \x55\x10\x00 reading 8 data bytes and 2 CRC bytes
|
||||||
|
$select=sprintf("\x55%c%c%c%c%c%c%c%c\x55\x10\x00",
|
||||||
|
@owx_ROM_ID);
|
||||||
|
|
||||||
|
#=============== wrong page write attempt ===============================
|
||||||
|
} else {
|
||||||
|
return "OWXCOUNT: Wrong memory page write attempt";
|
||||||
|
}
|
||||||
|
|
||||||
|
OWX_Reset($master);
|
||||||
|
$res=OWX_Block($master,$select);
|
||||||
|
|
||||||
|
#-- process results
|
||||||
|
if( $res eq 0 ){
|
||||||
|
return "OWXCOUNT: Device $owx_dev not accessible for writing";
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -12,7 +12,7 @@
|
|||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 1.10 - March, 2012
|
# Version 1.11 - March, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#
|
#
|
||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
#
|
#
|
||||||
# Version 1.10 - March, 2012
|
# Version 1.11 - March, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
@ -163,13 +163,17 @@ sub OWLCD_Define ($$) {
|
|||||||
|
|
||||||
#-- Initialization reading according to interface type
|
#-- Initialization reading according to interface type
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
#-- OWX interface
|
||||||
OWXLCD_InitializeDevice($hash);
|
if( $interface eq "OWX" ){
|
||||||
#-- set backlight on
|
OWXLCD_InitializeDevice($hash);
|
||||||
OWXLCD_SetFunction($hash,"bklon",0);
|
#-- set backlight on
|
||||||
#-- erase all icons
|
OWXLCD_SetFunction($hash,"bklon",0);
|
||||||
OWXLCD_SetIcon($hash,0,0);
|
#-- erase all icons
|
||||||
|
OWXLCD_SetIcon($hash,0,0);
|
||||||
|
#-- Unknown interface
|
||||||
|
}else{
|
||||||
|
return "OWLCD: Wrong IODev type $interface";
|
||||||
|
}
|
||||||
$hash->{STATE} = "Initialized";
|
$hash->{STATE} = "Initialized";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# OWTEMP.pm
|
# OWTEMP.pm
|
||||||
#
|
#
|
||||||
# FHEM module to commmunicate with 1-Wire temperature sensors
|
# FHEM module to commmunicate with 1-Wire temperature sensors DS1820, DS18S20, DS18B20, DS1822
|
||||||
#
|
#
|
||||||
# Attention: This module works as a replacement for the standard 21_OWTEMP.pm,
|
# Attention: This module works as a replacement for the standard 21_OWTEMP.pm,
|
||||||
# therefore may communicate with the 1-Wire File System OWFS,
|
# therefore may communicate with the 1-Wire File System OWFS,
|
||||||
@ -16,7 +16,7 @@
|
|||||||
# Prof. Dr. Peter A. Henning, 2012
|
# Prof. Dr. Peter A. Henning, 2012
|
||||||
# Martin Fischer, 2011
|
# Martin Fischer, 2011
|
||||||
#
|
#
|
||||||
# Version 1.10 - March, 2012
|
# Version 1.11 - March, 2012
|
||||||
#
|
#
|
||||||
# Setup bus device in fhem.cfg as
|
# Setup bus device in fhem.cfg as
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user