From 963c873024a447577a667c5d294ff6d0b789901f Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Mon, 14 Apr 2014 22:20:37 +0000 Subject: [PATCH] OWX_ASYNC: fix commandref, add attribute interval git-svn-id: https://svn.fhem.de/fhem/trunk@5526 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_OWX_ASYNC.pm | 125 +++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 49 deletions(-) diff --git a/fhem/FHEM/00_OWX_ASYNC.pm b/fhem/FHEM/00_OWX_ASYNC.pm index d5e677463..fac19a6f0 100644 --- a/fhem/FHEM/00_OWX_ASYNC.pm +++ b/fhem/FHEM/00_OWX_ASYNC.pm @@ -1,33 +1,29 @@ ######################################################################################## # -# OWX.pm +# OWX_ASYNC.pm # # FHEM module to commmunicate with 1-Wire bus devices -# * via an active DS2480/DS2482/DS2490/DS9097U bus master interface attached to an USB port -# * via a passive DS9097 interface attached to an USB port -# * via a network-attached CUNO -# * via a COC attached to a Raspberry Pi -# * via an Arduino running OneWireFirmata attached to USB +# * via an active DS2480 bus master interface attached to an USB port +# * via an Arduino running CopnfigurableFirmata attached to USB +# * via an Arduino running CopnfigurableFirmata connecting to FHEM via Ethernet # -# Prof. Dr. Peter A. Henning # Norbert Truchsess +# Prof. Dr. Peter A. Henning # -# $Id: 00_OWX.pm 2013-03 - pahenning $ +# $Id: 00_OWX_ASYNC.pm 2013-04 - ntruchsess $ # ######################################################################################## # -# define OWX for USB interfaces or -# define OWX for a CUNO or COC interface -# define OWX for a Arduino/Firmata (10_FRM.pm) interface +# define OWX_ASYNC for USB interfaces or +# define OWX_ASYNC for a Arduino/Firmata (10_FRM.pm) interface # # where may be replaced by any name string # is a serial (USB) device -# is a CUNO or COC device # is an Arduino pin # # get alarms => find alarmed 1-Wire devices (not with CUNO) # get devices => find all 1-Wire devices -# get version => OWX version number +# get version => OWX_ASYNC version number # # set interval => set period for temperature conversion and alarm testing # set followAlarms on/off => determine whether an alarm is followed by a search for @@ -38,6 +34,8 @@ # and to make an alarm check # 0 if not # +# attr interval => set period for temperature conversion and alarm testing +# ######################################################################################## # # This programm is free software; you can redistribute it and/or modify @@ -86,7 +84,7 @@ use Time::HiRes qw(gettimeofday); require "$main::attr{global}{modpath}/FHEM/DevIo.pm"; sub Log3($$$); -use vars qw{%owg_family %gets %sets $owx_version $owx_debug}; +use vars qw{%owg_family %gets %sets $owx_async_version $owx_async_debug}; # 1-Wire devices # http://owfs.sourceforge.net/family.html %owg_family = ( @@ -127,9 +125,9 @@ my %attrs = ( ); #-- some globals needed for the 1-Wire module -$owx_version=4.6; +$owx_async_version=5.0; #-- Debugging 0,1,2,3 -$owx_debug=0; +$owx_async_debug=0; ######################################################################################## # @@ -153,11 +151,12 @@ sub OWX_ASYNC_Initialize ($) { $hash->{UndefFn} = "OWX_ASYNC_Undef"; $hash->{GetFn} = "OWX_ASYNC_Get"; $hash->{SetFn} = "OWX_ASYNC_Set"; + $hash->{AttrFn} = "OWX_ASYNC_Attr"; $hash->{NotifyFn} = "OWX_ASYNC_Notify"; $hash->{ReadFn} = "OWX_ASYNC_Poll"; $hash->{ReadyFn} = "OWX_ASYNC_Ready"; $hash->{InitFn} = "OWX_ASYNC_Init"; - $hash->{AttrList} = "dokick:0,1 async:0,1 IODev timeout"; + $hash->{AttrList} = "dokick:0,1 interval IODev timeout"; main::LoadModule("OWX"); } @@ -174,9 +173,9 @@ sub OWX_ASYNC_Define ($$) { my @a = split("[ \t][ \t]*", $def); #-- check syntax - return "OWX: Syntax error - must be define OWX ||" if(int(@a) < 3); + return "OWX: Syntax error - must be define OWX |" if(int(@a) < 3); - Log3 ($hash->{NAME},2,"OWX: Warning - Some parameter(s) ignored, must be define OWX ||") if( int(@a)>3 ); + Log3 ($hash->{NAME},2,"OWX: Warning - Some parameter(s) ignored, must be define OWX |") if( int(@a)>3 ); my $dev = $a[2]; $hash->{NOTIFYDEV} = "global"; @@ -219,6 +218,35 @@ sub OWX_ASYNC_Define ($$) { return undef; } +####################################################################################### +# +# OWTX_Attr - Set one attribute value for device +# +# Parameter hash = hash of device addressed +# a = argument array +# +######################################################################################## + +sub OWX_ASYNC_Attr(@) { + my ($do,$name,$key,$value) = @_; + + my $hash = $main::defs{$name}; + my $ret; + + if ( $do eq "set") { + ARGUMENT_HANDLER: { + $key eq "interval" and do { + $hash->{interval} = $value; + if ($main::init_done) { + OWX_ASYNC_Kick($hash); + } + last; + }; + } + } + return $ret; +} + sub OWX_ASYNC_Notify { my ($hash,$dev) = @_; my $name = $hash->{NAME}; @@ -700,7 +728,7 @@ sub OWX_ASYNC_Get($@) { return $res } elsif( $a[1] eq "version") { - return $owx_version; + return $owx_async_version; } else { return "OWX: Get with unknown argument $a[1], choose one of ". @@ -753,7 +781,7 @@ sub OWX_ASYNC_Init ($) { InternalTimer(gettimeofday()+10, "OWX_ASYNC_Discover", $hash,0); #-- Default settings - $hash->{interval} = 300; # kick every 5 minutes + $hash->{interval} = AttrVal($hash->{NAME},"interval",300); # kick every 5 minutes $hash->{followAlarms} = "off"; $hash->{ALARMED} = "no"; @@ -1020,35 +1048,34 @@ sub OWX_ASYNC_AfterExecute($$$$$$$$) { =pod =begin html - -

OWX

+ +

OWX_ASYNC

FHEM module to commmunicate with 1-Wire bus devices

    -
  • via an active DS2480/DS2482/DS2490/DS9097U bus master interface attached to an USB - port or
  • -
  • via a passive DS9097 interface attached to an USB port or
  • -
  • via a network-attached CUNO or through a COC on the RaspBerry Pi
  • -
  • via an Arduino running OneWireFirmata attached to USB
  • -
Internally these interfaces are vastly different, read the corresponding Wiki pages +
  • via an active DS2480 bus master interface attached to an USB port or
  • +
  • via an Arduino running ConfigurableFirmata attached to USB
  • +
  • via an Arduino running ConfigurableFirmata connecting to FHEM via Ethernet
  • + +

    Internally these interfaces are vastly different, read the corresponding Wiki pages

    +

    OWX_ASYNC does pretty much the same job as OWX does, but using + an asynchronous mode of communication



    Example


    - define OWio1 OWX /dev/ttyUSB1 + define OWio1 OWX_ASYNC /dev/ttyUSB1
    - define OWio2 OWX COC -
    - define OWio3 OWX 10 + define OWio3 OWX_ASYNC 10


    - +

    Define

    - define <name> OWX <serial-device> or
    - define <name> OWX <cuno/coc-device> or
    - define <name> OWX <arduino-pin> + define <name> OWX_ASYNC <serial-device> or
    + define <name> OWX_ASYNC <cuno/coc-device> or
    + define <name> OWX_ASYNC <arduino-pin>

    Define a 1-Wire interface to communicate with a 1-Wire bus.

    @@ -1065,30 +1092,30 @@ sub OWX_ASYNC_AfterExecute($$$$$$$$) { use IODev attribute to select which FRM device to use.
    - +

    Set


    - +

    Get

      -
    • +
    • get <name> alarms

      performs an "alarm search" for devices on the 1-Wire bus and, if found, generates an event in the log (not with CUNO).
    • -
    • +
    • get <name> devices

      redicovers all devices on the 1-Wire bus. If a device found has a previous definition, this is automatically used. If a device is found but has no @@ -1096,14 +1123,14 @@ sub OWX_ASYNC_AfterExecute($$$$$$$$) { autodeleted.

    - +

    Attributes