| 1 | package RPi::LCD; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | our $VERSION = '3.1801'; | ||
| 7 | |||
| 8 | 1 | ▶ | use parent 'WiringPi::API'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | use Carp qw(confess); | ||
| 10 | use RPi::Const qw(:all); | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $self = bless {}, shift; | ||
| 14 | if (! defined $ENV{RPI_PIN_MODE}){ | ||
| 15 | $ENV{RPI_PIN_MODE} = RPI_MODE_GPIO; | ||
| 16 | $self->setup_gpio; | ||
| 17 | } | ||
| 18 | return $self; | ||
| 19 | } | ||
| 20 | sub init { | ||
| 21 | my ($self, %params) = @_; | ||
| 22 | |||
| 23 | my @required_args = qw( | ||
| 24 | rows cols bits rs strb | ||
| 25 | d0 d1 d2 d3 d4 d5 d6 d7 | ||
| 26 | ); | ||
| 27 | |||
| 28 | for (@required_args){ | ||
| 29 | if (! defined $params{$_}) { | ||
| 30 | die "\n'$_' is a required param for ::LCD::lcd_init()\n"; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | my $fd = $self->lcd_init(%params); | ||
| 35 | |||
| 36 | $self->_fd($fd); | ||
| 37 | |||
| 38 | return $self->_fd(); | ||
| 39 | } | ||
| 40 | sub home { | ||
| 41 | $_[0]->lcd_home($_[0]->_fd); | ||
| 42 | } | ||
| 43 | sub clear { | ||
| 44 | $_[0]->lcd_clear($_[0]->_fd); | ||
| 45 | } | ||
| 46 | sub display { | ||
| 47 | my ($self, $state) = @_; | ||
| 48 | $self->lcd_display($self->_fd, $state); | ||
| 49 | } | ||
| 50 | sub cursor { | ||
| 51 | my ($self, $state) = @_; | ||
| 52 | $self->lcd_cursor($self->_fd, $state); | ||
| 53 | } | ||
| 54 | sub cursor_blink { | ||
| 55 | my ($self, $state) = @_; | ||
| 56 | $self->lcd_cursor_blink($self->_fd, $state); | ||
| 57 | } | ||
| 58 | sub send_cmd { | ||
| 59 | my ($self, $cmd) = @_; | ||
| 60 | $self->lcd_send_cmd($self->_fd, $cmd); | ||
| 61 | } | ||
| 62 | sub position { | ||
| 63 | my ($self, $x, $y) = @_; | ||
| 64 | $self->lcd_position($self->_fd, $x, $y); | ||
| 65 | } | ||
| 66 | sub char_def { | ||
| 67 | my ($self, $index, $data) = @_; | ||
| 68 | $self->lcd_char_def($self->_fd, $index, $data); | ||
| 69 | } | ||
| 70 | |||
| 71 | *print_char = \&put_char; | ||
| 72 | |||
| 73 | sub put_char { | ||
| 74 | my ($self, $data) = @_; | ||
| 75 | $self->lcd_put_char($self->_fd, $data); | ||
| 76 | } | ||
| 77 | |||
| 78 | *print = \&puts; | ||
| 79 | |||
| 80 | sub puts { | ||
| 81 | my ($self, $string) = @_; | ||
| 82 | $self->lcd_puts($self->_fd, $string); | ||
| 83 | } | ||
| 84 | sub _fd { | ||
| 85 | my ($self, $fd) = @_; | ||
| 86 | if (defined $fd){ | ||
| 87 | if ($fd == -1){ | ||
| 88 | confess "\nMaximum number of LCDs (8) in use. Can't continue...\n" . | ||
| 89 | "Are you instantiating LCD objects within a loop?\n\n"; | ||
| 90 | } | ||
| 91 | $self->{fd} = $fd; | ||
| 92 | } | ||
| 93 | return $self->{fd} | ||
| 94 | } | ||
| 95 | sub __placeholder {} # vim folds | ||
| 96 | |||
| 97 | 1; | ||
| 98 | __END__ | ||