/
panel-ident
81 lines (60 loc) · 1.63 KB
/
panel-ident
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env perl
use v5.38.0;
use utf8;
use lib 'lib';
use IO::Async::Loop;
use IO::Socket;
use Time::HiRes ();
use Nib::Config;
use Nib::Dev;
binmode *STDOUT, ':encoding(UTF-8)';
my $config = Nib::Config->read_file('nib.toml');
my $dev = Nib::Dev->new(config => $config);
my $loop = IO::Async::Loop->new;
$loop->add($dev);
my $state = $dev->get_state->get;
unless ($state->{effects}{select} eq '*ExtControl*') {
say "Not currently in streaming mode, configuring...";
$dev->set_streaming->get;
}
my @panels =
sort { $a->{panelId} <=> $b->{panelId} }
$dev->get_panel_position_data->get;
die "no panels found?!\n" unless @panels;
my %colors = (
red => [ 0x50, 0x00, 0x00 ],
orange => [ 0x80, 0x30, 0x00 ],
yellow => [ 0x50, 0x50, 0x00 ],
green => [ 0x00, 0x50, 0x00 ],
cyan => [ 0x00, 0x50, 0x50 ],
blue => [ 0x00, 0x00, 0x60 ],
violet => [ 0x30, 0x00, 0x60 ],
brown => [ 0x60, 0x40, 0x20 ],
white => [ 0x50, 0x50, 0x50 ],
);
die "too many panels!\n" if
%colors < (grep { $_->{shapeType} == 12 } @panels);
$dev->blackout->get;
my @color_queue = sort keys %colors;
for my $panel (@panels) {
if ($panel->{shapeType} == 12) {
say sprintf "%6i %8s (%3i, %3i) %3i°",
$panel->{panelId},
'controls',
$panel->@{qw( x y o )};
next;
}
my $color = shift @color_queue;
unless ($color) {
say sprintf "%6i %8s (%3i, %3i) %3i°",
$panel->{panelId},
'(n/a)',
$panel->@{qw( x y o )};
next;
}
$dev->set_panel($panel->{panelId}, $colors{$color});
say sprintf "%6i %8s (%3i, %3i) %3i°",
$panel->{panelId},
$color,
$panel->@{qw( x y o )};
}