line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::USB::PCSensor::HidTEMPer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14577
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1346
|
use Device::USB; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::Device; |
8
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::NTC; |
9
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::TEMPer; |
10
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::TEMPer2; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Device::USB::PCSensor::HidTEMPer - Device overview |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 0.04 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 0.04; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Shared code: |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer; |
29
|
|
|
|
|
|
|
my $pcsensor = Device::USB::PCSensor::HidTEMPer->new(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Single-device systems: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $device = $pcsensor->device(); |
34
|
|
|
|
|
|
|
print $device->external()->fahrenheit() if defined $device->external(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Multi-device systems: |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @devices = $pcsensor->list_devices(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
foreach my $device ( @devices ){ |
41
|
|
|
|
|
|
|
print $device->internal()->celsius() if defined $device->internal(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module is a simplified interface to the HidTEMPer thermometers created |
47
|
|
|
|
|
|
|
by PCSensor. It hides any problems recognizing the correct objects to |
48
|
|
|
|
|
|
|
initialize and the dependency on Device::USB. Use of the connected |
49
|
|
|
|
|
|
|
thermometers can be done by either creating a array of objects if |
50
|
|
|
|
|
|
|
multiple devices are connected, or the function device() if |
51
|
|
|
|
|
|
|
only one device is present. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
One example of its usage can be found in the Linux Journal August 2010, |
54
|
|
|
|
|
|
|
"Cool Projects edition" page 32-34. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 CONSTANTS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The following constants are declared |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 3 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * PRODUCT_ID |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Contains the hex value of the product id on the usb chip, in this case 0x660c |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use constant PRODUCT_ID => 0x660c; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * VENDOR_ID |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Contains the hex value representing the manufacturer of the chip, in this |
73
|
|
|
|
|
|
|
case "Tenx Technology, Inc." |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use constant VENDOR_ID => 0x1130; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * SUPPORTED_DEVICES |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Contains the mapping between name and identifiers for all supported |
82
|
|
|
|
|
|
|
thermometers. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Hex value Product Internal sensor External sensor |
85
|
|
|
|
|
|
|
0x5b HidTEMPerNTC Yes Yes |
86
|
|
|
|
|
|
|
0x58 HidTEMPer Yes No |
87
|
|
|
|
|
|
|
0x59 HidTEMPer2 Yes Yes |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use constant SUPPORTED_DEVICES => { |
94
|
|
|
|
|
|
|
0x5b => { |
95
|
|
|
|
|
|
|
'name' => 'HidTEMPerNTC', |
96
|
|
|
|
|
|
|
'module' => 'Device::USB::PCSensor::HidTEMPer::NTC' |
97
|
|
|
|
|
|
|
}, |
98
|
|
|
|
|
|
|
0x58 => { |
99
|
|
|
|
|
|
|
'name' => 'HidTEMPer', |
100
|
|
|
|
|
|
|
'module' => 'Device::USB::PCSensor::HidTEMPer::TEMPer' |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
0x59 => { |
103
|
|
|
|
|
|
|
'name' => 'HidTEMPer2', |
104
|
|
|
|
|
|
|
'module' => 'Device::USB::PCSensor::HidTEMPer::TEMPer2' |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 METHODS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 3 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * new() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Initialize the system, and the USB-connection to be used. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub new |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
my $class = shift; |
121
|
|
|
|
|
|
|
my $self = { |
122
|
|
|
|
|
|
|
'usb' => Device::USB->new() |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
return bless $self, $class; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * device() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Return a single thermometer instance. ONLY to be used in systems using a |
131
|
|
|
|
|
|
|
single thermometer device. Returns undef if no devices was found. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub device |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
my $device = $self->{usb}->find_device( VENDOR_ID, PRODUCT_ID ); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
return undef unless defined $device; |
141
|
|
|
|
|
|
|
return _init_device($device); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * list_devices() |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns an array of recognized thermometer instances if an array value is |
147
|
|
|
|
|
|
|
expected, otherwise it returns a scalar with the number of devices found. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub list_devices |
152
|
|
|
|
|
|
|
{ |
153
|
|
|
|
|
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
my @list = (); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
@list = grep( defined($_), |
157
|
|
|
|
|
|
|
map( _init_device($_), |
158
|
|
|
|
|
|
|
$self->{usb}->list_devices( VENDOR_ID, |
159
|
|
|
|
|
|
|
PRODUCT_ID ))); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
return wantarray() ? return @list : scalar @list; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# This functions detects the correct object to be created and returned. |
165
|
|
|
|
|
|
|
# Returns undef if not supported device was found. |
166
|
|
|
|
|
|
|
sub _init_device |
167
|
|
|
|
|
|
|
{ |
168
|
|
|
|
|
|
|
my $prototype = Device::USB::PCSensor::HidTEMPer::Device->new( $_[0] ); |
169
|
|
|
|
|
|
|
my $parameters = SUPPORTED_DEVICES->{$prototype->identifier()}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
return undef unless defined $parameters; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
bless $prototype, $parameters->{module}; |
174
|
|
|
|
|
|
|
return $prototype->init(); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This module internally includes and takes use of the following packages: |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
use Device::USB; |
184
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::Device; |
185
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::NTC; |
186
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::TEMPer; |
187
|
|
|
|
|
|
|
use Device::USB::PCSensor::HidTEMPer::TEMPer2; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This module uses the strict and warning pragmas. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 BUGS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Please report any bugs or missing features using the CPAN RT tool. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 FOR MORE INFORMATION |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
None |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Magnus Sulland < msulland@cpan.org > |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Thanks to Elan Ruusamäe for fixing some compatibility issues with perl 5.8. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Thanks to Daniel Fahlgren for adding the TEMPer2 device. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Copyright (c) 2010-2011 Magnus Sulland |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
214
|
|
|
|
|
|
|
under the same terms as Perl itself. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; |