File Coverage

blib/lib/Device/MindWave/Packet/ThinkGear/DataValue/RawWave.pm
Criterion Covered Total %
statement 33 33 100.0
branch 4 4 100.0
condition n/a
subroutine 9 9 100.0
pod 5 5 100.0
total 51 51 100.0


line stmt bran cond sub pod time code
1             package Device::MindWave::Packet::ThinkGear::DataValue::RawWave;
2              
3 5     5   29552 use strict;
  5         12  
  5         175  
4 5     5   26 use warnings;
  5         9  
  5         148  
5              
6 5     5   646 use Device::MindWave::Utils qw(checksum);
  5         11  
  5         265  
7              
8 5     5   26 use base qw(Device::MindWave::Packet::ThinkGear::DataValue);
  5         19  
  5         2025  
9              
10             sub new
11             {
12 4     4 1 37 my ($class, $bytes, $index) = @_;
13              
14 4         11 my $upper = $bytes->[$index + 2];
15 4         10 my $lower = $bytes->[$index + 3];
16 4         9 my $value = ($upper << 8) | $lower;
17 4 100       186 if ($value > 32767) {
18 1         3 $value -= 65536;
19             }
20              
21 4         12 my $self = { value => $value };
22 4         16 bless $self, $class;
23 4         15 return $self;
24             }
25              
26             sub as_bytes
27             {
28 3     3 1 1363 my ($self) = @_;
29              
30 3         11 my $value = $self->{'value'};
31 3 100       11 if ($value < 0) {
32 1         3 $value += 65536;
33             }
34 3         6 my $upper = ($value >> 8) & 0xFF;
35 3         5 my $lower = $value & 0xFF;
36              
37 3         19 return [ 0x80, 0x02, $upper, $lower ];
38             }
39              
40             sub length
41             {
42 4     4 1 20 return 4;
43             }
44              
45             sub as_string
46             {
47 3     3 1 1113 my ($self) = @_;
48              
49 3         34 return "Raw wave: ".$self->{'value'};
50             }
51              
52             sub as_hashref
53             {
54 3     3 1 25 my ($self) = @_;
55              
56 3         30 return { RawWave => $self->{'value'} };
57             }
58              
59             1;
60              
61             __END__