mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-25 22:09:21 +00:00
I2C_LCD: add attribute pinMapping (only parser, not realy working yet)
git-svn-id: https://svn.fhem.de/fhem/trunk@5406 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b9efc69e05
commit
ca0fd12c47
@ -30,6 +30,19 @@ my %sets = (
|
|||||||
my %gets = (
|
my %gets = (
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my %mapping = (
|
||||||
|
'P0' => 'RS',
|
||||||
|
'P1' => 'RW',
|
||||||
|
'P2' => 'E',
|
||||||
|
'P3' => 'LED',
|
||||||
|
'P4' => 'D4',
|
||||||
|
'P5' => 'D5',
|
||||||
|
'P6' => 'D6',
|
||||||
|
'P7' => 'D7',
|
||||||
|
);
|
||||||
|
|
||||||
|
my @LEDPINS = sort values %mapping;
|
||||||
|
|
||||||
sub
|
sub
|
||||||
I2C_LCD_Initialize($)
|
I2C_LCD_Initialize($)
|
||||||
{
|
{
|
||||||
@ -41,7 +54,7 @@ I2C_LCD_Initialize($)
|
|||||||
$hash->{AttrFn} = "I2C_LCD_Attr";
|
$hash->{AttrFn} = "I2C_LCD_Attr";
|
||||||
$hash->{StateFn} = "I2C_LCD_State";
|
$hash->{StateFn} = "I2C_LCD_State";
|
||||||
|
|
||||||
$hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev model"
|
$hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev model pinMapping"
|
||||||
." backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off $main::readingFnAttributes";
|
." backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off $main::readingFnAttributes";
|
||||||
# autoScroll:on,off direction:leftToRight,rightToLeft do not work reliably
|
# autoScroll:on,off direction:leftToRight,rightToLeft do not work reliably
|
||||||
}
|
}
|
||||||
@ -60,6 +73,12 @@ I2C_LCD_Define($$)
|
|||||||
};
|
};
|
||||||
return I2C_LCD_Catch($@) if $@;
|
return I2C_LCD_Catch($@) if $@;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my @keyvalue = ();
|
||||||
|
while (my ($key, $value) = each %mapping) {
|
||||||
|
push @keyvalue,"$key=$value";
|
||||||
|
};
|
||||||
|
$main::attr{$a[0]}{"pinMapping"} = join (',',sort @keyvalue);;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +99,7 @@ I2C_LCD_Init($$)
|
|||||||
eval {
|
eval {
|
||||||
main::AssignIoPort($hash,AttrVal($hash->{NAME},"IODev",undef));
|
main::AssignIoPort($hash,AttrVal($hash->{NAME},"IODev",undef));
|
||||||
require LiquidCrystal_I2C;
|
require LiquidCrystal_I2C;
|
||||||
my $lcd = LiquidCrystal_I2C->new($hash->{I2C_Address},$hash->{sizex},$hash->{sizey});
|
my $lcd = LiquidCrystal_I2C->new($hash->{I2C_Address},$hash->{sizex},$hash->{sizey},\%mapping);
|
||||||
$lcd->attach(I2C_LCD_IO->new($hash));
|
$lcd->attach(I2C_LCD_IO->new($hash));
|
||||||
$lcd->init();
|
$lcd->init();
|
||||||
$hash->{lcd} = $lcd;
|
$hash->{lcd} = $lcd;
|
||||||
@ -119,8 +138,18 @@ I2C_LCD_Attr($$$$) {
|
|||||||
}
|
}
|
||||||
last;
|
last;
|
||||||
};
|
};
|
||||||
$main::attr{$name}{$attribute}=$value;
|
$attribute eq "pinMapping" and do {
|
||||||
I2C_LCD_Apply_Attribute($name,$attribute);
|
foreach my $keyvalue (split (/,/,$value)) {
|
||||||
|
my ($key,$value) = split (/=/,$keyvalue);
|
||||||
|
#Log3 ($name,5,"pinMapping, token: $key=$value, current mapping: $mapping{$key}");
|
||||||
|
die "unknown token $key in attribute pinMapping, valid tokens are ".join (',',keys %mapping) unless (defined $mapping{$key});
|
||||||
|
die "undefined or invalid value for token $key in attribute pinMapping, valid LED-Pins are ".join (',',@LEDPINS) unless $value and grep (/$value/,@LEDPINS);
|
||||||
|
$mapping{$key} = $value;
|
||||||
|
}
|
||||||
|
last;
|
||||||
|
};
|
||||||
|
$main::attr{$name}{$attribute}=$value;
|
||||||
|
I2C_LCD_Apply_Attribute($name,$attribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user