File Coverage

blib/lib/Device/Spektrum.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1             # Copyright (c) 2015, Timm Murray
2             # All rights reserved.
3             #
4             # Redistribution and use in source and binary forms, with or without
5             # modification, are permitted provided that the following conditions are
6             # met:
7             #
8             # * Redistributions of source code must retain the above copyright
9             # notice, this list of conditions and the following disclaimer.
10             # * Redistributions in binary form must reproduce the above copyright
11             # notice, this list of conditions and the following disclaimer in
12             # the documentation and/or other materials provided with the
13             # distribution.
14             #
15             # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16             # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17             # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18             # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19             # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20             # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21             # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22             # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23             # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24             # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25             # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26             #
27             package Device::Spektrum;
28             $Device::Spektrum::VERSION = '0.498225878299312';
29 1     1   683 use v5.14;
  1         3  
30 1     1   5 use warnings;
  1         2  
  1         29  
31 1     1   899 use Moose;
  1         469162  
  1         7  
32 1     1   7788 use namespace::autoclean;
  1         8443  
  1         5  
33              
34             # ABSTRACT: Send packets compatible with the Spektrum RC protoocol
35              
36              
37 1     1   58 no Moose;
  1         2  
  1         8  
38             __PACKAGE__->meta->make_immutable;
39             1;
40             __END__
41              
42              
43             =head1 NAME
44              
45             Device::Spektrum - Send packets compatible with the Spektrum RC protocol
46              
47             =head1 SYNOPSIS
48              
49             use Device::Spektrum::Packet;
50             my $packet = Device::Spektrum::Packet->new({
51             throttle => 170,
52             aileron => 200,
53             elevator => 250,
54             rudder => 800,
55             gear => SPEKTRUM_LOW,
56             aux1 => SPEKTRUM_MIDDLE,
57             aux2 => SPEKTRUM_HIGH,
58              
59             # Optional; may correct problems with buggy implementations
60             field_order => [qw(
61             throttle
62             aileron
63             elevator
64             rudder
65             gear
66             aux1
67             aux2
68             )],
69             });
70            
71             my $encoded_packet = $packet->encode_packet;
72              
73             =head1 DESCRIPTION
74              
75             Spektrum is a serial protocol that is compatible with many RC flight controllers. Using
76             this module allows you to craft output packets compatible with these flight controllers. It
77             supports up to 7 channels.
78              
79             Data is sent over a serial connection with one start bit, 8 data bits, LSB, no parity,
80             and one stop bit, all at 115.2Kbps. A 22 millisecond delay may be needed in between packets;
81             I had trouble getting the Naze32 to behave when the program sent data as fast as possible.
82              
83             The C<field_order> parameter shouldn't be necessary, because the protocol uses a few
84             identifier bits for each channel. However, some implementations out there hardcode the
85             channel order to what common Spektrum recievers put out, so you may need to work around
86             them with this parameter.
87              
88             Most of the interesting parts of the API is in L<Device::Spektrum::Packet>, so read those
89             docs for details.
90              
91             =head1 SEE ALSO
92              
93             Protocol description: L<http://www.desertrc.com/spektrum_protocol.htm>
94              
95             =head1 LICENSE
96              
97             Copyright (c) 2015, Timm Murray
98             All rights reserved.
99              
100             Redistribution and use in source and binary forms, with or without modification, are
101             permitted provided that the following conditions are met:
102              
103             * Redistributions of source code must retain the above copyright notice, this list of
104             conditions and the following disclaimer.
105             * Redistributions in binary form must reproduce the above copyright notice, this list of
106             conditions and the following disclaimer in the documentation and/or other materials
107             provided with the distribution.
108              
109             THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
110             OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
111             MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
112             COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
113             EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
114             SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
115             HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
116             TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
117             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118              
119             =cut