File Coverage

blib/lib/Device/BusPirate/Chip/SSD1306/I2C.pm
Criterion Covered Total %
statement 18 32 56.2
branch n/a
condition 0 2 0.0
subroutine 6 9 66.6
pod 1 3 33.3
total 25 46 54.3


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2015 -- leonerd@leonerd.org.uk
5              
6             package Device::BusPirate::Chip::SSD1306::I2C;
7              
8 1     1   773 use strict;
  1         1  
  1         31  
9 1     1   4 use warnings;
  1         1  
  1         24  
10 1     1   3 use base qw( Device::BusPirate::Chip::SSD1306 );
  1         2  
  1         91  
11              
12             our $VERSION = '0.01';
13              
14 1     1   4 use constant CHIP => "SSD1306-I2C";
  1         2  
  1         41  
15 1     1   4 use constant MODE => "I2C";
  1         1  
  1         41  
16              
17 1     1   4 use constant DEFAULT_ADDR => 0x3C;
  1         2  
  1         201  
18              
19             =head1 NAME
20              
21             C - use a F OLED driver in I2C mode
22              
23             =head1 DESCRIPTION
24              
25             This L subclass provides specific
26             communication to an F chip attached to the F via I2C.
27              
28             The chip name for this module is C.
29              
30             For actually interacting with the attached module, see the main
31             L documentation.
32              
33             =cut
34              
35             sub new
36             {
37 0     0 1   my $class = shift;
38 0           my ( $bp, %opts ) = @_;
39              
40 0           my $self = $class->SUPER::new( @_ );
41              
42 0           $self->{$_} = $opts{$_} for qw( address );
43              
44 0   0       $self->{address} //= DEFAULT_ADDR;
45              
46 0           return $self;
47             }
48              
49             sub send_cmd
50             {
51 0     0 0   my $self = shift;
52 0           my @vals = @_;
53              
54 0           my $final = pop @vals;
55              
56 0           $self->mode->send( $self->{address}, join "", ( map { "\x80" . chr $_ } @vals ),
  0            
57             "\x00" . chr $final );
58             }
59              
60             sub send_data
61             {
62 0     0 0   my $self = shift;
63 0           my ( $bytes ) = @_;
64              
65 0           $self->mode->send( $self->{address}, "\x40" . $_[0] )
66             }
67              
68             =head1 TODO
69              
70             Note that this module isn't actually fully tested on real hardware, as the
71             author currently lacks an F module with a working I2C interface.
72              
73             =head1 AUTHOR
74              
75             Paul Evans
76              
77             =cut
78              
79             0x55AA;