############################################## # $Id$ ############################################## package main; 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"; }; }; }; use Device::Firmata::Constants qw/ :all /; ##################################### sub FRM_I2C_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "FRM_Client_Define"; $hash->{InitFn} = "FRM_I2C_Init"; $hash->{UndefFn} = "FRM_Client_Undef"; $hash->{AttrFn} = "FRM_I2C_Attr"; $hash->{AttrList} = "IODev $main::readingFnAttributes"; main::LoadModule("FRM"); } sub FRM_I2C_Init($) { my ($hash,$args) = @_; my $u = "wrong syntax: define FRM_I2C address register numbytes"; return $u if(int(@$args) < 3); $hash->{"i2c-address"} = @$args[0]; $hash->{"i2c-register"} = @$args[1]; $hash->{"i2c-bytestoread"} = @$args[2]; eval { FRM_Client_AssignIOPort($hash); FRM_Client_FirmataDevice($hash)->i2c_read(@$args[0],@$args[1],@$args[2]); }; if ($@) { $@ =~ /^(.*)( at.*FHEM.*)$/; $hash->{STATE} = "error initializing: ".$1; return "error initializing '".$hash->{NAME}."': ".$1; } return "error calling i2c_read: ".$@ if ($@); if (! (defined AttrVal($hash->{NAME},"event-min-interval",undef))) { $main::attr{$hash->{NAME}}{"event-min-interval"} = 5; } return undef; } sub FRM_I2C_Attr($$$$) { my ($command,$name,$attribute,$value) = @_; my $hash = $main::defs{$name}; eval { if ($command eq "set") { ARGUMENT_HANDLER: { $attribute eq "IODev" and do { if ($main::init_done and (!defined ($hash->{IODev}) or $hash->{IODev}->{NAME} ne $value)) { FRM_Client_AssignIOPort($hash,$value); FRM_Init_Client($hash) if (defined ($hash->{IODev})); } last; }; } } }; if ($@) { $@ =~ /^(.*)( at.*FHEM.*)$/; $hash->{STATE} = "error setting $attribute to $value: ".$1; return "cannot $command attribute $attribute to $value for $name: ".$1; } } 1; =pod =begin html

FRM_I2C


=end html =cut