Modifikationsvorschlag für 98_PID20.pm

Begonnen von abc2006, 18 Januar 2018, 00:43:21

Vorheriges Thema - Nächstes Thema

abc2006

Hi,
mich hat ein bisschen gestört, dass ich jedes mal anfangen musste zu rechnen, wenn ich den PID in Startstellung bringen wollte (p_i=0).
(z.B. weil ich das Ende eines Zyklus nicht erkannt hatte und der PID deshalb weiterlief).

Ich habe deshalb einen reset-Befehl eingebaut, der die berechneten Werte löscht.

Jetzt kann man mit
set PID20 reset
den PID zurücksetzen, ohne sich Gedanken über Readings und Werte machen zu müssen.

diff anbei, vielleicht findet es ja Zustimmung.
Grüße,
Stephan
FHEM nightly auf Intel Atom (lubuntu) mit VDSL 50000 ;-)
Nutze zur Zeit OneWire und KNX

betateilchen

Da habe ich auch gleich noch einen patch Vorschlag.
Dieser erlaubt es, mittels pidActorCallBeforeSetting auch alphanumerische Daten an den actor schicken zu können.

Aber irgendwie habe ich den Eindruck, das Modul ist momentan etwas verwaist: Letzte Änderung war im Februar 2016...


Index: 98_PID20.pm
===================================================================
--- 98_PID20.pm (Revision 16975)
+++ 98_PID20.pm (Arbeitskopie)
@@ -65,6 +65,7 @@
use strict;
use warnings;
use feature qw/say switch/;
+use Scalar::Util qw(looks_like_number);
use vars qw(%defs);
use vars qw($readingFnAttributes);
use vars qw(%attr);
@@ -683,20 +684,26 @@
       
       # check calback for actuation
       my $actorCallBeforeSetting = AttrVal( $name, 'pidActorCallBeforeSetting', undef );
+      my $actuation_new = $actuation;
       if ( defined($actorCallBeforeSetting) && exists &$actorCallBeforeSetting )
       {
         PID20_Log $hash, 5, 'start callback ' . $actorCallBeforeSetting . ' with actuation:' . $actuation;
         no strict "refs";
-        $actuation = &$actorCallBeforeSetting( $name, $actuation );
+        $actuation_new = &$actorCallBeforeSetting( $name, $actuation );
         use strict "refs";
-        PID20_Log $hash, 5, 'return value of ' . $actorCallBeforeSetting . ':' . $actuation;
+        PID20_Log $hash, 5, 'return value of ' . $actorCallBeforeSetting . ':' . $actuation_new;
       }

       #build command for fhem
       PID20_Log $hash, 5, 'actor:' . $hash->{helper}{actor} . ' actorCommand:' . $hash->{helper}{actorCommand}
-        . ' actuation:' . $actuation;
-      my $cmd = sprintf( "set %s %s %g", $hash->{helper}{actor}, $hash->{helper}{actorCommand}, $actuation );
-
+        . ' actuation:' . $actuation_new;
+      my $cmd = "";
+      if (looks_like_number($actuation_new)) {
+         $cmd = sprintf( "set %s %s %g", $hash->{helper}{actor}, $hash->{helper}{actorCommand}, $actuation_new );
+         $actuation = $actuation_new;
+      } else {
+         $cmd = sprintf( "set %s %s %s", $hash->{helper}{actor}, $hash->{helper}{actorCommand}, $actuation_new );
+      }
       # execute command
       my $ret;
       $ret = fhem $cmd;
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!