]> git.gir.st - Ledberg-ESP8266.git/blob - hue-wheel.pl
implement storing color and use wifimanager to keep track of ssid/psk
[Ledberg-ESP8266.git] / hue-wheel.pl
1 #!/usr/bin/perl
2 # (c) 2019 Tobias Girstmair <https://gir.st/>; GPLv3
3
4 my $ip = "10.42.0.74";
5
6 use strict;
7 use warnings;
8
9 sub hue2rgb {
10 my $h = $_[0] / 60;
11 my $t = $h - int $h;
12 my $q = 1.0 - $t;
13
14 return ( 1, $t, 00) if $h < 1;
15 return ($q, 1, 00) if $h < 2;
16 return (00, 1, $t) if $h < 3;
17 return (00, $q, 1) if $h < 4;
18 return ($t, 00, 1) if $h < 5;
19 return ( 1, 00, $q) if $h < 6;
20 }
21 sub packet {
22 my ($type, $r, $g, $b) = @_;
23 open(my $netcat, "| nc -u $ip 1337");
24 print $netcat pack "CC", 0x01, $r if ($type eq "power");
25 print $netcat pack "CCCC", 0x02, $r*0xFF, $g*0x7F, $b*0x7F if ($type eq "color");
26 close($netcat);
27 }
28
29 packet "power", 1;
30 while(1) {
31 for (1..359) {
32 packet "color", hue2rgb($_, 1, 1);
33 select(undef, undef, undef, 0.2); # sub-second sleep() substitute
34 }
35 }
Imprint / Impressum