| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146 |
- ########################################################################################
- #
- # OWLCD.pm
- #
- # FHEM module to commmunicate with the 1-Wire LCD hardware
- #
- # Prof. Dr. Peter A. Henning
- #
- # $Id: 21_OWLCD.pm 11196 2016-04-06 18:56:28Z pahenning $
- #
- ########################################################################################
- #
- # define <name> OWLCD <ROM_ID> or FF.<ROM_ID>
- #
- # where <name> may be replaced by any name string
- #
- # <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
- # without Family ID, e.g. A2D90D000800
- #
- # get <name> id => FF.ROM_ID.CRC
- # get <name> present => 1 if device present, 0 if not
- # get <name> gpio => current state of the gpio pins (15 = all off, 0 = all on)
- # get <name> counter => four values (16 Bit) of the gpio counter
- # get <name> version => firmware version of the LCD adapter
- # get <name> memory <page> => get one of the internal memory pages 0..6
- # get <name> version => OWX version number
- #
- # set <name> alert red|yellow|beep|none => set one of the alert states (gpio pins)
- # set <name> icon <num> on|off|blink => set one of the icons 0..14
- # set <name> icon 15 0..6 => set icon no. 15 in one of its values
- # set <name> line <line> <string(s)> => set one of the display lines 0..3
- # set <name> memory <page> <string(s) => set one of the internal memory pages 0..6
- # set <name> gpio => state of the gpio pins 0..7
- # set <name> backlight on|off => set backlight on or off
- # set <name> lcd on|off => set LCD power on or off
- # set <name> reset => reset the display
- # set <name> test => display a test content
- #
- # attr <name> lcdgeometry => LCD geometry values are 0-32-64-96 or 0-64-20-84
- #
- # Careful: Not ASCII ! strange Codepage
- ########################################################################################
- #
- # 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;
- use vars qw{%attr %defs %modules $readingFnAttributes $init_done};
- use Time::HiRes qw(gettimeofday);
- 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 GPUtils qw(:all);
- use ProtoThreads;
- no warnings 'deprecated';
- sub Log3($$$);
- my $owx_version="6.01";
- #-- controller may be HD44780 or KS0073
- # these values can be changed by attribute for different display
- # geometries or memory maps
- my $lcdcontroller = "KS0073";
- my $lcdlines = 4;
- my $lcdchars = 20;
- my @lcdpage = (0,32,64,96);
- #-- declare variables
- my %gets = (
- "present" => "",
- "id" => "",
- "memory" => "",
- "gpio" => "",
- "counter" => "",
- "version" => ""
- #"register" => "",
- #"data" => ""
- );
- my %sets = (
- "icon" => "",
- "line" => "",
- "alert" => "",
- "memory" => "",
- "gpio" => "",
- "backlight" => "",
- "lcd" => "",
- "reset" => "",
- "test" => ""
- );
- my %updates = ();
-
- ########################################################################################
- #
- # The following subroutines are independent of the bus interface
- #
- # Prefix = OWLCD
- #
- ########################################################################################
- #
- # OWLCD_Initialize
- #
- # Parameter hash = hash of device addressed
- #
- ########################################################################################
- sub OWLCD_Initialize ($) {
- my ($hash) = @_;
- $hash->{DefFn} = "OWLCD_Define";
- $hash->{UndefFn} = "OWLCD_Undef";
- $hash->{GetFn} = "OWLCD_Get";
- $hash->{SetFn} = "OWLCD_Set";
- $hash->{NotifyFn} = "OWLCD_Notify";
- $hash->{InitFn} = "OWLCD_Init";
- $hash->{AttrFn} = "OWLCD_Attr";
- my $attlist = "IODev do_not_notify:0,1 showtime:0,1 ".
- "lcdgeometry:0-32-64-96,0-64-20-84 lcdcontroller:KS0073,HD44780 ".
- $readingFnAttributes;
- $hash->{AttrList} = $attlist;
- #-- make sure OWX is loaded so OWX_CRC is available if running with OWServer
- main::LoadModule("OWX");
- }
- #########################################################################################
- #
- # OWLCD_Define - Implements DefFn function
- #
- # Parameter hash = hash of device addressed, def = definition string
- #
- #########################################################################################
- sub OWLCD_Define ($$) {
- my ($hash, $def) = @_;
-
- #-- define <name> OWLCD <ROM_ID>
- my @a = split("[ \t][ \t]*", $def);
-
- my ($name,$fam,$id,$crc,$ret);
-
- #-- default
- $name = $a[0];
- $ret = "";
- #-- check syntax
- return "OWLCD: Wrong syntax, must be define <name> OWLCD <id>"
- if(int(@a) !=3 );
-
- #-- check id
- if( $a[2] =~ m/^[0-9|a-f|A-F]{12}$/ ) {
- $id = $a[2];
- } elsif( $a[2] =~ m/^FF\.[0-9|a-f|A-F]{12}$/ ) {
- $id = substr($a[2],3);
- } else {
- return "OWLCD: $a[0] ID $a[2] invalid, specify a 12 digit or 2.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("FF.".$id."00")) : "00";
-
- #-- Define device internals
- $hash->{ROM_ID} = "FF.".$id.$crc;
- $hash->{OW_ID} = $id;
- $hash->{OW_FAMILY} = "FF";
- $hash->{PRESENT} = 0;
-
- #-- Couple to I/O device
- AssignIoPort($hash);
- if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
- return "OWLCD: Warning, no 1-Wire I/O device found for $name.";
- } else {
- $hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
- }
- $modules{OWLCD}{defptr}{$id} = $hash;
-
- $hash->{STATE} = "Defined";
- Log3 $name,3, "OWLCD: Device $name defined.";
-
- $hash->{NOTIFYDEV} = "global";
-
- if ($main::init_done) {
- return OWLCD_Init($hash);
- }
- return undef;
- }
- ########################################################################################
- #
- # OWLCD_Notify - Implements Notify function
- #
- # Parameter hash = hash of device addressed
- #
- ########################################################################################
- sub OWLCD_Notify ($$) {
- my ($hash,$dev) = @_;
- if( grep(m/^(INITIALIZED|REREADCFG)$/, @{$dev->{CHANGED}}) ) {
- OWLCD_Init($hash);
- } elsif( grep(m/^SAVE$/, @{$dev->{CHANGED}}) ) {
- }
- }
- ########################################################################################
- #
- # OWLCD_Init - Implements Init function
- #
- # Parameter hash = hash of device addressed
- #
- ########################################################################################
- sub OWLCD_Init($) {
- my ($hash) = @_;
- #-- Initialization reading according to interface type
- my $interface= $hash->{IODev}->{TYPE};
- #-- OWX interface
- if( $interface eq "OWX" ){
- OWXLCD_InitializeDevice($hash);
- #-- set backlight on
- OWXLCD_SetFunction($hash,"bklon",0);
- #-- erase all icons
- OWXLCD_SetIcon($hash,0,0);
- #-- erase alarm state
- OWXLCD_SetFunction($hash,"gpio",15);
- } elsif ( $interface eq "OWX_ASYNC" ) {
- eval {
- OWXLCD_InitializeDevice($hash);
- #-- set backlight on
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetFunction($hash,"bklon",0));
- #-- erase all icons
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetIcon($hash,0,0));
- #-- erase alarm state
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_SetFunction($hash,"gpio",15));
- };
- return GP_Catch($@) if $@;
- #-- Unknown interface
- }else{
- return "OWLCD: Wrong IODev type $interface";
- }
- $hash->{STATE} = "Initialized";
- return undef;
- }
- #######################################################################################
- #
- # OWLCD_Attr - Set one attribute value for device
- #
- # Parameter hash = hash of device addressed
- # a = argument array
- #
- ########################################################################################
- sub OWLCD_Attr(@) {
- my ($do,$name,$key,$value) = @_;
-
- my $hash = $defs{$name};
- my $ret;
-
- if ( $do eq "set") {
- ARGUMENT_HANDLER: {
- $key eq "IODev" and do {
- AssignIoPort($hash,$value);
- if( defined($hash->{IODev}) ) {
- $hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
- if ($main::init_done) {
- return OWLCD_Init($hash);
- }
- }
- last;
- };
- $key eq "lcdgeometry" and do {
- if( $value eq "0-32-64-96" ){
- @lcdpage = (0,32,64,96);
- }elsif( $value eq "0-64-20-84" ){
- @lcdpage = (0,64,20,84);
- }
- last;
- };
- $key eq "lcdcontroller" and do {
- if( $value eq "KS0073," ){
- $lcdcontroller = "KS0073";
- }elsif( $value eq "HD44780" ){
- $lcdcontroller = "HD44780";
- }
- last;
- };
- };
- #} elsif ( $do eq "del" ) {
- # ARGUMENT_HANDLER: {
- # #-- empty so far
- # }
- }
- return $ret;
- }
- ########################################################################################
- #
- # OWLCD_Get - Implements GetFn function
- #
- # Parameter hash = hash of device addressed, a = argument array
- #
- ########################################################################################
- sub OWLCD_Get($@) {
- my ($hash, @a) = @_;
-
- my $reading = $a[1];
- my $name = $hash->{NAME};
- my $model = $hash->{OW_MODEL};
- my $master = $hash->{IODev};
- my $value = undef;
- my $ret = "";
- my $offset;
- my $factor;
- #-- check syntax
- return "OWLCD: Get argument is missing @a"
- if(int(@a) < 2);
-
- #-- check argument
- return "OWLCD: 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 "$name.id => $value";
- }
- #-- get present
- if($a[1] eq "present") {
- #-- asynchronous mode
- if( $hash->{ASYNC} ){
- eval {
- OWX_ASYNC_RunToCompletion($hash,OWX_ASYNC_PT_Verify($hash));
- };
- return GP_Catch($@) if $@;
- return "$name.present => ".ReadingsVal($name,"present","unknown");
- } else {
- $value = OWX_Verify($master,$hash->{ROM_ID});
- }
- $hash->{PRESENT} = $value;
- return "$name.present => $value";
- }
-
- #-- get gpio states
- if($a[1] eq "gpio") {
- if ($hash->{ASYNC}) {
- eval {
- $ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"gpio"));
- };
- $ret = GP_Catch($@) if $@;
- return $ret if $ret;
- return "$name.gpio => ".main::ReadingsVal($hash->{NAME},"gpio","");
- } else {
- $value = OWXLCD_Get($hash,"gpio");
- #-- process result
- if( $master->{ASYNCHRONOUS} ){
- return "OWLCD: $name getting gpio, please wait for completion";
- }else{
- return "$name.gpio => $value";
- }
- }
- }
-
- #-- get gpio counters
- if($a[1] eq "counter") {
- if ($hash->{ASYNC}) {
- eval {
- $ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"counter"));
- };
- $ret = GP_Catch($@) if $@;
- return $ret if $ret;
- return "$name.counter => ".main::ReadingsVal($hash->{NAME},"counter","");
- } else {
- $value = OWXLCD_Get($hash,"counter");
- #-- process result
- if( $master->{ASYNCHRONOUS} ){
- return "OWLCD: $name getting counter, please wait for completion";
- }else{
- return "$name.counter => $value";
- }
- }
- }
-
- #-- get version
- if($a[1] eq "version") {
- if ($hash->{ASYNC}) {
- eval {
- $ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_Get($hash,"version"));
- };
- $ret = GP_Catch($@) if $@;
- return $ret if $ret;
- return "$name.gpio => ".main::ReadingsVal($hash->{NAME},"version","");
- } else {
- $value = OWXLCD_Get($hash,"version");
- #-- process result
- if( $master->{ASYNCHRONOUS} ){
- return "OWLCD: $name getting version, please wait for completion";
- }else{
- return "$name.version => $owx_version (LCD firmware $value)";
- }
- }
- }
-
- #-- get EEPROM content
- if($a[1] eq "memory") {
- my $page = (defined $a[2] and $a[2] =~ m/\d/) ? int($a[2]) : 0;
- if ($hash->{ASYNC}) {
- eval {
- $ret = OWX_ASYNC_RunToCompletion($hash,OWXLCD_PT_GetMemory($hash,$page));
- };
- $ret = GP_Catch($@) if $@;
- return $ret if $ret;
- return "$name $reading $page => ".main::ReadingsVal($hash->{NAME},"memory$page","");
- } else {
- $value = OWXLCD_GetMemory($hash,$page);
- #-- process result
- if( $master->{ASYNCHRONOUS} ){
- return "OWLCD: $name memory page $page, please wait for completion";
- }else{
- return "$name $reading $page => $value";
- }
- }
- }
- }
- #######################################################################################
- #
- # OWLCD_Set - Set one value for device
- #
- # Parameter hash = hash of device addressed
- # a = argument array
- #
- ########################################################################################
- sub OWLCD_Set($@) {
- my ($hash, @a) = @_;
-
- my $key = $a[1];
- my $value = $a[2];
- my ($line,$icon,$i);
-
- #-- for the selector: which values are possible
- return join(" ", keys %sets)
- if ( (@a == 2) && !(($key eq "reset") || ($key eq "test")) );
-
- #-- check argument
- if( !defined($sets{$a[1]}) ){
- return "OWLCD: Set with unknown argument $a[1]";
- }
-
- #-- check syntax for setting line
- if( $key eq "line" ){
- return "OWLCD: Set needs one or two parameters when setting line value: <#line> <string>"
- if( int(@a)<3 );
- $line = ($a[2] =~ m/\d/) ? $a[2] : 0;
- $value = $a[3];
- if( defined($value) ){
- for( $i=4; $i< int(@a); $i++){
- $value .= " ".$a[$i];
- }
- }else{
- $value="";
- }
- #-- check syntax for setting memory
- } elsif( $key eq "memory" ){
- return "OWLCD: Set needs two parameters when setting memory page: <#page> <string>"
- if( int(@a)<4 );
- $line = ($a[2] =~ m/\d/) ? int($a[2]) : 0;
- $value = $a[3];
- for( $i=4; $i< int(@a); $i++){
- $value .= " ".$a[$i];
- }
- #-- check syntax for setting alert
- } elsif( $key eq "alert" ){
- return "OWLCD: Set needs a parameter when setting alert: <type>/none/off"
- if( int(@a)<3 );
- #-- check syntax for setting icon
- } elsif ( $key eq "icon" ){
- if( ($a[2] ne "0") && ($a[2] ne "none") ){
- return "OWLCD: Set needs two parameters when setting icon value: <#icon> on/off/blink (resp. 0..5/off/blink for #16)"
- if( (int(@a)!=4) );
- $icon = ($a[2] =~ m/\d\d?/) ? $a[2] : 0;
- $value = $a[3];
- } else {
- return "OWLCD: Set needs only one parameter when resetting icons"
- if( (int(@a)!=3) );
- $icon = 0;
- $value = "OFF";
- }
- #-- check syntax for reset and test
- } elsif ( ($key eq "reset") || ($key eq "test") ){
- return "OWLCD: Set needs no parameters when setting $key value"
- if( int(@a)!=2 );
- #-- other syntax
- } else {
- return "OWLCD: Set needs one parameter when setting $key value"
- if( int(@a)!=3 );
- }
-
- #-- define vars
- my $name = $hash->{NAME};
- my $model = $hash->{OW_MODEL};
-
- #-- set gpio ports from all off = to all on = 7
- if($key eq "gpio") {
- #-- check value and write to device
- return "OWLCD: Set with wrong value for gpio port, must be 0 <= gpio <= 7"
- if( ! ((int($value) >= 0) && (int($value) <= 7)) );
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", int($value)) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash, "gpio", int($value));
- }
- return undef;
- }
-
- #-- set LCD ON or OFF
- if($key eq "lcd") {
- #-- check value and write to device
- if( uc($value) eq "ON"){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "lcdon", 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash, "lcdon", 0);
- }
- }elsif( uc($value) eq "OFF" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "lcdoff", 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash, "lcdoff", 0);
- }
- } else {
- return "OWLCD: Set with wrong value for lcd, must be on/off"
- }
- return undef;
- }
-
- #-- set LCD Backlight ON or OFF
- if($key eq "backlight") {
- #-- check value and write to device
- if( uc($value) eq "ON"){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "bklon", 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash, "bklon", 0);
- }
- }elsif( uc($value) eq "OFF" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "bkloff", 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash, "bkloff", 0);
- }
- } else {
- return "OWLCD: Set with wrong value for backlight, must be on/off"
- }
- return undef;
- }
-
- #-- reset
- if($key eq "reset") {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "reset", 0) );
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 0, 0) );
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 15) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash,"reset",0);
- OWXLCD_SetIcon($hash,0,0);
- OWXLCD_SetFunction($hash,"gpio",15);
- }
- return undef;
- }
-
- #-- set icon
- if($key eq "icon") {
- return "OWLCD: Wrong icon type, choose 0..16"
- if( ( 0 > $icon ) || ($icon > 16) );
- #-- check value and write to device
- if( $icon == 16 ){
- if( uc($value) eq "OFF" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, 16, 0);
- }
- }elsif( uc($value) eq "BLINK" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, 6) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, 16, 6);
- }
- }elsif( ((int($value) > 0) && (int($value) < 6)) ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, 16, int($value)) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, 16, int($value));
- }
- } else {
- return "OWLCD: Set with wrong value for icon #16, must be 0..5/off/blink"
- }
- }else{
- if( uc($value) eq "OFF"){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, $icon, 0) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, $icon, 0);
- }
- }elsif( uc($value) eq "ON" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetIcon($hash, $icon, 1) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, $icon, 1);
- }
- }elsif( uc($value) eq "BLINK" ){
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, &OWXLCD_PT_SetIcon($hash, $icon, 2) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetIcon($hash, $icon, 2);
- }
- } else {
- return "OWLCD: Set with wrong value for icon $icon, must be on/off/blink"
- }
- }
- return undef;
- }
-
- #-- set a single LCD line
- if($key eq "line") {
- $value = OWXLCD_Trans($value);
- return "OWLCD: Wrong line number, choose 0..".$lcdlines
- if( ( 0 > $line ) || ($line > ($lcdlines-1)) );
- return "OWLCD: Wrong line length, must be <= ".$lcdchars
- if( length($value) > $lcdchars );
- #-- check value and write to device
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash, $line, $value) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetLine($hash,$line,$value);
- }
- return undef;
- }
-
- #-- set memory page 0..6
- if($key eq "memory") {
- return "OWLCD: Wrong page number, choose 0..6"
- if( (0 > $line) || ($line > 6) );
- return "OWLCD: Wrong line length, must be <=16 "
- if( length($value) > 16 );
- #-- write to device
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetMemory($hash, $line, $value) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetMemory($hash,$line,$value);
- }
- return undef;
- }
-
- #-- set alert
- if($key eq "alert") {
- if(lc($value) eq "beep") {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 14) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash,"gpio",14);
- }
- return undef;
- }elsif(lc($value) eq "red") {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 13) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash,"gpio",13);
- }
- return undef;
- }elsif(lc($value) eq "yellow") {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 11) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash,"gpio",11);
- }
- return undef;
- }elsif( (lc($value) eq "off") || (lc($value) eq "none") ) {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetFunction($hash, "gpio", 15) );
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetFunction($hash,"gpio",15);
- }
- return undef;
- }else{
- return "OWLCD: Set with wrong value for alert type, must be beep/red/yellow/off";
- }
- }
-
- #-- start test
- if($key eq "test") {
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,0,"Hallo Welt"));
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,1,"Mary had a big lamb"));
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,2,"Solar 4.322 kW "));
- OWX_ASYNC_Schedule( $hash, OWXLCD_PT_SetLine($hash,3,"\x5B\x5C\x5E\x7B\x7C\x7E\xBE"));
- };
- return GP_Catch($@) if $@;
- } else {
- OWXLCD_SetLine($hash,0,"Hallo Welt");
- OWXLCD_SetLine($hash,1,"Mary had a big lamb");
- OWXLCD_SetLine($hash,2,"Solar 4.322 kW ");
- OWXLCD_SetLine($hash,3,"\x5B\x5C\x5E\x7B\x7C\x7E\xBE");
- }
- return undef;
- }
- }
- ########################################################################################
- #
- # OWLCD_Undef - Implements UndefFn function
- #
- # Parameter hash = hash of device addressed
- #
- ########################################################################################
- sub OWLCD_Undef ($) {
- my ($hash) = @_;
- delete($modules{OWLCD}{defptr}{$hash->{OW_ID}});
- RemoveInternalTimer($hash);
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_InitializeDevice - initialize the display
- #
- # Parameter hash = hash of device addressed
- #
- ########################################################################################
- sub OWXLCD_InitializeDevice($) {
- my ($hash) = @_;
- my ($i,$data,$select, $res);
-
- #-- ID of the device
- my $owx_dev = $hash->{ROM_ID};
-
- #-- hash of the busmaster
- my $master = $hash->{IODev};
- #-- supposedly we do not need to do anything with a HD44780
- if( $lcdcontroller eq "HD44780"){
- return undef;
- #-- need some additional sequence for KS0073
- }elsif ( $lcdcontroller eq "KS0073"){
-
- #-- Function Set: 4 bit data size, RE => 0 = \x20
- #OWXLCD_Byte($hash,"register",32);
- #-- Entry Mode Set: cursor auto increment = \x06
- #OWXLCD_Byte($hash,"register",6);
- if ($hash->{ASYNC}) {
- eval {
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",38));
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register", 9));
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",32));
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register",12));
- OWX_ASYNC_Schedule($hash,OWXLCD_PT_Byte($hash,"register", 1));
- };
- return GP_Catch($@) if $@;
- } else {
- #-- Function Set: 4 bit data size, RE => 1, blink Enable = \x26
- OWXLCD_Byte($hash,"register",38);
-
- #-- Ext. Function Set: 4 line mode = \x09
- OWXLCD_Byte($hash,"register",9);
-
- #-- Function Set: 4 bit data size, RE => 0 = \x20
- OWXLCD_Byte($hash,"register",32);
-
- #-- Display ON/OFF: display on, cursor off, blink off = \x0C
- OWXLCD_Byte($hash,"register",12);
-
- #-- Clear Display
- OWXLCD_Byte($hash,"register",1);
- }
- return undef;
- #-- or else
- } else {
- return "OWXLCD: Wrong LCD controller type";
- }
- }
- ########################################################################################
- #
- # OWXLCD_Byte - write a single byte to the LCD device
- #
- # Parameter hash = hash of device addressed
- # cmd = register or data
- # byte = byte
- #
- ########################################################################################
- sub OWXLCD_Byte($$$) {
- my ($hash,$cmd,$byte) = @_;
- my ($select, $select2, $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);
-
- #=============== write to LCD register ===============================
- if ( $cmd eq "register" ) {
- #-- issue the read LCD register command \x10
- $select = sprintf("\x10%c",$byte);
- #=============== write to LCD data ===============================
- }elsif ( $cmd eq "data" ) {
- #-- issue the read LCD data command \x12
- $select = sprintf("\x12%c",$byte);
- #=============== wrong value requested ===============================
- } else {
- return "OWXLCD: Wrong byte write attempt";
- }
-
- #-- write to device
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for writing a byte";
- }
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "writebyte", 0, $owx_dev,$select, 0, 0, 0, undef, 0);
- }
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_Get - get values from the LCD device
- #
- # Parameter hash = hash of device addressed
- # cmd = command string
- #
- ########################################################################################
- sub OWXLCD_Get($$) {
- my ($hash,$cmd) = @_;
- my ($select, $select2, $len, $addr, $res, $res2);
-
- #-- ID of the device
- my $owx_dev = $hash->{ROM_ID};
-
- #-- hash of the busmaster
- my $master = $hash->{IODev};
-
- my ($i,$j,$k);
- #=============== fill scratch with gpio ports ===============================
- if ( $cmd eq "gpio" ) {
- #-- issue the read GPIO command \x22 (1 byte)
- $select = "\x22";
- $len = 1;
- #=============== fill scratch with gpio counters ===============================
- }elsif ( $cmd eq "counter" ) {
- #-- issue the read counter command \x23 (8 bytes)
- $select = "\x23";
- $len = 8;
- #=============== fill scratch with version ===============================
- }elsif ( $cmd eq "version" ) {
- #-- issue the read version command \x41
- $select = "\x41";
- $len = 16;
- } else {
- return "OWXLCD: Wrong get attempt";
- }
- #-- write to device
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for reading";
- }
-
- #-- issue the read scratchpad command \xBE
- $select2 = "\xBE";
- #-- write to device
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select2,$len);
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for reading in 2nd step";
- }
- OWXLCD_BinValues($hash, "get.".$cmd, 1, $owx_dev, "\xBE", $len, substr($res,10));
- return main::ReadingsVal($hash->{NAME},$cmd,"");
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "get.prep.".$len, 0, $owx_dev, $select, $cmd, 1, 10, \&OWXLCD_BinValues, 0);
- return undef;
- }
- }
- ########################################################################################
- #
- # OWXLCD_GetMemory - get memory page from LCD device (EXPERIMENTAL)
- #
- # Parameter hash = hash of device addressed
- # page = memory page address
- #
- ########################################################################################
- sub OWXLCD_GetMemory($$) {
- my ($hash,$page) = @_;
- my ($select, $res, $res2, $res3);
-
- #-- 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);
- #-- issue the match ROM command \x55 and the copy eeprom to scratchpad command \x4E
- #Log 1," page read is ".$page;
- $select = sprintf("\4E%c\x10\x37",$page);
- #-- write to device
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for reading";
- }
- #-- issue the match ROM command \x55 and the read scratchpad command \xBE
- $select = "\xBE";
- #-- write to device
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,16);
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for reading in 2nd step";
- }
- OWXLCD_BinValues($hash, "get.memory.$page", 1, $owx_dev, $select, 16, substr($res,11,16));
- #-- process results (10 bytes or more have been sent)
- #$res2 = substr($res,11,16);
- #return $res2;
- return main::ReadingsVal($hash->{NAME},"memory$page","");
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "get.prep.16", 0, $owx_dev, $select, "memory.$page", 1, 11, \&OWXLCD_BinValues, 0);
- return undef;
- }
- }
- ########################################################################################
- #
- # OWXLCD_BinValues - Process reading from one device - translate binary into raw
- #
- # Parameter hash = hash of device addressed
- # context = mode for evaluating the binary data
- # proc = processing instruction, also passed to OWX_Read.
- # bitwise interpretation !!
- # if 0, nothing special
- # if 1 = bit 0, a reset will be performed not only before, but also after
- # the last operation in OWX_Read
- # if 2 = bit 1, the initial reset of the bus will be suppressed
- # if 8 = bit 3, the fillup of the data with 0xff will be suppressed
- # if 16= bit 4, the insertion will be at the top of the queue
- # owx_dev = ROM ID of slave device
- # crcpart = part of the data that needs to be part of the CRC check
- # numread = number of bytes to receive
- # res = result string
- #
- #
- ########################################################################################
- sub OWXLCD_BinValues($$$$$$$) {
- my ($hash, $context, $reset, $owx_dev, $crcpart, $numread, $res) = @_;
-
-
- my ($ret,@data,$select);
- my $change = 0;
-
- my $master = $hash->{IODev};
- my $name = $hash->{NAME};
- my $msg;
- OWX_WDBG($name,"OWLCD: $name: BinValues called with ",$res)
- if( $main::owx_debug>2 );
-
- #-- process results
- #die "OWVAR: $name not accessible in 2nd step" unless ( defined $res and $res ne 0 );
-
- #=============== setline 2nd step ===============================
- if( $context eq "setline" ) {
- #-- issue the copy scratchpad to LCD command \x48
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "", 16, $owx_dev,"\x48", 0, 0, 0, undef, 0);
- #=============== seteeprom 2nd step ===============================
- }elsif( $context eq "seteeprom" ) {
- #-- issue the copy scratchpad to EEPROM command \x39
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "", 16, $owx_dev,"\x39", 0, 0, 0, undef, 0);
- #=============== eraseicon 2nd step ===============================
- }elsif( $context eq "eraseicon.1" ) {
- #-- SEGRAM addres to 0 = \x40,
- $select = "\x10\x40";
- #-- write 16 zeros to scratchpad
- $select .= "\x4E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "eraseicon.2", 16, $owx_dev, $select, 0, 0, 0, \&OWXLCD_BinValues, 0);
- #=============== eraseicon 3rd step ===============================
- }elsif( $context eq "eraseicon.2" ) {
- #-- issue the copy scratchpad to LCD command \x48
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "endicon", 16, $owx_dev,"\x48", 0, 1, 0, \&OWXLCD_BinValues, 0);
- #=============== seticon 2nd step ===============================
- }elsif( $context eq "seticon.1" ) {
- #-- SEGRAM addres to 0 = \x40 + icon address
- $select = substr($crcpart,0,2);
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "seticon.2", 16, $owx_dev, $select,$crcpart, 0, 0, \&OWXLCD_BinValues, 0);
- #=============== seticon 2nd step ===============================
- }elsif( $context eq "seticon.2" ) {
- #-- data
- $select = substr($crcpart,2);
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "endicon", 16, $owx_dev, $select, 0, 1, 0, \&OWXLCD_BinValues, 0);
- #=============== endicon ===============================
- }elsif( $context eq "endicon" ) {
- #-- issue the return to normal state command
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- # 16 ensures entry at top of queue
- OWX_Qomplex($master, $hash, "", 16, $owx_dev, "\x10\x20", 0, 0, 0, undef, 0);
- #=============== prepare some get values ===============================
- }elsif ( $context =~ /^get\.prep\.(\d+)/ ) {
- my $len = $1;
- #Log 1,"OWXLCD_BinValues: context get.$crcpart with length $len";
- #-- command hidden in crcpart, issueing read scratchpad command
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "get.".$crcpart, 0, $owx_dev, "\xBE", 0, $len, 10, \&OWXLCD_BinValues, 0);
- #=============== gpio ports ===============================
- }elsif ( $context eq "get.gpio" ) {
- $ret = ord($res);
- readingsSingleUpdate($hash,"gpio",$ret,1);
- #=============== gpio counters ===============================
- }elsif ( $context eq "get.counter" ) {
- for( my $i=0; $i<4; $i++){
- $data[$i] = ord(substr($res,2*$i+1,1))*256+ord(substr($res,2*$i,1));
- }
- $ret = join(" ",@data);
- readingsSingleUpdate($hash,"counter",$ret,1);
- #=============== version ===============================
- }elsif ( $context eq "get.version" ) {
- #TODO format version, raw value is unreadable
- readingsSingleUpdate($hash,"version",$res,1);
- #=============== memory ===============================
- }elsif ( $context =~ /^get\.memory\.([\d]+)$/ ) {
- readingsSingleUpdate($hash,"memory$1",unpack("H*",$res),1);
- }
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_SetFunction - write state and values of the LCD device
- #
- # Parameter hash = hash of device addressed
- # cmd = command string
- # value = data value
- #
- ########################################################################################
- sub OWXLCD_SetFunction($$$) {
- my ($hash,$cmd,$value) = @_;
- my ($select, $res, $res2, $res3, @data);
-
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
-
- my ($i,$j,$k);
-
- #=============== set gpio ports ===============================
- if ( $cmd eq "gpio" ) {
- #-- issue the write GPIO command
- # \x21 followed by the data value (= integer 0 - 7)
- $select = sprintf("\x21%c",$value);
- #=============== switch LCD on ===============================
- }elsif ( $cmd eq "lcdon" ) {
- #-- issue the lcd on cmd
- $select = "\x03";
- #=============== switch LCD off ===============================
- }elsif ( $cmd eq "lcdoff" ) {
- #-- issue the lcd off cmd
- $select = "\x05";
- #=============== switch LCD backlight on ===============================
- }elsif ( $cmd eq "bklon" ) {
- #-- issue the backlight on cmd
- $select = "\x08";
- #=============== switch LCD backlight off ===============================
- }elsif ( $cmd eq "bkloff" ) {
- #-- issue the backlight off cmd
- $select = "\x07";
- #=============== switch LCD backlight off ===============================
- }elsif ( $cmd eq "reset" ) {
- #-- issue the clear LCD command
- $select = "\x49";
- #=============== wrong write attempt ===============================
- } else {
- return "OWXLCD: Wrong function selected";
- }
-
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- #-- write to device
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
- #-- process results
- if( $res eq 0 ){
- return "OWLCD: Device $owx_dev not accessible for writing";
- }
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "setfunction", 0, $owx_dev, $select, 0, 0, 0, undef, 0);
- }
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_SetIcon - set one of the icons
- #
- # Parameter hash = hash of device addressed
- # icon = address of the icon used = 0,1 .. 16 (0 = all off)
- # value = data value: 0 = off, 1 = on, 2 = blink
- # for battery icon 16: 0 = off, 1 = empty ... 5 = full, 6 = empty blink
- #
- ########################################################################################
- sub OWXLCD_SetIcon($$$) {
- my ($hash,$icon,$value) = @_;
- my ($i,$data,$select, $res);
-
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
- #-- only for KS0073
- if ( $lcdcontroller eq "KS0073"){
-
- #-- write 16 zeros to erase all icons
- if( $icon == 0){
- #-- 4 bit data size, RE => 1, blink Enable = \x26
- $select = "\x10\x26";
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- SEGRAM addres to 0 = \x40,
- $select = "\x10\x40";
- #-- write 16 zeros to scratchpad
- $select .= "\x4E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- return to normal state
- $select = "\x10\x20";
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "eraseicon.1", 0, $owx_dev, $select, 0, 0, 0, \&OWXLCD_BinValues, 0);
- }
- } else {
- #-- determine data value
- if( int($icon) != 16 ){
- if( $value == 0 ){
- $data = 0;
- } elsif ( $value == 1) {
- $data = 16;
- } elsif ( $value == 2) {
- $data = 80;
- } else {
- return "OWXLCD: Wrong data value $value for icon $icon";
- }
- } else {
- if( $value == 0 ){
- $data = 0;
- } elsif ( $value == 1) {
- $data = 16;
- } elsif ( $value == 2) {
- $data = 24;
- } elsif ( $value == 3) {
- $data = 28;
- } elsif ( $value == 4) {
- $data = 30;
- } elsif ( $value == 5) {
- $data = 31;
- } elsif ( $value == 6) {
- $data = 80;
- } else {
- return "OWXLCD: Wrong data value $value for icon $icon";
- }
- }
- #-- 4 bit data size, RE => 1, blink Enable = \x26
- $select = "\x10\x26";
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- SEGRAM addres to 0 = \x40 + icon address
- $select = sprintf("\x10%c",63+$icon);
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- data
- $select = sprintf("\x12%c",$data);
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- return to normal state
- $select = "\x10\x20";
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "seticon.1", 0, $owx_dev, $select, sprintf("\x10%c",63+$icon).sprintf("\x12%c",$data), 0, 0, \&OWXLCD_BinValues, 0);
- }
- }
-
- #-- or else
- } else {
- return "OWXLCD: Wrong LCD controller type";
- }
- }
- ########################################################################################
- #
- # OWXLCD_SetLine - set one of the display lines
- #
- # Parameter hash = hash of device addressed
- # line = line number (0..3)
- # msg = data string to be written
- #
- ########################################################################################
- sub OWXLCD_SetLine($$$) {
- my ($hash,$line,$msg) = @_;
-
- my ($select, $res, $res2, $res3, $i, $msgA, $msgB);
- $res2 = "";
- $line = int($line);
- $msg = defined($msg) ? $msg : "";
-
- $msg = OWXLCD_Trans($msg);
-
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
-
- #-- split if longer than 16 bytes, fill each with blanks
- # has already been checked to be <= $lcdchars
- if( $lcdchars > 16 ){
- if( length($msg) > 16 ) {
- $msgA = substr($msg,0,16);
- $msgB = substr($msg,16,length($msg)-16);
- for($i = 0;$i<$lcdchars-length($msg);$i++){
- $msgB .= "\x20";
- }
- } else {
- $msgA = $msg;
- for($i = 0;$i<16-length($msg);$i++){
- $msgA .= "\x20";
- }
- for($i = 0;$i<$lcdchars-16;$i++){
- $msgB .= "\x20";
- }
- }
- }else{
- $msgA = $msg;
- for($i = 0;$i<$lcdchars-length($msg);$i++){
- $msgA .= "\x20";
- }
- $msgB = undef;
- }
-
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- $select=sprintf("\x4E%c",$lcdpage[$line]).$msgA;
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- OWX_Reset($master);
- $res3=OWX_Complex($master,$owx_dev,$select,0);
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "setline", 0, $owx_dev, $select, 0, 0, 0, \&OWXLCD_BinValues, 0);
- }
- #-- if second string available:
- if( defined($msgB) ) {
- #select(undef,undef,undef,0.005);
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- $select=sprintf("\x4E%c",$lcdpage[$line]+16).$msgB;
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res2=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- OWX_Reset($master);
- $res3=OWX_Complex($master,$owx_dev,$select,0);
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "setline", 0, $owx_dev, $select, 0, 0, 0, \&OWXLCD_BinValues, 0);
- }
- }
-
- #-- process results
- if( !$master->{ASYNCHRONOUS} ){
- if( ($res eq 0) || ($res2 eq 0) || ($res3 eq 0) ){
- return "OWLCD: Device $owx_dev not accessible for writing";
- }
- }
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_Trans - String translation helper
- #
- # Parameter msg = data string to be written
- #
- ########################################################################################
- sub OWXLCD_Trans($) {
- my ($msg) = @_;
-
- #-- replace umlaut chars for special codepage of KS0073
- if( $lcdcontroller eq "KS0073") {
- $msg =~ s/ä/\x7B/g;
- $msg =~ s/ö/\x7C/g;
- $msg =~ s/ü/\x7E/g;
- $msg =~ s/Ä/\x5B/g;
- $msg =~ s/Ö/\x5C/g;
- $msg =~ s/Ü/\x5E/g;
- $msg =~ s/ß/\xBE/g;
- $msg =~ s/°/\x80/g;
- #-- replace umlaut chars for special codepage of HD44780
- }elsif( $lcdcontroller eq "HD44780") {
- $msg =~ s/ä/\xE1/g;
- $msg =~ s/ö/\xEF/g;
- $msg =~ s/ü/\xF5/g;
- $msg =~ s/Ü/\x03/g;
- $msg =~ s/Ö/\x02/g;
- $msg =~ s/Ä/\x01/g;
- $msg =~ s/ß/\xE2/g;
- $msg =~ s/°/\xDF/g;
- }
-
- #-- replace other special chars
- $msg =~s/_/\xC4/g;
- return $msg;
- }
- ########################################################################################
- #
- # OWXLCD_SetMemory - set internal nonvolatile memory
- #
- # Parameter hash = hash of device addressed
- # page = page number (0..14)
- # msg = data string to be written
- #
- ########################################################################################
- sub OWXLCD_SetMemory($$$) {
- my ($hash,$page,$msg) = @_;
-
- my ($select, $res, $res2, $res3, $i, $msgA);
- $page = int($page);
- $msg = defined($msg) ? $msg : "";
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
-
- #-- fillup with blanks
- $msgA = $msg;
- for($i = 0;$i<16-length($msg);$i++){
- $msgA .= "\x20";
- }
-
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- #Log 1," page written is ".$page;
- $select=sprintf("\x4E\%c",$page).$msgA;
- #-- OLD OWX interface
- if( !$master->{ASYNCHRONOUS} ){
- OWX_Reset($master);
- $res=OWX_Complex($master,$owx_dev,$select,0);
- #-- issue the copy scratchpad to EEPROM command \x39
- $select = "\x39";
- OWX_Reset($master);
- $res2=OWX_Complex($master,$owx_dev,$select,0);
-
- #-- process results
- if( ($res eq 0) || ($res2 eq 0) ){
- return "OWLCD: Device $owx_dev not accessible for writing";
- }
- #-- NEW OWX interface
- }else{
- #### master slave context proc owx_dev data crcpart numread startread callback delay
- OWX_Qomplex($master, $hash, "seteeprom", 0, $owx_dev, $select, 0, 0, 0, \&OWXLCD_BinValues, 0);
- }
- return undef;
- }
- ########################################################################################
- #
- # OWXLCD_PT_Byte - write a single byte to the LCD device async
- #
- # Parameter hash = hash of device addressed
- # cmd = register or data
- # byte = byte
- #
- ########################################################################################
- sub OWXLCD_PT_Byte($$$) {
- my ($hash,$cmd,$byte) = @_;
-
- return PT_THREAD(sub {
- my ($thread) = @_;
- my ($select);
- #-- ID of the device
- my $owx_dev = $hash->{ROM_ID};
- #-- hash of the busmaster
- my $master = $hash->{IODev};
- my ($i,$j,$k);
- PT_BEGIN($thread);
- #=============== write to LCD register ===============================
- if ( $cmd eq "register" ) {
- #-- issue the read LCD register command \x10
- $select = sprintf("\x10%c",$byte);
- #=============== write to LCD data ===============================
- }elsif ( $cmd eq "data" ) {
- #-- issue the read LCD data command \x12
- $select = sprintf("\x12%c",$byte);
- #=============== wrong value requested ===============================
- } else {
- die "OWXLCD: Wrong byte write attempt";
- }
- #"byte"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_Get - get values from the LCD device async
- #
- # Parameter hash = hash of device addressed
- # cmd = command string
- #
- ########################################################################################
- sub OWXLCD_PT_Get($$) {
- my ($hash,$cmd) = @_;
- return PT_THREAD(sub {
- my ($thread) = @_;
- my ($select);
- #-- ID of the device
- my $owx_dev = $hash->{ROM_ID};
- #-- hash of the busmaster
- my $master = $hash->{IODev};
- my ($i,$j,$k);
- PT_BEGIN($thread);
- #=============== fill scratch with gpio ports ===============================
- if ( $cmd eq "gpio" ) {
- #-- issue the read GPIO command \x22 (1 byte)
- $select = "\x22";
- $thread->{len} = 1;
- #=============== fill scratch with gpio counters ===============================
- }elsif ( $cmd eq "counter" ) {
- #-- issue the read counter command \x23 (8 bytes)
- $select = "\x23";
- $thread->{len} = 8;
- #=============== fill scratch with version ===============================
- }elsif ( $cmd eq "version" ) {
- #-- issue the read version command \x41
- $select = "\x41";
- $thread->{len} = 16;
- } else {
- die("OWXLCD: Wrong get attempt");
- }
- #"get.prepare"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- issue the read scratchpad command \xBE
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,"\xBE", $thread->{len});
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- OWXLCD_BinValues($hash, "get.".$cmd, 1, $owx_dev, "\xBE", $thread->{len}, $thread->{pt_execute}->PT_RETVAL());
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_GetMemory - get memory page from LCD device async (EXPERIMENTAL)
- #
- # Parameter hash = hash of device addressed
- # page = memory page address
- #
- ########################################################################################
- sub OWXLCD_PT_GetMemory($$) {
- my ($hash,$page) = @_;
- return PT_THREAD(sub {
- my ($thread) = @_;
- my ($select);
- #-- ID of the device
- my $owx_dev = $hash->{ROM_ID};
- #-- hash of the busmaster
- my $master = $hash->{IODev};
- PT_BEGIN($thread);
- #-- issue the match ROM command \x55 and the copy eeprom to scratchpad command \x4E
- #Log 1," page read is ".$page;
- $select = sprintf("\4E%c\x10\x37",$page);
- #"prepare"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- sleeping for some time
- $thread->{ExecuteTime} = gettimeofday()+0.5;
- PT_YIELD_UNTIL(gettimeofday() >= $thread->{ExecuteTime});
- delete $thread->{ExecuteTime};
- #-- issue the match ROM command \x55 and the read scratchpad command \xBE
- $thread->{'select'} = "\xBE";
- #"get.memory.$page"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$thread->{'select'},16);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- OWXLCD_BinValues($hash, "get.memory.$page", 1, $owx_dev, $thread->{'select'}, 16, $thread->{pt_execute}->PT_RETVAL());
- #-- process results (10 bytes or more have been sent)
- #$res2 = substr($res,11,16);
- #return $res2;
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_SetFunction - write state and values of the LCD device async
- #
- # Parameter hash = hash of device addressed
- # cmd = command string
- # value = data value
- #
- ########################################################################################
- sub OWXLCD_PT_SetFunction($$$) {
- my ($hash,$cmd,$value) = @_;
- return PT_THREAD(sub {
- my ($thread) = @_;
- my ($select);
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
- my ($i,$j,$k);
- PT_BEGIN($thread);
- #=============== set gpio ports ===============================
- if ( $cmd eq "gpio" ) {
- #-- issue the write GPIO command
- # \x21 followed by the data value (= integer 0 - 7)
- $select = sprintf("\x21%c",$value);
- #=============== switch LCD on ===============================
- }elsif ( $cmd eq "lcdon" ) {
- #-- issue the lcd on cmd
- $select = "\x03";
- #=============== switch LCD off ===============================
- }elsif ( $cmd eq "lcdoff" ) {
- #-- issue the lcd off cmd
- $select = "\x05";
- #=============== switch LCD backlight on ===============================
- }elsif ( $cmd eq "bklon" ) {
- #-- issue the backlight on cmd
- $select = "\x08";
- #=============== switch LCD backlight off ===============================
- }elsif ( $cmd eq "bkloff" ) {
- #-- issue the backlight off cmd
- $select = "\x07";
- #=============== switch LCD backlight off ===============================
- }elsif ( $cmd eq "reset" ) {
- #-- issue the clear LCD command
- $select = "\x49";
- #=============== wrong write attempt ===============================
- } else {
- die "OWXLCD: Wrong function selected '$cmd'";
- }
- #"set.function"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
-
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_SetIcon - set one of the icons async
- #
- # Parameter hash = hash of device addressed
- # icon = address of the icon used = 0,1 .. 16 (0 = all off)
- # value = data value: 0 = off, 1 = on, 2 = blink
- # for battery icon 16: 0 = off, 1 = empty ... 5 = full, 6 = empty blink
- #
- ########################################################################################
- sub OWXLCD_PT_SetIcon($$$) {
- my ($hash,$icon,$value) = @_;
- return PT_THREAD(sub {
- my ($thread) = @_;
- my ($i,$data,$select, $res);
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
- PT_BEGIN($thread);
- #-- only for KS0073
- if ( $lcdcontroller eq "KS0073"){
- #-- write 16 zeros to erase all icons
- if( $icon == 0){
- #-- 4 bit data size, RE => 1, blink Enable = \x26
- $select = "\x10\x26";
- #"set.icon.1"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- SEGRAM addres to 0 = \x40,
- $select = "\x10\x40";
- #-- write 16 zeros to scratchpad
- $select .= "\x4E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
- #"set.icon.2"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- #"set.icon.3"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- } else {
- #-- determine data value
- if( int($icon) != 16 ){
- if( $value == 0 ){
- $data = 0;
- } elsif ( $value == 1) {
- $data = 16;
- } elsif ( $value == 2) {
- $data = 80;
- } else {
- die("OWXLCD: Wrong data value $value for icon $icon");
- }
- } else {
- if( $value == 0 ){
- $data = 0;
- } elsif ( $value == 1) {
- $data = 16;
- } elsif ( $value == 2) {
- $data = 24;
- } elsif ( $value == 3) {
- $data = 28;
- } elsif ( $value == 4) {
- $data = 30;
- } elsif ( $value == 5) {
- $data = 31;
- } elsif ( $value == 6) {
- $data = 80;
- } else {
- die("OWXLCD: Wrong data value $value for icon $icon");
- }
- }
- #-- 4 bit data size, RE => 1, blink Enable = \x26
- $select = "\x10\x26";
- #"set.icon.4"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- SEGRAM addres to 0 = \x40 + icon address
- $select = sprintf("\x10%c",63+$icon);
- #"set.icon.5"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- data
- $select = sprintf("\x12%c",$data);
- #"set.icon.6"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- }
- #-- return to normal state
- $select = "\x10\x20";
- #"set.icon.7"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- or else
- } else {
- die("OWXLCD: Wrong LCD controller type");
- }
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_SetLine - set one of the display lines async
- #
- # Parameter hash = hash of device addressed
- # line = line number (0..3)
- # msg = data string to be written
- #
- ########################################################################################
- sub OWXLCD_PT_SetLine($$$) {
- my ($hash,$line,$msg) = @_;
-
- return PT_THREAD(sub {
-
- my ($thread) = @_;
- my ($select, $i, $msgA, $msgB);
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
- $line = int($line);
- PT_BEGIN($thread);
- $msg = defined($msg) ? $msg : "";
- $msg = OWXLCD_Trans($msg);
- #-- split if longer than 16 bytes, fill each with blanks
- # has already been checked to be <= $lcdchars
- if( $lcdchars > 16 ){
- if( length($msg) > 16 ) {
- $msgA = substr($msg,0,16);
- $msgB = substr($msg,16,length($msg)-16);
- for($i = 0;$i<$lcdchars-length($msg);$i++){
- $msgB .= "\x20";
- }
- } else {
- $msgA = $msg;
- for($i = 0;$i<16-length($msg);$i++){
- $msgA .= "\x20";
- }
- for($i = 0;$i<$lcdchars-16;$i++){
- $msgB .= "\x20";
- }
- }
- }else{
- $msgA = $msg;
- for($i = 0;$i<$lcdchars-length($msg);$i++){
- $msgA .= "\x20";
- }
- $msgB = undef;
- }
- $thread->{msgB} = $msgB;
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- $select=sprintf("\x4E%c",$lcdpage[$line]).$msgA;
- #"set.line.1"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- #"set.line.2"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- if second string available:
- if( defined($thread->{msgB}) ) {
- #select(undef,undef,undef,0.005);
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- $select=sprintf("\x4E%c",$lcdpage[$line]+16).$thread->{msgB};
- #"set.line.3"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- issue the copy scratchpad to LCD command \x48
- $select="\x48";
- #"set.line.4"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- }
- PT_END;
- });
- }
- ########################################################################################
- #
- # OWXLCD_PT_SetMemory - set internal nonvolatile memory async
- #
- # Parameter hash = hash of device addressed
- # page = page number (0..14)
- # msg = data string to be written
- #
- ########################################################################################
- sub OWXLCD_PT_SetMemory($$$) {
- my ($hash,$page,$msg) = @_;
- return PT_THREAD(sub {
- my ($thread,$hash,$page,$msg) = @_;
- my ($select, $i, $msgA);
- #-- ID of the device, hash of the busmaster
- my $owx_dev = $hash->{ROM_ID};
- my $master = $hash->{IODev};
- PT_BEGIN($thread);
- $page = int($page);
- $msg = defined($msg) ? $msg : "";
- #-- fillup with blanks
- $msgA = $msg;
- for($i = 0;$i<16-length($msg);$i++){
- $msgA .= "\x20";
- }
- #-- issue the match ROM command \x55 and the write scratchpad command \x4E
- # followed by LCD page address and the text
- #Log 1," page written is ".$page;
- $select=sprintf("\x4E\%c",$page).$msgA;
- #"set.memory.page"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- #-- issue the copy scratchpad to EEPROM command \x39
- $select = "\x39";
- #"set.memory.copy"
- $thread->{pt_execute} = OWX_ASYNC_PT_Execute($master,1,$owx_dev,$select,0);
- PT_WAIT_THREAD($thread->{pt_execute});
- die $thread->{pt_execute}->PT_CAUSE() if ($thread->{pt_execute}->PT_STATE() == PT_ERROR);
- PT_END;
- });
- }
- 1;
- =pod
- =begin html
- <a name="OWLCD"></a>
- <h3>OWLCD</h3>
- <p>FHEM module to commmunicate with the <a
- href="http://www.louisswart.co.za/1-Wire_Overview.html">1-Wire LCD controller</a>
- from Louis Swart (1-Wire family id FF). See also the corresponding <a
- href="http://fhemwiki.de/wiki/1-Wire_Textdisplay">Wiki page.</a><br /><br />
- Note:<br /> This 1-Wire module so far works only with the OWX interface module. Please
- define an <a href="#OWX">OWX</a> device first. <br /></p>
- <br /><h4>Example</h4>
- <p>
- <code>define OWX_LCD OWLCD 9F0700000100</code>
- <br />
- </p>
- <br />
- <a name="OWLCDdefine"></a>
- <h4>Define</h4>
- <p>
- <code>define <name> OWLCD <id></code> or <br/>
- <code>define <name> OWLCD FF.<id></code>
- <br /><br /> Define a 1-Wire LCD device.<br /><br /></p>
- <ul>
- <li>
- <code><id></code>
- <br />12-character unique ROM id of the converter device without family id and CRC
- code </li>
- </ul>
- <br />
- <a name="OWLCDset"></a>
- <h4>Set</h4>
- <ul>
- <li><a name="owlcd_icon">
- <code>set <name> icon <int> on|off|blink</code></a><br /> Set one of
- the icons 0..14 on, off or blinking</li>
- <li><a name="owlcd_icon2">
- <code>set <name> icon 15 0..6</code></a><br /> Set icon 15 to one of its
- values</li>
- <li><a name="owlcd_icon3">
- <code>set <name> icon none</code></a><br /> Set all icons off</li>
- <li><a name="owlcd_line">
- <code>set <name> line <int> <string></code></a><br /> Write
- LCD line 0..3 with some content </li>
- <li><a name="owlcd_memory">
- <code>set <name> memory <page> <string></code></a><br />Write
- memory page 0..6</li>
- <li><a name="owlcd_gpio">
- <code>set <name> gpio <value></code></a><br />Write state for all
- three gpio pins (value = 0..7, for each bit 0=ON, 1=OFF)</li>
- <li><a name="owlcd_bl">
- <code>set <name> backlight ON|OFF</code></a><br />Switch backlight on or
- off</li>
- <li><a name="owlcd_lcd">
- <code>set <name> lcd ON|OFF</code></a><br />Switch LCD power on or
- off</li>
- <li><a name="owlcd_gpio">
- <code>set <name> reset</code></a><br />Reset the display</li>
- <li><a name="owlcd_gpio">
- <code>set <name> test</code></a><br />Test the display</li>
- </ul>
- <br />
- <a name="owlcdget"></a>
- <h4>Get</h4>
- <ul>
- <li><a name="owlcd_id">
- <code>get <name> id</code></a>
- <br /> Returns the full 1-Wire device id OW_FAMILY.ROM_ID.CRC </li>
- <li><a name="owlcd_present">
- <code>get <name> present</code>
- </a>
- <br /> Returns 1 if this 1-Wire device is present, otherwise 0. </li>
- <li><a name="owlcd_memory2">
- <code>get <name> memory <page></code></a><br />Read memory page 0..6 </li>
- <li><a name="owlcd_gpio">
- <code>get <name> gpio</code></a><br />Obtain state of all four input
- channels (15 = all off, 0 = all on)</li>
- <li><a name="owlcd_counter">
- <code>get <name> counter</code></a><br />Obtain state of all four input
- counters (4 x 16 Bit)</li>
- <li><a name="owlcd_version">
- <code>get <name> version</code></a><br />Obtain firmware version of the
- controller</li>
- </ul>
- <br />
- <a name="owlcdattr"></a>
- <h4>Attributes</h4>
- <ul>
- <li><a name="owlcd_lcdgeometry">
- <code>attr <name> lcdgeometry <string></code></a><br />
- LCD geometry, values are 0-32-64-96 (default) or 0-64-20-84</li>
- <li><a name="owlcd_lcdgcontroller">
- <code>attr <name> lcdcontroller <string></code></a><br />
- LCD geometry, values are KS0073 (default) HD44780</li>
- <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
- </ul>
-
- =end html
- =cut
|