From 994dfa91f247f44a3be5a95e4a2ddeb909498514 Mon Sep 17 00:00:00 2001 From: dirkho Date: Mon, 9 Mar 2015 00:55:07 +0000 Subject: [PATCH] WebViewControl: first commit git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@8178 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/50_WS300.pm | 2 - fhem/FHEM/51_I2C_BMP180.pm | 143 +- fhem/MAINTAINER.txt | 1 + .../WebViewControl/95_WebViewControl.pm | 311 + .../packages/WebViewControl-0.4a.zip | Bin 0 -> 524936 bytes .../WebViewControl/screenshots/sc1.jpg | Bin 0 -> 52825 bytes .../WebViewControl/screenshots/sc2.jpg | Bin 0 -> 55521 bytes .../WebViewControl/screenshots/settings.jpg | Bin 0 -> 36314 bytes .../WebViewControl/screenshots/settings.png | Bin 0 -> 63226 bytes .../www/images/default/batteryIconSprite.png | Bin 0 -> 13878 bytes .../www/images/default/mic_sprite.png | Bin 0 -> 12436 bytes .../www/images/default/onlineIconSprite.png | Bin 0 -> 2041 bytes .../WebViewControl/www/pgm2/cordova-2.3.0.js | 6460 +++++++++++++++++ .../www/pgm2/webviewcontrol.css | 147 + .../WebViewControl/www/pgm2/webviewcontrol.js | 876 +++ 15 files changed, 7866 insertions(+), 74 deletions(-) create mode 100644 fhem/contrib/WebViewControl/95_WebViewControl.pm create mode 100644 fhem/contrib/WebViewControl/packages/WebViewControl-0.4a.zip create mode 100644 fhem/contrib/WebViewControl/screenshots/sc1.jpg create mode 100644 fhem/contrib/WebViewControl/screenshots/sc2.jpg create mode 100644 fhem/contrib/WebViewControl/screenshots/settings.jpg create mode 100644 fhem/contrib/WebViewControl/screenshots/settings.png create mode 100644 fhem/contrib/WebViewControl/www/images/default/batteryIconSprite.png create mode 100644 fhem/contrib/WebViewControl/www/images/default/mic_sprite.png create mode 100644 fhem/contrib/WebViewControl/www/images/default/onlineIconSprite.png create mode 100644 fhem/contrib/WebViewControl/www/pgm2/cordova-2.3.0.js create mode 100644 fhem/contrib/WebViewControl/www/pgm2/webviewcontrol.css create mode 100644 fhem/contrib/WebViewControl/www/pgm2/webviewcontrol.js diff --git a/fhem/FHEM/50_WS300.pm b/fhem/FHEM/50_WS300.pm index 1102c152d..0d0b77254 100644 --- a/fhem/FHEM/50_WS300.pm +++ b/fhem/FHEM/50_WS300.pm @@ -66,7 +66,6 @@ WS300_Initialize($) # Provider $hash->{AttrList} = "do_not_notify:0,1 showtime:0,1 model:ws300 ". - "loglevel:0,1,2,3,4,5,6 ". $readingFnAttributes; $hash->{DefFn} = "WS300_Define"; @@ -669,7 +668,6 @@ NEXTPOLL: Attributes diff --git a/fhem/FHEM/51_I2C_BMP180.pm b/fhem/FHEM/51_I2C_BMP180.pm index 613f0b945..9d53daad4 100644 --- a/fhem/FHEM/51_I2C_BMP180.pm +++ b/fhem/FHEM/51_I2C_BMP180.pm @@ -72,14 +72,14 @@ sub I2C_BMP180_Initialize($) { my ($hash) = @_; eval "use HiPi::Device::I2C;"; - $libcheck_hasHiPi = 0 if($@); + $libcheck_hasHiPi = 0 if($@); $hash->{DefFn} = 'I2C_BMP180_Define'; $hash->{InitFn} = 'I2C_BMP180_Init'; $hash->{AttrFn} = 'I2C_BMP180_Attr'; $hash->{SetFn} = 'I2C_BMP180_Set'; $hash->{UndefFn} = 'I2C_BMP180_Undef'; - $hash->{I2CRecFn} = 'I2C_BMP180_I2CRec'; + $hash->{I2CRecFn} = 'I2C_BMP180_I2CRec'; $hash->{AttrList} = 'IODev do_not_notify:0,1 showtime:0,1 model:BMP180,BMP085 ' . 'poll_interval:1,2,5,10,20,30 oversampling_settings:0,1,2,3 ' . @@ -119,10 +119,9 @@ sub I2C_BMP180_Define($$) { return $msg; } if ($main::init_done || $hash->{HiPi_used}) { - eval { I2C_BMP180_Init( $hash, [ @a[ 2 .. scalar(@a) - 1 ] ] ); }; - return I2C_BMP180_Catch($@) if $@; - } - + eval { I2C_BMP180_Init( $hash, [ @a[ 2 .. scalar(@a) - 1 ] ] ); }; + return I2C_BMP180_Catch($@) if $@; + } } sub I2C_BMP180_Init($$) { @@ -160,12 +159,12 @@ sub I2C_BMP180_Init($$) { } sub I2C_BMP180_Catch($) { - my $exception = shift; - if ($exception) { - $exception =~ /^(.*)( at.*FHEM.*)$/; - return $1; - } - return undef; + my $exception = shift; + if ($exception) { + $exception =~ /^(.*)( at.*FHEM.*)$/; + return $1; + } + return undef; } =head2 I2C_BMP180_Attr @@ -260,7 +259,7 @@ sub I2C_BMP180_Undef($$) { sub I2C_BMP180_I2CRec ($$) { my ($hash, $clientmsg) = @_; - my $name = $hash->{NAME}; + my $name = $hash->{NAME}; my $pname = undef; unless ($hash->{HiPi_used}) {#nicht nutzen wenn HiPi Bibliothek in Benutzung my $phash = $hash->{IODev}; @@ -275,7 +274,7 @@ sub I2C_BMP180_I2CRec ($$) { || $hash->{HiPi_used}) ) { if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) { Log3 $hash, 5, "$name empfangen: $clientmsg->{received}"; - I2C_BMP180_GetCal ($hash, $clientmsg->{received}) if $clientmsg->{reg} == hex("AA"); + I2C_BMP180_GetCal ($hash, $clientmsg->{received}) if $clientmsg->{reg} == hex("AA"); I2C_BMP180_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{reg} == hex("F6") && $clientmsg->{nbyte} == 2; I2C_BMP180_GetPress ($hash, $clientmsg->{received}) if $clientmsg->{reg} == hex("F6") && $clientmsg->{nbyte} == 3; } @@ -284,7 +283,7 @@ sub I2C_BMP180_I2CRec ($$) { sub I2C_BMP180_GetCal ($$) { my ($hash, $rawdata) = @_; - my @raw = split(" ",$rawdata); + my @raw = split(" ",$rawdata); my $n = 0; Log3 $hash, 5, "in get cal: $rawdata"; $hash->{calibrationData}{ac1} = I2C_BMP180_GetCalVar($raw[$n++], $raw[$n++]); @@ -317,23 +316,23 @@ sub I2C_BMP180_GetCalVar ($$;$) { sub I2C_BMP180_GetTemp ($$) { my ($hash, $rawdata) = @_; - my @raw = split(" ",$rawdata); - $hash->{uncompTemp} = $raw[0] << 8 | $raw[1]; + my @raw = split(" ",$rawdata); + $hash->{uncompTemp} = $raw[0] << 8 | $raw[1]; } sub I2C_BMP180_GetPress ($$) { my ($hash, $rawdata) = @_; - my @raw = split(" ",$rawdata); + my @raw = split(" ",$rawdata); my $overSamplingSettings = AttrVal($hash->{NAME}, 'oversampling_settings', 3); - my $ut = $hash->{uncompTemp}; + my $ut = $hash->{uncompTemp}; delete $hash->{uncompTemp}; my $up = ( ( ($raw[0] << 16) | ($raw[1] << 8) | $raw[2] ) >> (8 - $overSamplingSettings) ); my $temperature = sprintf( - '%.' . AttrVal($hash->{NAME}, 'roundTemperatureDecimal', 1) . 'f', - I2C_BMP180_calcTrueTemperature($hash, $ut) / 10 - ); + '%.' . AttrVal($hash->{NAME}, 'roundTemperatureDecimal', 1) . 'f', + I2C_BMP180_calcTrueTemperature($hash, $ut) / 10 + ); my $pressure = sprintf( '%.' . AttrVal($hash->{NAME}, 'roundPressureDecimal', 1) . 'f', @@ -369,7 +368,7 @@ sub I2C_BMP180_GetPress ($$) { =cut sub I2C_BMP180_readUncompensatedTemperature($) { my ($hash) = @_; - + # Write 0x2E into Register 0xF4. This requests a temperature reading I2C_BMP180_i2cwrite($hash, hex("F4"), hex("2E")); @@ -452,8 +451,8 @@ sub I2C_BMP180_i2cwrite($$$) { CallFn($iodev->{NAME}, "I2CWrtFn", $iodev, { direction => "i2cwrite", i2caddress => $hash->{I2C_Address}, - reg => $reg, - data => join (' ',@data), + reg => $reg, + data => join (' ',@data), }); } else { return "no IODev assigned to '$hash->{NAME}'"; @@ -531,39 +530,39 @@ sub I2C_BMP180_calcTruePressure($$$) { via the i2c bus on Raspberry Pi.

