diff --git a/fhem/FHEM/10_FRM.pm b/fhem/FHEM/10_FRM.pm index 5ac6c46d3..67859627e 100755 --- a/fhem/FHEM/10_FRM.pm +++ b/fhem/FHEM/10_FRM.pm @@ -75,6 +75,7 @@ sub FRM_Define($$) { $hash->{DeviceName} = $dev; my $ret = DevIo_OpenDev($hash, 0, "FRM_DoInit"); + return $ret if (defined $ret and $ret eq ""); $hash->{STATE}="Initialized"; return $ret; } diff --git a/fhem/FHEM/20_FRM_LCD.pm b/fhem/FHEM/20_FRM_LCD.pm index f95699e61..3bafc42b2 100755 --- a/fhem/FHEM/20_FRM_LCD.pm +++ b/fhem/FHEM/20_FRM_LCD.pm @@ -32,7 +32,7 @@ FRM_LCD_Initialize($) $hash->{AttrFn} = "FRM_LCD_Attr"; $hash->{StateFn} = "FRM_LCD_State"; - $hash->{AttrList} = "IODev model backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; + $hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev model backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; # autoScroll:on,off direction:leftToRight,rightToLeft do not work reliably } @@ -52,21 +52,26 @@ FRM_LCD_Init($) return "no IODev set" unless defined $hash->{IODev}; return "no FirmataDevice assigned to ".$hash->{IODev}->{NAME} unless defined $hash->{IODev}->{FirmataDevice}; + my $name = $hash->{NAME}; if (($hash->{type} eq "i2c") and defined $hash->{address}) { require LiquidCrystal_I2C; my $lcd = LiquidCrystal_I2C->new($hash->{address},$hash->{sizex},$hash->{sizey}); $lcd->attach($hash->{IODev}->{FirmataDevice}); $lcd->init(); $hash->{lcd} = $lcd; - my $name = $hash->{NAME}; -# FRM_LCD_Apply_Attribute($name,"backlight"); + FRM_LCD_Apply_Attribute($name,"backLight"); # FRM_LCD_Apply_Attribute($name,"autoscroll"); # FRM_LCD_Apply_Attribute($name,"direction"); -# FRM_LCD_Apply_Attribute($name,"blink"); - if (! (defined AttrVal($name,"stateFormat",undef))) { - $main::attr{$name}{"stateFormat"} = "text"; - } + FRM_LCD_Apply_Attribute($name,"blink"); } + if (! (defined AttrVal($name,"stateFormat",undef))) { + $main::attr{$name}{"stateFormat"} = "text"; + } + my $value = ReadingsVal($name,"text",undef); + if (defined $value and AttrVal($hash->{NAME},"restoreOnReconnect","on") eq "on") { + FRM_LCD_Set($hash,$name,"text",$value); + } + return undef; } @@ -118,8 +123,6 @@ sub FRM_LCD_Apply_Attribute { last; }; } - } else { - main::Log (3, "no lcd found"); } } @@ -131,6 +134,7 @@ sub FRM_LCD_Set(@) { return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets) if(!defined($sets{$command})); my $lcd = $hash->{lcd}; + return unless defined $lcd; COMMAND_HANDLER: { $command eq "text" and do { if (AttrVal($hash->{NAME},"autoClear","on") eq "on") { @@ -195,7 +199,9 @@ sub FRM_LCD_State($$$$) STATEHANDLER: { $sname eq "text" and do { - FRM_LCD_Set($hash,$hash->{NAME},$sname,$sval); + if (AttrVal($hash->{NAME},"restoreOnStartup","on") eq "on") { + FRM_LCD_Set($hash,$hash->{NAME},$sname,$sval); + } last; } } @@ -212,39 +218,48 @@ FRM_LCD_Undef($$) =pod =begin html - -

FRM_I2C

+ +

FRM_LCD