mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
fix servo
git-svn-id: https://svn.fhem.de/fhem/trunk@2635 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
41eaede2c6
commit
7b62d329f9
@ -20,7 +20,7 @@ sub FRM_Initialize($) {
|
||||
|
||||
# Provider
|
||||
$hash->{Clients} =
|
||||
":FRM_IN:FRM_OUT:FRM_AD:FRM_PWM:FRM_I2C:OWX:";
|
||||
":FRM_IN:FRM_OUT:FRM_AD:FRM_PWM:FRM_I2C:FRM_SERVO:OWX:";
|
||||
$hash->{ReadyFn} = "FRM_Ready";
|
||||
$hash->{ReadFn} = "FRM_Read";
|
||||
|
||||
|
@ -7,6 +7,11 @@ use Device::Firmata;
|
||||
use Device::Firmata::Constants qw/ :all /;
|
||||
|
||||
#####################################
|
||||
|
||||
my %sets = (
|
||||
"value" => "",
|
||||
);
|
||||
|
||||
sub
|
||||
FRM_PWM_Initialize($)
|
||||
{
|
||||
@ -37,7 +42,11 @@ sub
|
||||
FRM_PWM_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $value = $a[1];
|
||||
return "Need at least one parameters" if(@a < 2);
|
||||
return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets)
|
||||
if(!defined($sets{$a[1]}));
|
||||
my $command = $a[1];
|
||||
my $value = $a[2];
|
||||
my $iodev = $hash->{IODev};
|
||||
if (defined $iodev and defined $iodev->{FirmataDevice} and defined $iodev->{FD}) {
|
||||
$iodev->{FirmataDevice}->analog_write($hash->{PIN},$value);
|
||||
@ -79,7 +88,7 @@ FRM_PWM_Undef($$)
|
||||
<a name="FRM_PWMset"></a>
|
||||
<b>Set</b><br>
|
||||
<ul>
|
||||
<code>set <name> <value></code><br>
|
||||
<code>set <name> value <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>
|
||||
|
@ -7,6 +7,11 @@ use Device::Firmata;
|
||||
use Device::Firmata::Constants qw/ :all /;
|
||||
|
||||
#####################################
|
||||
|
||||
my %sets = (
|
||||
"angle" => "",
|
||||
);
|
||||
|
||||
sub
|
||||
FRM_SERVO_Initialize($)
|
||||
{
|
||||
@ -60,7 +65,11 @@ sub
|
||||
FRM_SERVO_Set($@)
|
||||
{
|
||||
my ($hash, @a) = @_;
|
||||
my $value = $a[1];
|
||||
return "Need at least one parameters" if(@a < 2);
|
||||
return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets)
|
||||
if(!defined($sets{$a[1]}));
|
||||
my $command = $a[1];
|
||||
my $value = $a[2];
|
||||
my $iodev = $hash->{IODev};
|
||||
if (defined $iodev and defined $iodev->{FirmataDevice} and defined $iodev->{FD}) {
|
||||
$iodev->{FirmataDevice}->servo_write($hash->{PIN},$value);
|
||||
@ -102,7 +111,7 @@ FRM_SERVO_Undef($$)
|
||||
<a name="FRM_SERVOset"></a>
|
||||
<b>Set</b><br>
|
||||
<ul>
|
||||
<code>set <name> <value></code><br>sets the angle of the servo-motors shaft to the value specified (in degrees).<br>
|
||||
<code>set <name> angle <value></code><br>sets the angle of the servo-motors shaft to the value specified (in degrees).<br>
|
||||
</ul>
|
||||
<a name="FRM_SERVOget"></a>
|
||||
<b>Get</b><br>
|
||||
|
@ -436,7 +436,7 @@ sub pin_mode {
|
||||
last;
|
||||
};
|
||||
|
||||
( $mode == PIN_PWM || $mode == PIN_I2C || $mode == PIN_ONEWIRE ) and do {
|
||||
( $mode == PIN_PWM || $mode == PIN_I2C || $mode == PIN_ONEWIRE || $mode == PIN_SERVO ) and do {
|
||||
$self->{io}->data_write($self->{protocol}->message_prepare( SET_PIN_MODE => 0, $pin, $mode ));
|
||||
last;
|
||||
};
|
||||
@ -594,9 +594,17 @@ sub i2c_config {
|
||||
}
|
||||
|
||||
sub servo_write {
|
||||
|
||||
# --------------------------------------------------
|
||||
# Sets the SERVO value on an arduino
|
||||
#
|
||||
my ( $self, $pin, $value ) = @_;
|
||||
return undef unless $self->is_configured_mode($pin,PIN_SERVO);
|
||||
return analog_write( $self, $pin, $value );
|
||||
|
||||
# FIXME: 8 -> 7 bit translation should be done in the protocol module
|
||||
my $byte_0 = $value & 0x7f;
|
||||
my $byte_1 = $value >> 7;
|
||||
return $self->{io}->data_write($self->{protocol}->message_prepare( ANALOG_MESSAGE => $pin, $byte_0, $byte_1 ));
|
||||
}
|
||||
|
||||
sub servo_config {
|
||||
|
Loading…
x
Reference in New Issue
Block a user