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.009';
26             # ABSTRACT: Duct Tape for the Internet of Things
27 14     14   229407 use v5.12;
  14         49  
  14         601  
28 14     14   8292 use Moo;
  14         150893  
  14         100  
29 14     14   27181 use namespace::clean;
  14         196753  
  14         110  
30 14     14   9731 use Device::WebIO::Exceptions;
  14         40  
  14         54159  
31              
32             has '_device_by_name' => (
33             is => 'ro',
34             default => sub {{
35             }},
36             );
37              
38              
39             sub register
40             {
41 13     13 1 1276 my ($self, $name, $device) = @_;
42 13         102 $self->_device_by_name->{$name} = $device;
43 13         34 return 1;
44             }
45              
46              
47             sub pin_desc
48             {
49 1     1 1 7 my ($self, $name) = @_;
50 1         5 my $obj = $self->_get_obj( $name );
51 1         13 return $obj->pin_desc;
52             }
53              
54             sub all_desc
55             {
56 2     2 1 1353 my ($self, $name) = @_;
57 2         4 my $obj = $self->_get_obj( $name );
58 2         7 return $obj->all_desc;
59             }
60              
61              
62             sub set_as_input
63             {
64 7     7 1 2400 my ($self, $name, $pin) = @_;
65 7         17 my $obj = $self->_get_obj( $name );
66 7         15 $self->_role_check( $obj, 'DigitalInput' );
67 7         15 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
68 6         18 $obj->set_as_input( $pin );
69 6         33 return 1;
70             }
71              
72             sub set_as_output
73             {
74 5     5 1 2853 my ($self, $name, $pin) = @_;
75 5         15 my $obj = $self->_get_obj( $name );
76 5         12 $self->_role_check( $obj, 'DigitalOutput' );
77 5         12 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
78 3         11 $obj->set_as_output( $pin );
79 3         18 return 1;
80             }
81              
82             sub is_set_input
83             {
84 8     8 1 1781 my ($self, $name, $pin) = @_;
85 8         25 my $obj = $self->_get_obj( $name );
86 8         17 $self->_role_check( $obj, 'DigitalInput' );
87 8         16 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
88 8         25 return $obj->is_set_input( $pin );
89             }
90              
91             sub is_set_output
92             {
93 4     4 1 1259 my ($self, $name, $pin) = @_;
94 4         10 my $obj = $self->_get_obj( $name );
95 4         12 $self->_role_check( $obj, 'DigitalOutput' );
96 4         13 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
97 4         12 return $obj->is_set_output( $pin );
98             }
99              
100             sub digital_input_pin_count
101             {
102 3     3 1 807 my ($self, $name) = @_;
103 3         12 my $obj = $self->_get_obj( $name );
104 3         10 $self->_role_check( $obj, 'DigitalInput' );
105 3         10 my $count = $obj->input_pin_count;
106 3         19 return $count;
107             }
108              
109             sub digital_output_pin_count
110             {
111 2     2 1 774 my ($self, $name) = @_;
112 2         7 my $obj = $self->_get_obj( $name );
113 2         6 $self->_role_check( $obj, 'DigitalOutput' );
114 2         6 my $count = $obj->output_pin_count;
115 2         11 return $count;
116             }
117              
118             sub digital_input
119             {
120 5     5 1 2194 my ($self, $name, $pin) = @_;
121 5         15 my $obj = $self->_get_obj( $name );
122 5         17 $self->_role_check( $obj, 'DigitalInput' );
123 4         11 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
124 3         9 return $obj->input_pin( $pin );
125             }
126              
127             sub digital_input_port
128             {
129 2     2 1 312 my ($self, $name) = @_;
130 2         6 my $obj = $self->_get_obj( $name );
131 2         5 $self->_role_check( $obj, 'DigitalInput' );
132 2         10 return $obj->input_port;
133             }
134              
135             sub digital_input_callback
136             {
137 3     3 1 4 my ($self, $name, $pin, $type, $callback) = @_;
138 3         7 my $obj = $self->_get_obj( $name );
139 3         6 $self->_role_check( $obj, 'DigitalInputCallback' );
140 3         4 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInputCallback' );
141 3         8 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         6 my $obj = $self->_get_obj( $name );
148 1         4 $self->_role_check( $obj, 'DigitalInputCallback' );
149 1         6 return $obj->input_begin_loop();
150             }
151              
152             sub digital_output_port
153             {
154 2     2 1 6 my ($self, $name, $out) = @_;
155 2         12 my $obj = $self->_get_obj( $name );
156 2         7 $self->_role_check( $obj, 'DigitalOutput' );
157 2         12 $obj->output_port( $out );
158 2         4 return 1;
159             }
160              
161             sub digital_output
162             {
163 7     7 1 2339 my ($self, $name, $pin, $val) = @_;
164 7         21 my $obj = $self->_get_obj( $name );
165 7         20 $self->_role_check( $obj, 'DigitalOutput' );
166 4         10 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
167 3         10 $obj->output_pin( $pin, $val );
168 3         18 return 1;
169             }
170              
171             sub adc_count
172             {
173 1     1 1 5 my ($self, $name) = @_;
174 1         4 my $obj = $self->_get_obj( $name );
175 1         4 $self->_role_check( $obj, 'ADC' );
176 1         7 return $obj->adc_pin_count;
177             }
178              
179             sub adc_resolution
180             {
181 2     2 1 398 my ($self, $name, $pin) = @_;
182 2         6 my $obj = $self->_get_obj( $name );
183 2         5 $self->_role_check( $obj, 'ADC' );
184 2         8 return $obj->adc_bit_resolution( $pin );
185             }
186              
187             sub adc_max_int
188             {
189 2     2 1 856 my ($self, $name, $pin) = @_;
190 2         6 my $obj = $self->_get_obj( $name );
191 2         5 $self->_role_check( $obj, 'ADC' );
192 2         7 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         5 my $obj = $self->_get_obj( $name );
199 2         4 $self->_role_check( $obj, 'ADC' );
200 2         6 return $obj->adc_volt_ref( $pin );
201             }
202              
203             sub adc_input_int
204             {
205 4     4 1 1250 my ($self, $name, $pin) = @_;
206 4         8 my $obj = $self->_get_obj( $name );
207 4         8 $self->_role_check( $obj, 'ADC' );
208 4         7 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
209 3         10 return $obj->adc_input_int( $pin );
210             }
211              
212             sub adc_input_float
213             {
214 3     3 1 942 my ($self, $name, $pin) = @_;
215 3         8 my $obj = $self->_get_obj( $name );
216 3         11 $self->_role_check( $obj, 'ADC' );
217 3         6 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
218 2         6 return $obj->adc_input_float( $pin );
219             }
220              
221             sub adc_input_volts
222             {
223 3     3 1 411 my ($self, $name, $pin) = @_;
224 3         6 my $obj = $self->_get_obj( $name );
225 3         6 $self->_role_check( $obj, 'ADC' );
226 3         8 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
227 2         6 return $obj->adc_input_volts( $pin );
228             }
229              
230             sub pwm_count
231             {
232 1     1 1 5 my ($self, $name) = @_;
233 1         4 my $obj = $self->_get_obj( $name );
234 1         4 $self->_role_check( $obj, 'PWM' );
235 1         7 return $obj->pwm_pin_count;
236             }
237              
238             sub pwm_resolution
239             {
240 2     2 1 5 my ($self, $name, $pin) = @_;
241 2         5 my $obj = $self->_get_obj( $name );
242 2         6 $self->_role_check( $obj, 'PWM' );
243 2         6 return $obj->pwm_bit_resolution( $pin );
244             }
245              
246             sub pwm_max_int
247             {
248 2     2 1 941 my ($self, $name, $pin) = @_;
249 2         6 my $obj = $self->_get_obj( $name );
250 2         5 $self->_role_check( $obj, 'PWM' );
251 2         10 return $obj->pwm_max_int( $pin );
252             }
253              
254             sub pwm_output_int
255             {
256 3     3 1 1828 my ($self, $name, $pin, $value) = @_;
257 3         7 my $obj = $self->_get_obj( $name );
258 3         6 $self->_role_check( $obj, 'PWM' );
259 3         7 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
260 2         6 return $obj->pwm_output_int( $pin, $value );
261             }
262              
263             sub pwm_output_float
264             {
265 2     2 1 600 my ($self, $name, $pin, $value) = @_;
266 2         21 my $obj = $self->_get_obj( $name );
267 2         7 $self->_role_check( $obj, 'PWM' );
268 2         6 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
269 1         6 return $obj->pwm_output_float( $pin, $value );
270             }
271              
272             sub vid_channels
273             {
274 1     1 1 1009 my ($self, $name) = @_;
275 1         5 my $obj = $self->_get_obj( $name );
276 1         4 $self->_role_check( $obj, 'VideoOutput' );
277 1         4 return $obj->vid_channels;
278             }
279              
280             sub vid_width
281             {
282 2     2 1 471 my ($self, $name, $pin) = @_;
283 2         6 my $obj = $self->_get_obj( $name );
284 2         6 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
285 2         3 $self->_role_check( $obj, 'VideoOutput' );
286 2         5 return $obj->vid_width( $pin );
287             }
288              
289             sub vid_height
290             {
291 2     2 1 775 my ($self, $name, $pin) = @_;
292 2         7 my $obj = $self->_get_obj( $name );
293 2         4 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
294 2         3 $self->_role_check( $obj, 'VideoOutput' );
295 2         6 return $obj->vid_height( $pin );
296             }
297              
298             sub vid_fps
299             {
300 2     2 1 775 my ($self, $name, $pin) = @_;
301 2         5 my $obj = $self->_get_obj( $name );
302 2         4 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
303 2         3 $self->_role_check( $obj, 'VideoOutput' );
304 2         6 return $obj->vid_fps( $pin );
305             }
306              
307             sub vid_kbps
308             {
309 2     2 1 797 my ($self, $name, $pin) = @_;
310 2         5 my $obj = $self->_get_obj( $name );
311 2         5 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
312 2         5 $self->_role_check( $obj, 'VideoOutput' );
313 2         10 return $obj->vid_kbps( $pin );
314             }
315              
316             sub vid_set_width
317             {
318 1     1 1 380 my ($self, $name, $pin, $value) = @_;
319 1         2 my $obj = $self->_get_obj( $name );
320 1         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
321 1         3 $self->_role_check( $obj, 'VideoOutput' );
322 1         4 return $obj->vid_set_width( $pin, $value );
323             }
324              
325             sub vid_set_height
326             {
327 1     1 1 8 my ($self, $name, $pin, $value) = @_;
328 1         2 my $obj = $self->_get_obj( $name );
329 1         3 $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 8 my ($self, $name, $pin, $value) = @_;
337 1         2 my $obj = $self->_get_obj( $name );
338 1         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
339 1         3 $self->_role_check( $obj, 'VideoOutput' );
340 1         3 return $obj->vid_set_fps( $pin, $value );
341             }
342              
343             sub vid_set_kbps
344             {
345 1     1 0 8 my ($self, $name, $pin, $value) = @_;
346 1         3 my $obj = $self->_get_obj( $name );
347 1         3 $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 417 my ($self, $name, $pin) = @_;
355 1         4 my $obj = $self->_get_obj( $name );
356 1         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
357 1         3 $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 371 my ($self, $name, $pin, $type) = @_;
364 1         3 my $obj = $self->_get_obj( $name );
365 1         3 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
366 1         3 $self->_role_check( $obj, 'VideoOutput' );
367 1         3 return $obj->vid_stream( $pin, $type );
368             }
369              
370             sub vid_stream_callback
371             {
372 1     1 1 1498 my ($self, $name, $pin, $type, $callback) = @_;
373 1         4 my $obj = $self->_get_obj( $name );
374 1         4 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
375 1         4 $self->_role_check( $obj, 'VideoOutputCallback' );
376 1         6 return $obj->vid_stream_callback( $pin, $type, $callback );
377             }
378              
379             sub vid_stream_begin_loop
380             {
381 1     1 1 495 my ($self, $name, $pin) = @_;
382 1         4 my $obj = $self->_get_obj( $name );
383 1         2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
384 1         3 $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 5 my ($self, $name) = @_;
391 1         5 my $obj = $self->_get_obj( $name );
392 1         4 $self->_role_check( $obj, 'StillImageOutput' );
393 1         4 return $obj->img_channels;
394             }
395              
396             sub img_width
397             {
398 2     2 1 804 my ($self, $name, $pin) = @_;
399 2         7 my $obj = $self->_get_obj( $name );
400 2         5 $self->_role_check( $obj, 'StillImageOutput' );
401 2         7 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
402 2         177 return $obj->img_width( $pin );
403             }
404              
405             sub img_height
406             {
407 2     2 1 894 my ($self, $name, $pin) = @_;
408 2         7 my $obj = $self->_get_obj( $name );
409 2         7 $self->_role_check( $obj, 'StillImageOutput' );
410 2         7 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
411 2         7 return $obj->img_height( $pin );
412             }
413              
414             sub img_quality
415             {
416 2     2 1 893 my ($self, $name, $pin) = @_;
417 2         6 my $obj = $self->_get_obj( $name );
418 2         6 $self->_role_check( $obj, 'StillImageOutput' );
419 2         6 $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 1888 my ($self, $name, $pin, $value) = @_;
426 1         5 my $obj = $self->_get_obj( $name );
427 1         4 $self->_role_check( $obj, 'StillImageOutput' );
428 1         4 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
429 1         4 return $obj->img_set_width( $pin, $value );
430             }
431              
432             sub img_set_height
433             {
434 1     1 1 9 my ($self, $name, $pin, $value) = @_;
435 1         3 my $obj = $self->_get_obj( $name );
436 1         10 $self->_role_check( $obj, 'StillImageOutput' );
437 1         4 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
438 1         4 return $obj->img_set_height( $pin, $value );
439             }
440              
441             sub img_set_quality
442             {
443 1     1 1 162 my ($self, $name, $pin, $value) = @_;
444 1         5 my $obj = $self->_get_obj( $name );
445 1         3 $self->_role_check( $obj, 'StillImageOutput' );
446 1         3 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
447 1         5 return $obj->img_set_quality( $pin, $value );
448             }
449              
450             sub img_allowed_content_types
451             {
452 1     1 1 1250 my ($self, $name, $pin) = @_;
453 1         4 my $obj = $self->_get_obj( $name );
454 1         3 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
455 1         4 return $obj->img_allowed_content_types( $pin );
456             }
457              
458             sub img_stream
459             {
460 1     1 1 408 my ($self, $name, $pin, $type) = @_;
461 1         2 my $obj = $self->_get_obj( $name );
462 1         4 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
463 1         4 return $obj->img_stream( $pin, $type );
464             }
465              
466             sub i2c_read
467             {
468 2     2 1 40 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         5 return $obj->i2c_read( $pin, $addr, $register, $num_bytes );
472             }
473              
474             sub i2c_write
475             {
476 2     2 1 1721 my ($self, $name, $pin, $addr, $register, @bytes) = @_;
477 2         6 my $obj = $self->_get_obj( $name );
478 2         7 $self->_pin_count_check( $name, $obj, $pin, 'I2CProvider' );
479 2         7 return $obj->i2c_write( $pin, $addr, $register, @bytes );
480             }
481              
482             sub temp_celsius
483             {
484 2     2 0 14 my ($self, $name) = @_;
485 2         7 my $obj = $self->_get_obj( $name );
486 2 50       14 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         88 return $obj->temp_celsius;
491             }
492              
493             sub temp_kelvins
494             {
495 2     2 0 7 my ($self, $name) = @_;
496 2         8 my $obj = $self->_get_obj( $name );
497 2 50       14 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         44 return $obj->temp_kelvins;
502             }
503              
504             sub temp_fahrenheit
505             {
506 2     2 0 6 my ($self, $name) = @_;
507 2         8 my $obj = $self->_get_obj( $name );
508 2 50       9 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         46 return $obj->temp_fahrenheit;
513             }
514              
515             sub spi_set_speed
516             {
517 1     1 1 5 my ($self, $name, $pin, $speed) = @_;
518 1         3 my $obj = $self->_get_obj( $name );
519 1         3 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
520 1         6 return $obj->spi_set_speed( $pin, $speed );
521             }
522              
523             sub spi_read
524             {
525 1     1 1 857 my ($self, $name, $pin, $len) = @_;
526 1         4 my $obj = $self->_get_obj( $name );
527 1         3 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
528 1         5 return $obj->spi_read( $pin, $len );
529             }
530              
531             sub spi_write
532             {
533 1     1 1 520 my ($self, $name, $pin, $data) = @_;
534 1         3 my $obj = $self->_get_obj( $name );
535 1         4 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
536 1         7 return $obj->spi_write( $pin, $data );
537             }
538              
539              
540             sub _get_obj
541             {
542 121     121   167 my ($self, $name) = @_;
543 121         411 my $obj = $self->_device_by_name->{$name};
544 121         199 return $obj;
545             }
546              
547             sub _pin_count_check
548             {
549 84     84   116 my ($self, $name, $obj, $pin, $type) = @_;
550 84         149 my $pin_count = $self->_pin_count_for_obj( $obj, $type );
551              
552 84 100       164 if( $pin_count <= $pin ) {
553 10         133 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         83 return 1;
560             }
561              
562             sub _pin_count_for_obj
563             {
564 84     84   123 my ($self, $obj, $type) = @_;
565              
566 84         79 my $count;
567 84 100 66     772 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         187 $count = $obj->input_pin_count;
570             }
571             elsif( $type eq 'DigitalInputCallback' &&
572             $obj->does( 'Device::WebIO::Device::DigitalInputCallback' ) ) {
573 3         25 $count = $obj->input_pin_count;
574             }
575             elsif( $type eq 'DigitalOutput' &&
576             $obj->does( 'Device::WebIO::Device::DigitalOutput' ) ) {
577 13         148 $count = $obj->output_pin_count;
578             }
579             elsif( $type eq 'ADC' &&
580             $obj->does( 'Device::WebIO::Device::ADC' ) ) {
581 10         88 $count = $obj->adc_pin_count;
582             }
583             elsif( $type eq 'PWM' &&
584             $obj->does( 'Device::WebIO::Device::PWM' ) ) {
585 5         62 $count = $obj->pwm_pin_count;
586             }
587             elsif( $type eq 'VideoOutput' &&
588             $obj->does( 'Device::WebIO::Device::VideoOutput' ) ) {
589 16         201 $count = $obj->vid_channels;
590             }
591             elsif( $type eq 'StillImageOutput' &&
592             $obj->does( 'Device::WebIO::Device::StillImageOutput' ) ) {
593 11         267 $count = $obj->img_channels;
594             }
595             elsif( $type eq 'I2CProvider' &&
596             $obj->does( 'Device::WebIO::Device::I2CProvider' ) ) {
597 4         76 $count = $obj->i2c_channels;
598             }
599             elsif( $type eq 'SPI' &&
600             $obj->does( 'Device::WebIO::Device::SPI' ) ) {
601 3         78 $count = $obj->spi_channels;
602             }
603              
604 84         166 return $count;
605             }
606              
607             sub _role_check
608             {
609 103     103   177 my ($self, $obj, @want_types) = @_;
610              
611 103         88 my $does = 0;
612 103         156 for (@want_types) {
613 103         178 my $full_type = 'Device::WebIO::Device::' . $_;
614 103 100       260 if( $obj->does( $full_type ) ) {
615 99         1081 $does = 1;
616 99         232 last;
617             }
618             }
619 103 100       260 if(! $does ) {
620 4         60 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         260 return 1;
627             }
628              
629              
630             1;
631             __END__