There are two possibilities connecting to I2C bus:
-

+ +

Define

    define BMP180 I2C_BMP180 [<I2C device>]

    - <I2C device> must not be used if you connect via RPII2C module. For HiPi it's mandatory.
    + <I2C device> must not be used if you connect via RPII2C module. For HiPi it's mandatory.

    Examples:
    @@ -571,7 +570,7 @@ sub I2C_BMP180_calcTruePressure($$$) {
           attr BMP180 oversampling_settings 3
           attr BMP180 poll_interval 5
         
    -
    +    
           define BMP180 I2C_BMP180
           attr BMP180 IODev RPiI2CMod
           attr BMP180 oversampling_settings 3
    @@ -640,39 +639,39 @@ sub I2C_BMP180_calcTruePressure($$$) {
         Dieses Modul ermöglicht das Auslesen der digitalen (Luft)drucksensoren
         BMP085 und BMP180 über den I2C Bus des Raspberry Pi.

    Es gibt zwei Möglichkeiten das Modul mit dem I2C Bus zu verbinden:
    -
      -
    • Über das RPII2C Modul
      - I2C-Botschaften werden über ein I2C Interface Modul wie beispielsweise das RPII2C, FRM - oder NetzerI2C gesendet. Daher muss dieses vorher definiert werden.
      - Das Attribut IODev muss definiert sein.

      -
    • -
    • Über die HiPi Bibliothek
      - Diese beiden Zeilen müssen in die Datei /etc/modules angefügt werden, - um die Kernel Module automatisch beim Booten des Raspberry Pis zu laden.
      -
      	i2c-bcm2708 
      +    
        +
      • Über das RPII2C Modul
        + I2C-Botschaften werden über ein I2C Interface Modul wie beispielsweise das RPII2C, FRM + oder NetzerI2C gesendet. Daher muss dieses vorher definiert werden.
        + Das Attribut IODev muss definiert sein.

        +
      • +
      • Über die HiPi Bibliothek
        + Diese beiden Zeilen müssen in die Datei /etc/modules angefügt werden, + um die Kernel Module automatisch beim Booten des Raspberry Pis zu laden.
        +
        i2c-bcm2708 
                 i2c-dev
        - Installation des HiPi Perl Moduls:
        -
        	wget http://raspberry.znix.com/hipifiles/hipi-install
        +        Installation des HiPi Perl Moduls:
        +
        wget http://raspberry.znix.com/hipifiles/hipi-install
                 perl hipi-install
        - Um die Rechte für die I2C Devices anzupassen, folgende Datei:
        -
        	/etc/udev/rules.d/98_i2c.rules
        - mit diesem Inhalt anlegen:
        -
        	SUBSYSTEM=="i2c-dev", MODE="0666"
        - Reboot

        - Falls der Sensor am zweiten I2C Bus am Stecker P5 (nur in Version 2 des - Raspberry Pi) verwendet werden soll, muss die fett gedruckte Zeile - des folgenden Codes in das FHEM Start Skript aufgenommen werden: -
        	case "$1" in
        +        Um die Rechte für die I2C Devices anzupassen, folgende Datei:
        +
        	/etc/udev/rules.d/98_i2c.rules
        + mit diesem Inhalt anlegen:
        +
        SUBSYSTEM=="i2c-dev", MODE="0666"
        + Reboot

        + Falls der Sensor am zweiten I2C Bus am Stecker P5 (nur in Version 2 des + Raspberry Pi) verwendet werden soll, muss die fett gedruckte Zeile + des folgenden Codes in das FHEM Start Skript aufgenommen werden: +
        	case "$1" in
                 'start')
                 sudo hipi-i2c e 0 1
                 ...
        -
      +

    Define

      define BMP180 <BMP180_name> <I2C_device>

      - <I2C device> darf nicht verwendet werden, wenn der I2C Bus über das RPII2C Modul angesprochen wird. For HiPi ist es allerdings notwendig.
      + <I2C device> darf nicht verwendet werden, wenn der I2C Bus über das RPII2C Modul angesprochen wird. For HiPi ist es allerdings notwendig.

      Beispiel:
      @@ -680,7 +679,7 @@ sub I2C_BMP180_calcTruePressure($$$) {
             attr BMP180 oversampling_settings 3
             attr BMP180 poll_interval 5
           
      -
      +    
             define BMP180 I2C_BMP180
             attr BMP180 IODev RPiI2CMod
             attr BMP180 oversampling_settings 3
      diff --git a/fhem/MAINTAINER.txt b/fhem/MAINTAINER.txt
      index 68bb91ce4..fae3307fa 100644
      --- a/fhem/MAINTAINER.txt
      +++ b/fhem/MAINTAINER.txt
      @@ -324,6 +324,7 @@ contrib/71_LISTENLIVE.pm     betateilchen         http://forum.fhem.de Multimedi
       contrib/98_geodata.pm        betateilchen         http://forum.fhem.de Sonstiges
       contrib/98_openweathermap.pm betateilchen         http://forum.fhem.de Unterstuetzende Dienste
       contrib/98_PID.pm            betateilchen         http://forum.fhem.de Automatisierung
      +contrib/WebViewControl/*     Dirk                 http://forum.fhem.de Mobile Devices
       
       www/codemirror/*             betateilchen         http://forum.fhem.de Frontends
       www/gplot/*                  rudolfkoenig         http://forum.fhem.de Frontends
      diff --git a/fhem/contrib/WebViewControl/95_WebViewControl.pm b/fhem/contrib/WebViewControl/95_WebViewControl.pm
      new file mode 100644
      index 000000000..15aad6216
      --- /dev/null
      +++ b/fhem/contrib/WebViewControl/95_WebViewControl.pm
      @@ -0,0 +1,311 @@
      +################################################################################
      +# 95_webViewControl.pm
      +# Modul for FHEM
      +#
      +# Modul for communication between WebViewControl Android App and FHEM
      +#
      +# contributed by Dirk Hoffmann 01/2013
      +# $Id:
      +#
      +################################################################################
      +
      +package main;
      +
      +use Data::Dumper;    # for debugging only
      +
      +use strict;
      +use warnings;
      +use URI::Escape;
      +
      +use vars qw {%data %attr %defs %modules $FW_RET}; #supress errors in Eclipse EPIC
      +
      +use constant {
      +	webViewControl_Version => '0.5.1_beta',
      +};
      +
      +#########################
      +# Forward declaration
      +sub webViewControl_Initialize($);		# Initialize
      +sub webViewControl_Define($$);			# define  WEBVIEWCONTROL
      +sub webViewControl_Undef($$);			# delete
      +sub webViewControl_modifyJsInclude($);	# include js parts
      +sub webViewControl_Set($@);				# set
      +sub webViewControl_Get($@);				# get
      +sub webViewControl_Cgi();				# analyze and parse URL
      +sub webViewControl_Attr(@);
      +
      +#########################
      +# Global variables
      +my $fhemUrl = '/webviewcontrol' ;
      +
      +my %sets = (
      +	'screenBrightness'	=> 'screenBrightness', # slider,1,1,100',
      +	'volume'			=> 'volume', # slider,1,1,100',	
      +	'keepScreenOn'		=> 'keepScreenOn',
      +	'toastMessage'		=> 'toastMessage',
      +	'reload'			=> 'reload',
      +	'audioPlay'			=> 'audioPlay',
      +	'audioStop'			=> 'audioStop',
      +	'ttsSay'			=> 'ttsSay',
      +	'voiceRec'			=> 'voiceRec',
      +	'newUrl'			=> 'newUrl',	
      +	'reload'			=> 'reload',	
      +);
      +	
      +my %gets = (
      +	'powerLevel'				=> 1,
      +	'powerPlugged'				=> 1,
      +	'voiceRecognitionLastError'	=> 1,
      +	'voiceRecognitionLastResult'=> 1,
      +);
      +
      +my $FW_encoding="UTF-8";		 # like in FHEMWEB: encoding hardcoded
      +
      +################################################################################
      +# Implements Initialize function
      +#
      +# @param	hash	$hash	hash of device addressed
      +#
      +################################################################################
      +sub webViewControl_Initialize($) {
      +	my ($hash) = @_;
      +
      +	$hash->{DefFn}    = 'webViewControl_Define';
      +	$hash->{UndefFn}  = 'webViewControl_Undef';
      +	$hash->{SetFn}    = 'webViewControl_Set';
      +	$hash->{GetFn}    = 'webViewControl_Get';
      +	$hash->{AttrFn}   = "webViewControl_Attr";
      +
      +	$hash->{AttrList} = 'loglevel:0,1,2,3,4,5,6 model userJsFile userCssFile '
      +	                  . $readingFnAttributes;
      +
      +	# CGI
      +	$data{FWEXT}{$fhemUrl}{FUNC} = 'webViewControl_Cgi';
      +}
      +
      +################################################################################
      +# Implements DefFn function
      +#
      +# @param	hash	$hash	hash of device addressed
      +# @param	string	$def	definition string
      +#
      +# @return	string
      +#
      +################################################################################
      +sub webViewControl_Define($$) {
      +	my ($hash, $def) = @_;
      +	my @a = split("[ \t][ \t]*", $def);
      +
      +	my $name = $hash->{NAME};
      +	return "wrong syntax: define  WEBVIEWCONTROL APP-ID" if int(@a)!=3;
      +
      +	$hash->{appID} = $a[2];
      +	$modules{webViewControl}{defptr}{$name} = $hash;									  
      +
      +	webViewControl_modifyJsInclude($hash);
      +
      +	$hash->{VERSION} = webViewControl_Version;
      +
      +	return undef;
      +}
      +
      +#############################
      +sub webViewControl_Undef($$) {
      +	my ($hash, $name) = @_;
      +  
      +	delete($modules{webViewControl}{defptr}{$name});
      +	webViewControl_modifyJsInclude($hash);
      +
      +  return undef;
      +}
      +
      +sub webViewControl_Attr (@) {
      +	my (undef, $name, $attr, $val) =  @_;
      +	my $hash = $defs{$name};
      +	my $msg = '';
      +
      +	if ($attr eq 'userJsFile' || $attr eq 'userCssFile') {
      +		$attr{$name}{$attr} = $val;
      +		webViewControl_modifyJsInclude($hash);
      +	}
      +
      +	return undef;
      +}
      +
      +sub webViewControl_modifyJsInclude($) {
      +	my ($hash) = @_;
      +	my $name = $hash->{NAME};
      +
      +	my @appsArray;
      +	foreach my $appName (keys %{ $modules{webViewControl}{defptr} } ) {
      +		push(@appsArray, '\'' . $modules{webViewControl}{defptr}{$appName}->{appID} . '\': \'' . $appName . '\'');
      +	}
      +
      +	my $vars = 'var wvcDevices = {' . join(', ', @appsArray) . '}';
      +	my $userJs = AttrVal($name, 'userJsFile', '');
      +	$userJs = $userJs ? '' : '';
      +
      +	my $userCss = AttrVal($name, 'userCssFile', '');
      +	if ($userCss) {
      +		$vars.= '; var wvcUserCssFile="' . $userCss . '"';  
      +	}
      +
      +	$data{FWEXT}{$fhemUrl}{SCRIPT} = 'cordova-2.3.0.js">' .
      +									 '' .
      +									 $userJs .
      +									 '' .
      +									 '