| 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, 2024 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
397561
|
use v5.26; |
|
|
2
|
|
|
|
|
8
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
112
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Object::Pad 0.800; |
|
|
2
|
|
|
|
|
13
|
|
|
|
2
|
|
|
|
|
76
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
253
|
use utf8; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
14
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Device::Chip::SGP4x 0.02; |
|
13
|
|
|
|
|
|
|
class Device::Chip::SGP4x |
|
14
|
1
|
|
|
1
|
|
449
|
:isa(Device::Chip::From::Sensirion); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
140
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
410
|
use Future::AsyncAwait; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
13
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=encoding UTF-8 |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
C - chip driver for F and F |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=for highlighter language=perl |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Device::Chip::SGP4x; |
|
29
|
|
|
|
|
|
|
use Future::AsyncAwait; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $chip = Device::Chip::SGP4x->new; |
|
32
|
|
|
|
|
|
|
await $chip->mount( Device::Chip::Adapter::...->new ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
await $chip->execute_conditioning; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
while(1) { |
|
37
|
|
|
|
|
|
|
await Future::IO->sleep(1); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my ( $raw_NOx, $raw_VOC ) = await $chip->measure_raw_signals; |
|
40
|
|
|
|
|
|
|
printf "NOx = %d, VOC = %d\n", $raw_NOx, $raw_VOC; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This L subclass provides specific communication to a |
|
46
|
|
|
|
|
|
|
F F or F attached to a computer via I²C adapter. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
The reader is presumed to be familiar with the general operation of this chip; |
|
49
|
|
|
|
|
|
|
the documentation here will not attempt to explain or define chip-specific |
|
50
|
|
|
|
|
|
|
concepts or features, only the use of this module to access them. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 MOUNT PARAMETERS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 addr |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The I²C address of the device. Can be specified in decimal, octal or hex with |
|
59
|
|
|
|
|
|
|
leading C<0> or C<0x> prefixes. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
0
|
554
|
method I2C_options ( %params ) |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
64
|
|
|
|
|
|
|
{ |
|
65
|
1
|
|
50
|
|
|
8
|
my $addr = delete $params{addr} // 0x59; |
|
66
|
1
|
50
|
|
|
|
7
|
$addr = oct $addr if $addr =~ m/^0/; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return ( |
|
69
|
1
|
|
|
|
|
10
|
addr => $addr, |
|
70
|
|
|
|
|
|
|
max_bitrate => 400E3, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 METHODS |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The following methods documented in an C expression return L |
|
77
|
|
|
|
|
|
|
instances. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 execute_conditioning |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
await $chip->execute_conditioning; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Performs a conditioning operation. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
|
|
1
|
1
|
1883
|
async method execute_conditioning () |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
90
|
1
|
|
|
|
|
3
|
{ |
|
91
|
1
|
|
|
|
|
15
|
my $result = await $self->_cmd( 0x2612, |
|
92
|
|
|
|
|
|
|
words_out => [ 0x8000, 0x6666 ], |
|
93
|
|
|
|
|
|
|
delay => 0.050, |
|
94
|
|
|
|
|
|
|
read => 1, |
|
95
|
|
|
|
|
|
|
); |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
102
|
return; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 execute_self_test |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
await $chip->execute_self_test; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Performs a self-test operation. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
0
|
1
|
0
|
async method execute_self_test () |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
109
|
0
|
|
|
|
|
0
|
{ |
|
110
|
0
|
|
|
|
|
0
|
my $result = await $self->_cmd( 0x280E, delay => 0.320, read => 1 ); |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my $NOx_OK = $result & (1<<1); |
|
113
|
0
|
|
|
|
|
0
|
my $VOC_OK = $result & (1<<0); |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
0
|
die "NOx failed" if !$NOx_OK; |
|
116
|
0
|
0
|
|
|
|
0
|
die "VOC failed" if !$VOC_OK; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
return; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 measure_raw_signals |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
( $adc_VOC, $adc_NOx ) = await $chip->measure_raw_signals; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Performs a sampling cycle and returns the raw ADC values from the sensor |
|
126
|
|
|
|
|
|
|
elements. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
1
|
|
|
1
|
1
|
6649
|
async method measure_raw_signals () |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
2
|
|
|
131
|
1
|
|
|
|
|
3
|
{ |
|
132
|
|
|
|
|
|
|
# TODO: permit temp/humid compensation |
|
133
|
|
|
|
|
|
|
|
|
134
|
1
|
|
|
|
|
9
|
my @words = await $self->_cmd( 0x2619, |
|
135
|
|
|
|
|
|
|
words_out => [ 0x8000, 0x6666 ], |
|
136
|
|
|
|
|
|
|
delay => 0.050, |
|
137
|
|
|
|
|
|
|
read => 2, |
|
138
|
|
|
|
|
|
|
); |
|
139
|
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
104
|
return @words; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Paul Evans |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
0x55AA; |