line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# CMD-Class for Revolt USB Dongle PX-1674-675
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Device::USB::PX1674;
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '1.04';
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
17318
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
235
|
use Device::USB;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Carp;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new{
|
14
|
|
|
|
|
|
|
my $class = shift;
|
15
|
|
|
|
|
|
|
my %cfg = (
|
16
|
|
|
|
|
|
|
vid => 0xFFFF, # Vendor ID
|
17
|
|
|
|
|
|
|
pid => 0x1122, # Product ID
|
18
|
|
|
|
|
|
|
ept => 0x02, # Endpoint Out
|
19
|
|
|
|
|
|
|
addr => 0x1A1A, # Hauscode
|
20
|
|
|
|
|
|
|
intf => 0, # Interface
|
21
|
|
|
|
|
|
|
cfg => 1, # Configuration
|
22
|
|
|
|
|
|
|
verb => 0, # Verbose
|
23
|
|
|
|
|
|
|
@_);
|
24
|
|
|
|
|
|
|
my $self = bless{
|
25
|
|
|
|
|
|
|
CMD => {
|
26
|
|
|
|
|
|
|
1 => { On => 0xF0, Off => 0xE0 },
|
27
|
|
|
|
|
|
|
2 => { On => 0xD0, Off => 0xC0 },
|
28
|
|
|
|
|
|
|
3 => { On => 0xB0, Off => 0xA0 },
|
29
|
|
|
|
|
|
|
4 => { On => 0x90, Off => 0x80 },
|
30
|
|
|
|
|
|
|
5 => { On => 0x70, Off => 0x60 },
|
31
|
|
|
|
|
|
|
6 => { On => 0x50, Off => 0x40 },
|
32
|
|
|
|
|
|
|
group => { On => 0x20, Off => 0x10 },
|
33
|
|
|
|
|
|
|
},
|
34
|
|
|
|
|
|
|
CFG => \%cfg,
|
35
|
|
|
|
|
|
|
}, $class;
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
eval{
|
38
|
|
|
|
|
|
|
my $vid = sprintf "%04X", $cfg{vid};
|
39
|
|
|
|
|
|
|
my $pid = sprintf "%04X", $cfg{pid};
|
40
|
|
|
|
|
|
|
my $usb = Device::USB->new;
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $dev = undef;
|
43
|
|
|
|
|
|
|
foreach my $d( $usb->list_devices ){
|
44
|
|
|
|
|
|
|
if( $d->idVendor == $cfg{vid} && $d->idProduct == $cfg{pid} ){
|
45
|
|
|
|
|
|
|
$dev = $d;
|
46
|
|
|
|
|
|
|
last;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
die "Device Vendor '$vid', Product '$pid' not found\n"
|
50
|
|
|
|
|
|
|
unless $dev;
|
51
|
|
|
|
|
|
|
$dev->open || die "Error open device!\n";
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if( $dev->set_configuration($cfg{cfg}) != 0 ){
|
54
|
|
|
|
|
|
|
die "Can not set configuration!\n";
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
if( $dev->claim_interface($cfg{intf}) != 0 ){
|
57
|
|
|
|
|
|
|
die "Can not claim interface\n";
|
58
|
|
|
|
|
|
|
}
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$self->{usb_dev} = $dev;
|
61
|
|
|
|
|
|
|
$self;
|
62
|
|
|
|
|
|
|
};
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
# On|Off|switch
|
65
|
|
|
|
|
|
|
# Übergeben wird die Gerätenummer
|
66
|
|
|
|
|
|
|
# Ansonsten wird die Gruppe geschaltet
|
67
|
|
|
|
|
|
|
# __ANON__
|
68
|
|
|
|
|
|
|
my $OnOff = sub{
|
69
|
|
|
|
|
|
|
my $self = shift;
|
70
|
|
|
|
|
|
|
my $dest = shift;
|
71
|
|
|
|
|
|
|
my $devnr = shift || 'group';
|
72
|
|
|
|
|
|
|
my $payload = $self->_payload($devnr, $dest);
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
print join(" ", map{sprintf("%02X", $_)}unpack "C*", $payload) if $self->{CFG}{verb};
|
75
|
|
|
|
|
|
|
return $self->{usb_dev}->bulk_write( $self->{CFG}{ept}, $payload, 8, 5000);
|
76
|
|
|
|
|
|
|
};
|
77
|
|
|
|
|
|
|
############################ Private ######################################
|
78
|
|
|
|
|
|
|
sub _payload{
|
79
|
|
|
|
|
|
|
my $self = shift;
|
80
|
|
|
|
|
|
|
my $devnr = shift;
|
81
|
|
|
|
|
|
|
my $dest = shift;
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $cmd = $self->{CMD}{$devnr}{$dest} || croak "CMD '$dest' for device '$devnr' not found!";
|
84
|
|
|
|
|
|
|
my ($b1, $b2) = unpack "CC", pack "n", $self->{CFG}{addr};
|
85
|
|
|
|
|
|
|
my $chk = 255 - ($b1 + $b2 + $cmd) % 256;
|
86
|
|
|
|
|
|
|
return pack "C8", $b1,$b2,$cmd,$chk,0x20,0x0A,0x00,0x18;
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# On || Off || switch über eine anonyme Funktion
|
90
|
|
|
|
|
|
|
sub AUTOLOAD{
|
91
|
|
|
|
|
|
|
my $self = shift;
|
92
|
|
|
|
|
|
|
my $name = our $AUTOLOAD =~ /::(\w+)$/ ? $1 : '';
|
93
|
|
|
|
|
|
|
if( $name eq 'On' || $name eq 'Off' ){
|
94
|
|
|
|
|
|
|
$self->$OnOff($name, @_);
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
elsif( $name eq 'switch'){
|
97
|
|
|
|
|
|
|
$self->$OnOff(@_);
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
else{ die "Unbekannte Funktion: '$name'!\n" }
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
sub DESTROY{}
|
102
|
|
|
|
|
|
|
1;#########################################################################
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#my $px = Device::USB::PX1674->new() or die $@;
|
105
|
|
|
|
|
|
|
#$px->Off;
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__
|