File Coverage

blib/lib/Device/WebIO.pm
Criterion Covered Total %
statement 304 304 100.0
branch 26 30 86.6
condition 17 27 62.9
subroutine 65 65 100.0
pod 52 57 91.2
total 464 483 96.0


line stmt bran cond sub pod time code
1             # Copyright (c) 2014 Timm Murray
2             # All rights reserved.
3             #
4             # Redistribution and use in source and binary forms, with or without
5             # modification, are permitted provided that the following conditions are met:
6             #
7             # * Redistributions of source code must retain the above copyright notice,
8             # this list of conditions and the following disclaimer.
9             # * Redistributions in binary form must reproduce the above copyright
10             # notice, this list of conditions and the following disclaimer in the
11             # documentation and/or other materials provided with the distribution.
12             #
13             # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14             # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15             # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16             # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17             # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18             # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19             # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20             # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21             # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22             # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23             # POSSIBILITY OF SUCH DAMAGE.
24             package Device::WebIO;
25             $Device::WebIO::VERSION = '0.010';
26             # ABSTRACT: Duct Tape for the Internet of Things
27 14     14   141564 use v5.12;
  14         32  
  14         456  
28 14     14   4324 use Moo;
  14         101017  
  14         57  
29 14     14   16762 use namespace::clean;
  14         106171  
  14         59  
30 14     14   5950 use Device::WebIO::Exceptions;
  14         21  
  14         33083  
