File Coverage

blib/lib/Device/Chip/SSD1306/I2C.pm
Criterion Covered Total %
statement 36 41 87.8
branch n/a
condition 1 2 50.0
subroutine 9 10 90.0
pod 1 4 25.0
total 47 57 82.4


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-2023 -- leonerd@leonerd.org.uk
5              
6 2     2   317106 use v5.26;
  2         10  
7 2     2   14 use warnings;
  2         5  
  2         145  
8 2     2   14 use Object::Pad 0.800;
  2         18  
  2         100  
9              
10             package Device::Chip::SSD1306::I2C 0.16;
11             class Device::Chip::SSD1306::I2C
12 1     1   951 :isa(Device::Chip::SSD1306);
  1         4  
  1         194  
13              
14 2     2   645 use constant PROTOCOL => "I2C";
  2         4  
  2         216  
15              
16 2     2   16 use constant DEFAULT_ADDR => 0x3C;
  2         5  
  2         2619  
17              
18             =encoding UTF-8
19              
20             =head1 NAME
21              
22             C - use a F OLED driver in I²C mode
23              
24             =head1 DESCRIPTION
25              
26             This L subclass provides specific communication to an
27             F chip attached via I²C.
28              
29             For actually interacting with the attached module, see the main
30             L documentation.
31              
32             =cut
33              
34             field $addr;
35              
36 1     1 1 89 method mount ( $adapter, %params )
  1         3  
  1         1  
  1         1  
  1         2  
37             {
38 1   50     5 $addr = delete $params{addr} // DEFAULT_ADDR;
39              
40 1         9 return $self->SUPER::mount( $adapter, %params );
41             }
42              
43             method I2C_options
44             {
45             return (
46             addr => $addr,
47             );
48             }
49              
50             # passthrough
51 0     0 0 0 method power ( $on ) { $self->protocol->power( $on ) }
  0         0  
  0         0  
  0         0  
  0         0  
52              
53 1     1 0 1110 method send_cmd ( @vals )
  1         5  
  1         2  
  1         1  
54             {
55 1         2 my $final = pop @vals;
56              
57 1         5 $self->protocol->write( join "", ( map { "\x80" . chr $_ } @vals ),
  2         14  
58             "\x00" . chr $final );
59             }
60              
61 1     1 0 9087 method send_data ( $bytes )
  1         3  
  1         1  
  1         1  
62             {
63 1         6 $self->protocol->write( "\x40" . $bytes )
64             }
65              
66             =head1 AUTHOR
67              
68             Paul Evans
69              
70             =cut
71              
72             0x55AA;