Gyroscope/L3GD20.pm

filter: Statementstmt 67.3% 31 / 46 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 100% 5 / 5 totaltotal 67.6% 44 / 65 CC 1 SCAR 3.6
CC
1
Cov
67%
enable
2.0
getRawReading
2.0
getReadingDegreesPerSecond
2.0
CRAP 1.4
↑ Summary L3GD20.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Device::Gyroscope::L3GD20;
5  
6 # PODNAME: Device::Gyroscope::L3GD20
7 # ABSTRACT: I2C interface to Gyroscope on the L3GD20 using Device::SMBus
8 #
9 # This file is part of Device-L3GD20
10 #
11 # This software is copyright (c) 2016 by Shantanu Bhadoria.
12 #
13 # This is free software; you can redistribute it and/or modify it under
14 # the same terms as the Perl 5 programming language system itself.
15 #
16 3 our $VERSION = '0.010'; # VERSION
17  
18 # Dependencies
19 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use Math::Trig qw(deg2rad);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 extends 'Device::SMBus';
26  
27  
28 3 has '+I2CDeviceAddress' => (
29 is => 'ro',
30 default => 0x6b,
31 );
32  
33  
34 3 has gyroscopeGain => (
35 is => 'rw',
36 default => 0.07,
37 );
38  
39  
40 3 has xZero => (
41 is => 'rw',
42 default => 0,
43 );
44  
45  
46 3 has yZero => (
47 is => 'rw',
48 default => 0,
49 );
50  
51  
52 3 has zZero => (
53 is => 'rw',
54 default => 0,
55 );
56  
57  
58 # Registers for the Gyroscope
59 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
60 3 CTRL_REG1 => 0x20,
61 CTRL_REG4 => 0x23,
62 3 };
63  
64  
65 # X, Y and Z Axis Gyroscope Data value in 2's complement
66 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
67 3 OUT_X_H => 0x29,
68 OUT_X_L => 0x28,
69  
70 OUT_Y_H => 0x2b,
71 OUT_Y_L => 0x2a,
72  
73 OUT_Z_H => 0x2d,
74 OUT_Z_L => 0x2c,
75 3 };
76  
77 #use integer; # Use arithmetic right shift instead of unsigned binary right shift with >> 4
78  
79  
80 0 ▶sub enable {
Subroutine enable: not called CC=1 SCAR=6.9
Pod documented
81 0 my ($self) = @_;
82 0 $self->writeByteData( CTRL_REG1, 0b00001111 );
83 0 $self->writeByteData( CTRL_REG4, 0b00110000 );
84 }
85  
86  
87 0 ▶sub getRawReading {
Subroutine getRawReading: not called CC=1 SCAR=6.9
Pod documented
88 0 my ($self) = @_;
89  
90 return {
91 0 x =>
92 ( $self->_typecast_int_to_int16( $self->readNBytes( OUT_X_L, 2 ) ) )
93 - $self->xZero,
94 y =>
95 ( $self->_typecast_int_to_int16( $self->readNBytes( OUT_Y_L, 2 ) ) )
96 - $self->yZero,
97 z =>
98 ( $self->_typecast_int_to_int16( $self->readNBytes( OUT_Z_L, 2 ) ) )
99 - $self->zZero,
100 };
101 }
102  
103  
104 0 ▶sub getReadingDegreesPerSecond {
Subroutine getReadingDegreesPerSecond: not called CC=1 SCAR=6.9
Pod documented
105 0 my ($self) = @_;
106  
107 0 my $gain = $self->gyroscopeGain;
108 0 my $gyro = $self->getRawReading;
109 return {
110 x => ( $gyro->{x} * $gain ),
111 y => ( $gyro->{y} * $gain ),
112 0 z => ( $gyro->{z} * $gain ),
113 };
114 }
115  
116  
117 0 ▶sub getReadingRadiansPerSecond {
Subroutine getReadingRadiansPerSecond: not called CC=1 SCAR=6.9
Pod documented
118 0 my ($self) = @_;
119  
120 0 my $gain = $self->gyroscopeGain;
121 0 my $gyro = $self->getRawReading;
122 return {
123 x => deg2rad( $gyro->{x} * $gain ),
124 y => deg2rad( $gyro->{y} * $gain ),
125 0 z => deg2rad( $gyro->{z} * $gain ),
126 };
127 }
128  
129 0 ▶sub _typecast_int_to_int16 {
Subroutine _typecast_int_to_int16: not called CC=1 SCAR=6.9
130 0 return unpack 's' => pack 'S' => $_[1];
131 }
132  
133  
134 0 ▶sub calibrate {
Subroutine calibrate: not called CC=1 SCAR=6.9
Pod documented
135 0 my ($self) = @_;
136  
137 }
138  
139 3 1;
140  
141 __END__
↑ Summary L3GD20.pm »