File Coverage

blib/lib/Device/Chip/SSD1306/I2C.pm
Criterion Covered Total %
statement 38 43 88.3
branch n/a
condition 1 2 50.0
subroutine 10 11 90.9
pod 1 5 20.0
total 50 61 81.9


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   263689 use v5.26;
  2         12  
7 2     2   10 use warnings;
  2         4  
  2         54  
8 2     2   8 use Object::Pad 0.800;
  2         12  
  2         77  
9              
10             package Device::Chip::SSD1306::I2C 0.14;
11             class Device::Chip::SSD1306::I2C
12 1     1   509 :isa(Device::Chip::SSD1306);
  1         2  
  1         32  
13              
14 2     2   416 use constant PROTOCOL => "I2C";
  2         3  
  2         107  
15              
16 2     2   11 use constant DEFAULT_ADDR => 0x3C;
  2         3  
  2         1250  
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         2 method mount ( $adapter, %params )
  1         2  
  1         2  
  1         2  
37 1     1 1 65 {
38 1   50     6 $addr = delete $params{addr} // DEFAULT_ADDR;
39              
40 1         18 return $self->SUPER::mount( $adapter, %params );
41             }
42              
43             method I2C_options
44 1     1 0 312 {
45             return (
46 1         4 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         2 method send_cmd ( @vals )
  1         2  
  1         1  
54 1     1 0 263 {
55 1         2 my $final = pop @vals;
56              
57 1         4 $self->protocol->write( join "", ( map { "\x80" . chr $_ } @vals ),
  2         15  
58             "\x00" . chr $final );
59             }
60              
61 1         3 method send_data ( $bytes )
  1         2  
  1         1  
62 1     1 0 10909 {
63 1         4 $self->protocol->write( "\x40" . $bytes )
64             }
65              
66             =head1 AUTHOR
67              
68             Paul Evans
69              
70             =cut
71              
72             0x55AA;