mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-07 22:29:19 +00:00
106 lines
2.7 KiB
Perl
Executable File
106 lines
2.7 KiB
Perl
Executable File
#############################################
|
|
package main;
|
|
|
|
use strict;
|
|
use warnings;
|
|
use Device::Firmata;
|
|
use Device::Firmata::Constants qw/ :all /;
|
|
|
|
#####################################
|
|
sub
|
|
FRM_PWM_Initialize($)
|
|
{
|
|
my ($hash) = @_;
|
|
|
|
$hash->{SetFn} = "FRM_PWM_Set";
|
|
$hash->{DefFn} = "FRM_Client_Define";
|
|
$hash->{InitFn} = "FRM_PWM_Init";
|
|
$hash->{UndefFn} = "FRM_PWM_Undef";
|
|
|
|
$hash->{AttrList} = "IODev loglevel:0,1,2,3,4,5 $main::readingFnAttributes";
|
|
}
|
|
|
|
sub
|
|
FRM_PWM_Init($$)
|
|
{
|
|
my ($hash,$args) = @_;
|
|
if (FRM_Init_Pin_Client($hash,$args,PIN_PWM)) {
|
|
my $firmata = $hash->{IODev}->{FirmataDevice};
|
|
$main::defs{$hash->{NAME}}{resolution}=$firmata->{metadata}{pwm_resolutions}{$hash->{PIN}} if (defined $firmata->{metadata}{pwm_resolutions});
|
|
main::readingsSingleUpdate($hash,"state","Initialized",1);
|
|
return undef;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
sub
|
|
FRM_PWM_Set($@)
|
|
{
|
|
my ($hash, @a) = @_;
|
|
my $value = $a[1];
|
|
my $iodev = $hash->{IODev};
|
|
if (defined $iodev and defined $iodev->{FirmataDevice} and defined $iodev->{FD}) {
|
|
$iodev->{FirmataDevice}->analog_write($hash->{PIN},$value);
|
|
main::readingsSingleUpdate($hash,"state",$a[1], 1);
|
|
} else {
|
|
return $hash->{NAME}." no IODev assigned" if (!defined $iodev);
|
|
return $hash->{NAME}.", ".$iodev->{NAME}." is not connected";
|
|
}
|
|
return undef;
|
|
}
|
|
|
|
sub
|
|
FRM_PWM_Undef($$)
|
|
{
|
|
my ($hash, $name) = @_;
|
|
}
|
|
|
|
1;
|
|
|
|
=pod
|
|
=begin html
|
|
|
|
<a name="FRM_PWM"></a>
|
|
<h3>FRM_PWM</h3>
|
|
<ul>
|
|
represents a pin of an <a href="http://www.arduino.cc">Arduino</a> running <a href="http://www.firmata.org">Firmata</a>
|
|
configured for analog output.<br>
|
|
The value set will be output by the specified pin as a pulse-width-modulated signal.<br>
|
|
Requires a defined <a href="#FRM">FRM</a>-device to work.<br><br>
|
|
|
|
<a name="FRM_PWMdefine"></a>
|
|
<b>Define</b>
|
|
<ul>
|
|
<code>define <name> FRM_PWM <pin></code> <br>
|
|
Defines the FRM_PWM device. <pin>> is the arduino-pin to use.
|
|
</ul>
|
|
|
|
<br>
|
|
<a name="FRM_PWMset"></a>
|
|
<b>Set</b><br>
|
|
<ul>
|
|
<code>set <name> <value></code><br>
|
|
sets the pulse-width of the signal that is output on the configured arduino pin<br>
|
|
Range is from 0 to 255 (see <a href="http://arduino.cc/en/Reference/AnalogWrite">analogWrite()</a> for details)
|
|
</ul>
|
|
<a name="FRM_PWMget"></a>
|
|
<b>Get</b><br>
|
|
<ul>
|
|
N/A
|
|
</ul><br>
|
|
<a name="FRM_PWMattr"></a>
|
|
<b>Attributes</b><br>
|
|
<ul>
|
|
<li><a href="#IODev">IODev</a><br>
|
|
Specify which <a href="#FRM">FRM</a> to use. (Optional, only required if there is more
|
|
than one FRM-device defined.)
|
|
</li>
|
|
<li><a href="#eventMap">eventMap</a><br></li>
|
|
<li><a href="#readingFnAttributes">readingFnAttributes</a><br></li>
|
|
</ul>
|
|
</ul>
|
|
<br>
|
|
|
|
=end html
|
|
=cut
|