31              
32             has '_device_by_name' => (
33             is => 'ro',
34             default => sub {{
35             }},
36             );
37              
38              
39             sub register
40             {
41 13     13 1 947 my ($self, $name, $device) = @_;
42 13         66 $self->_device_by_name->{$name} = $device;
43 13         24 return 1;
44             }
45              
46              
47             sub pin_desc
48             {
49 1     1 1 3 my ($self, $name) = @_;
50 1         2 my $obj = $self->_get_obj( $name );
51 1         6 return $obj->pin_desc;
52             }
53              
54             sub all_desc
55             {
56 2     2 1 872 my ($self, $name) = @_;
57 2         3 my $obj = $self->_get_obj( $name );
58 2         5 return $obj->all_desc;
59             }
60              
61              
62             sub set_as_input
63             {
64 7     7 1 1298 my ($self, $name, $pin) = @_;
65 7         14 my $obj = $self->_get_obj( $name );
66 7         11 $self->_role_check( $obj, 'DigitalInput' );
67 7         10 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
68 6         14 $obj->set_as_input( $pin );
69 6         25 return 1;
70             }
71              
72             sub set_as_output
73             {
74 5     5 1 1451 my ($self, $name, $pin) = @_;
75 5         9 my $obj = $self->_get_obj( $name );
76 5         8 $self->_role_check( $obj, 'DigitalOutput' );
77 5         9 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
78 3         7 $obj->set_as_output( $pin );
79 3         12 return 1;
80             }
81              
82             sub is_set_input
83             {
84 8     8 1 1243 my ($self, $name, $pin) = @_;
85 8         15 my $obj = $self->_get_obj( $name );
86 8         14 $self->_role_check( $obj, 'DigitalInput' );
87 8         13 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
88 8         42 return $obj->is_set_input( $pin );
89             }
90              
91             sub is_set_output
92             {
93 4     4 1 534 my ($self, $name, $pin) = @_;
94 4         7 my $obj = $self->_get_obj( $name );
95 4         7 $self->_role_check( $obj, 'DigitalOutput' );
96 4         7 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
97 4         9 return $obj->is_set_output( $pin );
98             }
99              
100             sub digital_input_pin_count
101             {
102 3     3 1 445 my ($self, $name) = @_;
103 3         6 my $obj = $self->_get_obj( $name );
104 3         7 $self->_role_check( $obj, 'DigitalInput' );
105 3         8 my $count = $obj->input_pin_count;
106 3         11 return $count;
107             }
108              
109             sub digital_output_pin_count
110             {
111 2     2 1 348 my ($self, $name) = @_;
112 2         4 my $obj = $self->_get_obj( $name );
113 2         4 $self->_role_check( $obj, 'DigitalOutput' );
114 2         5 my $count = $obj->output_pin_count;
115 2         9 return $count;
116             }
117              
118             sub digital_input
119             {
120 5     5 1 1040 my ($self, $name, $pin) = @_;
121 5         8 my $obj = $self->_get_obj( $name );
122 5         10 $self->_role_check( $obj, 'DigitalInput' );
123 4         6 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
124 3         5 return $obj->input_pin( $pin );
125             }
126              
127             sub digital_input_port
128             {
129 2     2 1 176 my ($self, $name) = @_;
130 2         4 my $obj = $self->_get_obj( $name );
131 2         4 $self->_role_check( $obj, 'DigitalInput' );
132 2         6 return $obj->input_port;
133             }
134              
135             sub digital_input_callback
136             {
137 3     3 1 5 my ($self, $name, $pin, $type, $callback) = @_;
138 3         6 my $obj = $self->_get_obj( $name );
139 3         5 $self->_role_check( $obj, 'DigitalInputCallback' );
140 3         4 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInputCallback' );
141 3         6 return $obj->input_callback_pin( $pin, $type, $callback );
142             }
143              
144             sub digital_input_begin_loop
145             {
146 1     1 1 2 my ($self, $name) = @_;
147 1         2 my $obj = $self->_get_obj( $name );
148 1         3 $self->_role_check( $obj, 'DigitalInputCallback' );
149 1         2 return $obj->input_begin_loop();
150             }
151              
152             sub digital_output_port
153             {
154 2     2 1 4 my ($self, $name, $out) = @_;
155 2         5 my $obj = $self->_get_obj( $name );
156 2         4 $self->_role_check( $obj, 'DigitalOutput' );
157 2         6 $obj->output_port( $out );
158 2         3 return 1;
159             }
160              
161             sub digital_output
162             {
163 7     7 1 1321 my ($self, $name, $pin, $val) = @_;
164 7         15 my $obj = $self->_get_obj( $name );
165 7         12 $self->_role_check( $obj, 'DigitalOutput' );
166 4         6 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
167 3         6 $obj->output_pin( $pin, $val );
168 3         12 return 1;
169             }
170              
171             sub adc_count
172             {
173 1     1 1 3 my ($self, $name) = @_;
174 1         2 my $obj = $self->_get_obj( $name );
175 1         2 $self->_role_check( $obj, 'ADC' );
176 1         4 return $obj->adc_pin_count;
177             }
178              
179             sub adc_resolution
180             {
181 2     2 1 236 my ($self, $name, $pin) = @_;
182 2         5 my $obj = $self->_get_obj( $name );
183 2         2 $self->_role_check( $obj, 'ADC' );
184 2         5 return $obj->adc_bit_resolution( $pin );
185             }
186              
187             sub adc_max_int
188             {
189 2     2 1 505 my ($self, $name, $pin) = @_;
190 2         3 my $obj = $self->_get_obj( $name );
191 2         4 $self->_role_check( $obj, 'ADC' );
192 2         5 return $obj->adc_max_int( $pin );
193             }
194              
195             sub adc_volt_ref
196             {
197 2     2 1 4 my ($self, $name, $pin) = @_;
198 2         3 my $obj = $self->_get_obj( $name );
199 2         2 $self->_role_check( $obj, 'ADC' );
200 2         4 return $obj->adc_volt_ref( $pin );
201             }
202              
203             sub adc_input_int
204             {
205 4     4 1 735 my ($self, $name, $pin) = @_;
206 4         6 my $obj = $self->_get_obj( $name );
207 4         7 $self->_role_check( $obj, 'ADC' );
208 4         5 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
209 3         6 return $obj->adc_input_int( $pin );
210             }
211              
212             sub adc_input_float
213             {
214 3     3 1 530 my ($self, $name, $pin) = @_;
215 3         6 my $obj = $self->_get_obj( $name );
216 3         6 $self->_role_check( $obj, 'ADC' );
217 3         7 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
218 2         5 return $obj->adc_input_float( $pin );
219             }
220              
221             sub adc_input_volts
222             {
223 3     3 1 208 my ($self, $name, $pin) = @_;
224 3         4 my $obj = $self->_get_obj( $name );
225 3         4 $self->_role_check( $obj, 'ADC' );
226 3         6 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
227 2         5 return $obj->adc_input_volts( $pin );
228             }
229              
230             sub pwm_count
231             {
232 1     1 1 3 my ($self, $name) = @_;
233 1         3 my $obj = $self->_get_obj( $name );
234 1         3 $self->_role_check( $obj, 'PWM' );
235 1         4 return $obj->pwm_pin_count;
236             }
237              
238             sub pwm_resolution
239             {
240 2     2 1 3 my ($self, $name, $pin) = @_;
241 2         4 my $obj = $self->_get_obj( $name );
242 2         3 $self->_role_check( $obj, 'PWM' );
243 2         5 return $obj->pwm_bit_resolution( $pin );
244             }
245              
246             sub pwm_max_int
247             {
248 2     2 1 474 my ($self, $name, $pin) = @_;
249 2         4 my $obj = $self->_get_obj( $name );
250 2         5 $self->_role_check( $obj, 'PWM' );
251 2         5 return $obj->pwm_max_int( $pin );
252             }
253              
254             sub pwm_output_int
255             {
256 3     3 1 736 my ($self, $name, $pin, $value) = @_;
257 3         5 my $obj = $self->_get_obj( $name );
258 3         5 $self->_role_check( $obj, 'PWM' );
259 3         6 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
260 2         4 return $obj->pwm_output_int( $pin, $value );
261             }
262              
263             sub pwm_output_float
264             {
265 2     2 1 288 my ($self, $name, $pin, $value) = @_;
266 2         12 my $obj = $self->_get_obj( $name );
267 2         3 $self->_role_check( $obj, 'PWM' );
268 2         4 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
269 1         3 return $obj->pwm_output_float( $pin, $value );
270             }
271              
272             sub vid_channels
273             {
274 1     1 1 755 my ($self, $name) = @_;
275 1         2 my $obj = $self->_get_obj( $name );
276 1         3 $self->_role_check( $obj, 'VideoOutput' );
277 1         2 return $obj->vid_channels;
278             }
279              
280             sub vid_width
281             {
282 2     2 1 341 my ($self, $name, $pin) = @_;
283 2         3 my $obj = $self->_get_obj( $name );
284 2         4 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
285 2         4 $self->_role_check( $obj, 'VideoOutput' );
286 2         4 return $obj->vid_width( $pin );
287             }
288              
289             sub vid_height
290             {
291 2     2 1 691 my ($self, $name, $pin) = @_;
292 2         5 my $obj = $self->_get_obj( $name );
293 2         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
294 2         3 $self->_role_check( $obj, 'VideoOutput' );
295 2         3 return $obj->vid_height( $pin );
296             }
297              
298             sub vid_fps
299             {
300 2     2 1 652 my ($self, $name, $pin) = @_;
301 2         4 my $obj = $self->_get_obj( $name );
302 2         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
303 2         2 $self->_role_check( $obj, 'VideoOutput' );
304 2         3 return $obj->vid_fps( $pin );
305             }
306              
307             sub vid_kbps
308             {
309 2     2 1 655 my ($self, $name, $pin) = @_;
310 2         4 my $obj = $self->_get_obj( $name );
311 2         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
312 2         3 $self->_role_check( $obj, 'VideoOutput' );
313 2         6 return $obj->vid_kbps( $pin );
314             }
315              
316             sub vid_set_width
317             {
318 1     1 1 322 my ($self, $name, $pin, $value) = @_;
319 1         2 my $obj = $self->_get_obj( $name );
320 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
321 1         2 $self->_role_check( $obj, 'VideoOutput' );
322 1         3 return $obj->vid_set_width( $pin, $value );
323             }
324              
325             sub vid_set_height
326             {
327 1     1 1 6 my ($self, $name, $pin, $value) = @_;
328 1         2 my $obj = $self->_get_obj( $name );
329 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
330 1         2 $self->_role_check( $obj, 'VideoOutput' );
331 1         3 return $obj->vid_set_height( $pin, $value );
332             }
333              
334             sub vid_set_fps
335             {
336 1     1 0 5 my ($self, $name, $pin, $value) = @_;
337 1         2 my $obj = $self->_get_obj( $name );
338 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
339 1         1 $self->_role_check( $obj, 'VideoOutput' );
340 1         2 return $obj->vid_set_fps( $pin, $value );
341             }
342              
343             sub vid_set_kbps
344             {
345 1     1 0 5 my ($self, $name, $pin, $value) = @_;
346 1         2 my $obj = $self->_get_obj( $name );
347 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
348 1         2 $self->_role_check( $obj, 'VideoOutput' );
349 1         3 return $obj->vid_set_kbps( $pin, $value );
350             }
351              
352             sub vid_allowed_content_types
353             {
354 1     1 1 320 my ($self, $name, $pin) = @_;
355 1         2 my $obj = $self->_get_obj( $name );
356 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
357 1         2 $self->_role_check( $obj, 'VideoOutput' );
358 1         3 return $obj->vid_allowed_content_types( $pin );
359             }
360              
361             sub vid_stream
362             {
363 1     1 1 267 my ($self, $name, $pin, $type) = @_;
364 1         2 my $obj = $self->_get_obj( $name );
365 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
366 1         2 $self->_role_check( $obj, 'VideoOutput' );
367 1         2 return $obj->vid_stream( $pin, $type );
368             }
369              
370             sub vid_stream_callback
371             {
372 1     1 1 648 my ($self, $name, $pin, $type, $callback) = @_;
373 1         3 my $obj = $self->_get_obj( $name );
374 1         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
375 1         3 $self->_role_check( $obj, 'VideoOutputCallback' );
376 1         3 return $obj->vid_stream_callback( $pin, $type, $callback );
377             }
378              
379             sub vid_stream_begin_loop
380             {
381 1     1 1 269 my ($self, $name, $pin) = @_;
382 1         2 my $obj = $self->_get_obj( $name );
383 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
384 1         2 $self->_role_check( $obj, 'VideoOutputCallback' );
385 1         3 return $obj->vid_stream_begin_loop( $pin );
386             }
387              
388             sub img_channels
389             {
390 1     1 1 4 my ($self, $name) = @_;
391 1         3 my $obj = $self->_get_obj( $name );
392 1         3 $self->_role_check( $obj, 'StillImageOutput' );
393 1         3 return $obj->img_channels;
394             }
395              
396             sub img_width
397             {
398 2     2 1 328 my ($self, $name, $pin) = @_;
399 2         4 my $obj = $self->_get_obj( $name );
400 2         3 $self->_role_check( $obj, 'StillImageOutput' );
401 2         4 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
402 2         5 return $obj->img_width( $pin );
403             }
404              
405             sub img_height
406             {
407 2     2 1 508 my ($self, $name, $pin) = @_;
408 2         5 my $obj = $self->_get_obj( $name );
409 2         4 $self->_role_check( $obj, 'StillImageOutput' );
410 2         3 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
411 2         5 return $obj->img_height( $pin );
412             }
413              
414             sub img_quality
415             {
416 2     2 1 478 my ($self, $name, $pin) = @_;
417 2         5 my $obj = $self->_get_obj( $name );
418 2         3 $self->_role_check( $obj, 'StillImageOutput' );
419 2         3 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
420 2         5 return $obj->img_quality( $pin );
421             }
422              
423             sub img_set_width
424             {
425 1     1 1 237 my ($self, $name, $pin, $value) = @_;
426 1         3 my $obj = $self->_get_obj( $name );
427 1         3 $self->_role_check( $obj, 'StillImageOutput' );
428 1         2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
429 1         3 return $obj->img_set_width( $pin, $value );
430             }
431              
432             sub img_set_height
433             {
434 1     1 1 5 my ($self, $name, $pin, $value) = @_;
435 1         2 my $obj = $self->_get_obj( $name );
436 1         5 $self->_role_check( $obj, 'StillImageOutput' );
437 1         2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
438 1         3 return $obj->img_set_height( $pin, $value );
439             }
440              
441             sub img_set_quality
442             {
443 1     1 1 6 my ($self, $name, $pin, $value) = @_;
444 1         2 my $obj = $self->_get_obj( $name );
445 1         2 $self->_role_check( $obj, 'StillImageOutput' );
446 1         2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
447 1         2 return $obj->img_set_quality( $pin, $value );
448             }
449              
450             sub img_allowed_content_types
451             {
452 1     1 1 240 my ($self, $name, $pin) = @_;
453 1         3 my $obj = $self->_get_obj( $name );
454 1         2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
455 1         3 return $obj->img_allowed_content_types( $pin );
456             }
457              
458             sub img_stream
459             {
460 1     1 1 187 my ($self, $name, $pin, $type) = @_;
461 1         2 my $obj = $self->_get_obj( $name );
462 1         2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
463 1         2 return $obj->img_stream( $pin, $type );
464             }
465              
466             sub i2c_read
467             {
468 2     2 1 29 my ($self, $name, $pin, $addr, $register, $num_bytes) = @_;
469 2         4 my $obj = $self->_get_obj( $name );
470 2         3 $self->_pin_count_check( $name, $obj, $pin, 'I2CProvider' );
471 2         4 return $obj->i2c_read( $pin, $addr, $register, $num_bytes );
472             }
473              
474             sub i2c_write
475             {
476 2     2 1 1034 my ($self, $name, $pin, $addr, $register, @bytes) = @_;
477 2         5 my $obj = $self->_get_obj( $name );
478 2         4 $self->_pin_count_check( $name, $obj, $pin, 'I2CProvider' );
479 2         5 return $obj->i2c_write( $pin, $addr, $register, @bytes );
480             }
481              
482             sub temp_celsius
483             {
484 2     2 0 8 my ($self, $name) = @_;
485 2         4 my $obj = $self->_get_obj( $name );
486 2 50       7 Device::WebIO::FunctionNotSupportedException->throw(
487             message => "Asked for temperature, but $name does not do the"
488             . " TempSensor role"
489             ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
490 2         46 return $obj->temp_celsius;
491             }
492              
493             sub temp_kelvins
494             {
495 2     2 0 4 my ($self, $name) = @_;
496 2         3 my $obj = $self->_get_obj( $name );
497 2 50       6 Device::WebIO::FunctionNotSupportedException->throw(
498             message => "Asked for temperature, but $name does not do the"
499             . " TempSensor role"
500             ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
501 2         24 return $obj->temp_kelvins;
502             }
503              
504             sub temp_fahrenheit
505             {
506 2     2 0 2 my ($self, $name) = @_;
507 2         4 my $obj = $self->_get_obj( $name );
508 2 50       4 Device::WebIO::FunctionNotSupportedException->throw(
509             message => "Asked for temperature, but $name does not do the"
510             . " TempSensor role"
511             ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
512 2         25 return $obj->temp_fahrenheit;
513             }
514              
515             sub spi_set_speed
516             {
517 1     1 1 4 my ($self, $name, $pin, $speed) = @_;
518 1         2 my $obj = $self->_get_obj( $name );
519 1         3 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
520 1         3 return $obj->spi_set_speed( $pin, $speed );
521             }
522              
523             sub spi_read
524             {
525 1     1 1 339 my ($self, $name, $pin, $len) = @_;
526 1         3 my $obj = $self->_get_obj( $name );
527 1         3 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
528 1         3 return $obj->spi_read( $pin, $len );
529             }
530              
531             sub spi_write
532             {
533 1     1 1 338 my ($self, $name, $pin, $data) = @_;
534 1         2 my $obj = $self->_get_obj( $name );
535 1         3 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
536 1         3 return $obj->spi_write( $pin, $data );
537             }
538              
539              
540             sub _get_obj
541             {
542 121     121   143 my ($self, $name) = @_;
543 121         181 my $obj = $self->_device_by_name->{$name};
544 121         143 return $obj;
545             }
546              
547             sub _pin_count_check
548             {
549 84     84   92 my ($self, $name, $obj, $pin, $type) = @_;
550 84         110 my $pin_count = $self->_pin_count_for_obj( $obj, $type );
551              
552 84 100       115 if( $pin_count <= $pin ) {
553 10         84 Device::WebIO::PinDoesNotExistException->throw(
554             message => "Asked for $type pin $pin, but device $name"
555             . " only has $pin_count pins",
556             );
557             }
558              
559 74         79 return 1;
560             }
561              
562             sub _pin_count_for_obj
563             {
564 84     84   63 my ($self, $obj, $type) = @_;
565              
566 84         60 my $count;
567 84 100 66     567 if( $type eq 'DigitalInput' &&
    100 66        
    100 66        
    100 66        
    100 66        
    100 66        
    100 66        
    100 66        
    50 33        
568             $obj->does( 'Device::WebIO::Device::DigitalInput' ) ) {
569 19         139 $count = $obj->input_pin_count;
570             }
571             elsif( $type eq 'DigitalInputCallback' &&
572             $obj->does( 'Device::WebIO::Device::DigitalInputCallback' ) ) {
573 3         22 $count = $obj->input_pin_count;
574             }
575             elsif( $type eq 'DigitalOutput' &&
576             $obj->does( 'Device::WebIO::Device::DigitalOutput' ) ) {
577 13         94 $count = $obj->output_pin_count;
578             }
579             elsif( $type eq 'ADC' &&
580             $obj->does( 'Device::WebIO::Device::ADC' ) ) {
581 10         83 $count = $obj->adc_pin_count;
582             }
583             elsif( $type eq 'PWM' &&
584             $obj->does( 'Device::WebIO::Device::PWM' ) ) {
585 5         36 $count = $obj->pwm_pin_count;
586             }
587             elsif( $type eq 'VideoOutput' &&
588             $obj->does( 'Device::WebIO::Device::VideoOutput' ) ) {
589 16         158 $count = $obj->vid_channels;
590             }
591             elsif( $type eq 'StillImageOutput' &&
592             $obj->does( 'Device::WebIO::Device::StillImageOutput' ) ) {
593 11         84 $count = $obj->img_channels;
594             }
595             elsif( $type eq 'I2CProvider' &&
596             $obj->does( 'Device::WebIO::Device::I2CProvider' ) ) {
597 4         57 $count = $obj->i2c_channels;
598             }
599             elsif( $type eq 'SPI' &&
600             $obj->does( 'Device::WebIO::Device::SPI' ) ) {
601 3         52 $count = $obj->spi_channels;
602             }
603              
604 84         128 return $count;
605             }
606              
607             sub _role_check
608             {
609 103     103   127 my ($self, $obj, @want_types) = @_;
610              
611 103         72 my $does = 0;
612 103         124 for (@want_types) {
613 103         123 my $full_type = 'Device::WebIO::Device::' . $_;
614 103 100       189 if( $obj->does( $full_type ) ) {
615 99         788 $does = 1;
616 99         95 last;
617             }
618             }
619 103 100       197 if(! $does ) {
620 4         39 Device::WebIO::FunctionNotSupportedException->throw( message =>
621             "Object of type " . ref($obj)
622             . " does not any of the " . join( ', ', @want_types ) . " roles"
623             );
624             }
625              
626 99         85 return 1;
627             }
628              
629              
630             1;
631             __END__