line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################################### |
2
|
|
|
|
|
|
|
# Package HiPi::Energenie::ENER314 |
3
|
|
|
|
|
|
|
# Description : Control Energenie ENER314 board |
4
|
|
|
|
|
|
|
# Copyright : Copyright (c) 2016-2017 Mark Dootson |
5
|
|
|
|
|
|
|
# License : This is free software; you can redistribute it and/or modify it under |
6
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
7
|
|
|
|
|
|
|
######################################################################################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package HiPi::Energenie::ENER314; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
######################################################################################### |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1208
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
14
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
15
|
1
|
|
|
1
|
|
9
|
use parent qw( HiPi::Class ); |
|
1
|
|
|
|
|
32
|
|
|
1
|
|
|
|
|
12
|
|
16
|
1
|
|
|
1
|
|
66
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
17
|
1
|
|
|
1
|
|
6
|
use HiPi qw( :rpi :energenie ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
440
|
|
18
|
1
|
|
|
1
|
|
429
|
use HiPi::GPIO; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
19
|
1
|
|
|
1
|
|
8
|
use Time::HiRes; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->create_accessors( qw( device signal_d0_pin signal_d1_pin signal_d2_pin signal_d3_pin |
22
|
|
|
|
|
|
|
mode_select_pin mode_enable_pin ) ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION ='0.81'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
0
|
|
|
0
|
0
|
|
my( $class, %userparams ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my %params = ( |
30
|
|
|
|
|
|
|
signal_d0_pin => RPI_PIN_11, |
31
|
|
|
|
|
|
|
signal_d1_pin => RPI_PIN_15, |
32
|
|
|
|
|
|
|
signal_d2_pin => RPI_PIN_16, |
33
|
|
|
|
|
|
|
signal_d3_pin => RPI_PIN_13, |
34
|
|
|
|
|
|
|
mode_select_pin => RPI_PIN_18, |
35
|
|
|
|
|
|
|
mode_enable_pin => RPI_PIN_22, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
foreach my $key (sort keys(%userparams)) { |
39
|
0
|
|
|
|
|
|
$params{$key} = $userparams{$key}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
unless( defined($params{device}) ) { |
43
|
0
|
|
|
|
|
|
$params{device} = HiPi::GPIO->new; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%params); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# setup defaults |
49
|
0
|
|
|
|
|
|
$self->_init(); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _init { |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->mode_enable_pin, RPI_MODE_OUTPUT ); |
58
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->mode_enable_pin, RPI_LOW ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->mode_select_pin, RPI_MODE_OUTPUT ); |
61
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->mode_select_pin, RPI_LOW ); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->signal_d0_pin, RPI_MODE_OUTPUT ); |
64
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d0_pin, RPI_LOW ); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->signal_d1_pin, RPI_MODE_OUTPUT ); |
67
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d1_pin, RPI_LOW ); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->signal_d2_pin, RPI_MODE_OUTPUT ); |
70
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d2_pin, RPI_LOW ); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->device->set_pin_mode( $self->signal_d3_pin, RPI_MODE_OUTPUT ); |
73
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d3_pin, RPI_LOW ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub send_gpio_message { |
78
|
0
|
|
|
0
|
0
|
|
my($self, $data ) = @_; |
79
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->mode_enable_pin, RPI_LOW ); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d0_pin, ( $data & 8 ) ? 1 : 0 ); |
82
|
0
|
0
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d1_pin, ( $data & 4 ) ? 1 : 0 ); |
83
|
0
|
0
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d2_pin, ( $data & 2 ) ? 1 : 0 ); |
84
|
0
|
0
|
|
|
|
|
$self->device->set_pin_level( $self->signal_d3_pin, ( $data & 1 ) ? 1 : 0 ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
Time::HiRes::sleep( 0.1 ); |
87
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->mode_enable_pin, RPI_HIGH ); |
88
|
0
|
|
|
|
|
|
Time::HiRes::sleep( 1.0 ); |
89
|
0
|
|
|
|
|
|
$self->device->set_pin_level( $self->mode_enable_pin, RPI_LOW ); |
90
|
0
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#------------------------------------------------------- |
94
|
|
|
|
|
|
|
# Common OOK switch handler |
95
|
|
|
|
|
|
|
#------------------------------------------------------- |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub switch_ook_socket { |
98
|
0
|
|
|
0
|
0
|
|
my($self, $groupid, $data, $repeat) = @_; |
99
|
|
|
|
|
|
|
# $groupid is ignored as this board has a single hard coded id |
100
|
0
|
|
|
|
|
|
$self->send_gpio_message( $data ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub DESTROY { |
104
|
0
|
|
|
0
|
|
|
my $self = shift; |
105
|
0
|
|
|
|
|
|
$self->SUPER::DESTROY; |
106
|
0
|
|
|
|
|
|
$self->device( undef ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |