Skip to content

Commit

Permalink
fhem - RGB_Dimmer: add parser and set function for ColorAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Roadyweb committed Aug 11, 2014
1 parent 1aa0bdd commit e540a5e
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion host_software/fhem/37_SHCdev.pm
Expand Up @@ -332,6 +332,18 @@ sub SHCdev_Parse($$)
my $color = $parser->getField("Color");
readingsBulkUpdate($rhash, "color", $color);
}
when ('ColorAnimation') {
my $repeat = $parser->getField("Repeat");
my $autoreverse = $parser->getField("AutoReverse");
readingsBulkUpdate($rhash, "repeat", $repeat);
readingsBulkUpdate($rhash, "autoreverse", $autoreverse);
for (my $i = 0 ; $i < 10 ; $i = $i + 1) {
my $time = $parser->getField("Time" , $i);
my $color = $parser->getField("Color", $i);
readingsBulkUpdate($rhash, "time$i", $time);
readingsBulkUpdate($rhash, "color$i", $color);
}
}
}
}
}
Expand Down Expand Up @@ -508,8 +520,8 @@ sub SHCdev_Set($@)
}
}
when ('RGB_Dimmer') {
#TODO Verify argument values
if ($cmd eq 'Color') {
#TODO Verify argument values
my $color = $arg;

# DEBUG
Expand All @@ -519,6 +531,37 @@ sub SHCdev_Set($@)
$parser->initPacket("Dimmer", "Color", "SetGet");
$parser->setField("Dimmer", "Color", "Color", $color);
SHCdev_Send($hash);
} elsif ($cmd eq 'ColorAnimation') {
#TODO Verify argument values

$parser->initPacket("Dimmer", "ColorAnimation", "SetGet");
$parser->setField("Dimmer", "ColorAnimation", "Repeat", $arg);
$parser->setField("Dimmer", "ColorAnimation", "AutoReverse", $arg2);

my $curtime = 0;
my $curcolor = 0;
# Iterate over all given command line parameters and set Time and Color
# accordingly. Fill the remaining values with zero.
for (my $i = 0 ; $i < 10 ; $i = $i + 1) {
if (!defined($aa[($i * 2) + 3])) {
$curtime = 0;
} else {
$curtime = $aa[($i * 2) + 3];
}
if (!defined($aa[($i * 2) + 4])) {
$curcolor = 0;
} else {
$curcolor = $aa[($i * 2) + 4];
}

# DEBUG
# Log3 $name, 3, "$name: Nr: $i Time: $curtime Color: $curcolor";

$parser->setField("Dimmer", "ColorAnimation", "Time" , $curtime, $i);
$parser->setField("Dimmer", "ColorAnimation", "Color", $curcolor, $i);
}
readingsSingleUpdate($hash, "state", "set-coloranimation", 1);
SHCdev_Send($hash);
} else {
return SetExtensions($hash, "", $name, @aa);
}
Expand Down

0 comments on commit e540a5e

Please sign in to comment.