File Coverage

blib/lib/Device/Chip/SSD1306/I2C.pm
Criterion Covered Total %
statement 35 40 87.5
branch n/a
condition 1 2 50.0
subroutine 9 10 90.0
pod 1 5 20.0
total 46 57 80.7


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