mini-led-cube/tools/frame2cube.pl

92 lines
3.1 KiB
Perl
Raw Permalink Normal View History

#!/usr/bin/perl -w
2011-12-29 22:50:22 +01:00
#
2012-01-14 10:44:35 +01:00
# author: Kai Lauterbach (klaute at gmail dot com)
# date: 01/2012
# license: GPL v3
#
2012-01-15 00:29:34 +01:00
# usage:
2011-12-29 22:50:22 +01:00
#
2012-01-15 00:29:34 +01:00
# ./frame2cube.pl "frame 1 data" "frame 2 data" ... "frame N data"
2011-12-29 22:50:22 +01:00
#
# frame X data = delay; layer 1; layer 2; layer 3
#
# delay = 0 to 31 (multiplied by 8 in firmware and equals to the ISR calls (delay/300 seconds)
# 0 equals to a delay of 255/300 seconds.
#
2011-12-29 22:54:59 +01:00
# layer Y = layer no(1,2,3), bit0, bit1, bit2, ..., bit8 (bitN = 1 ... 9)
2011-12-29 22:50:22 +01:00
#
# Sample usage which generates 5 frames:
#
2012-01-15 00:29:34 +01:00
# perl ./frame2cube.pl "25;3,2,5,8;" "14;3,3,5,7" "3;3,4,5,6;2,6,5,4" "23;3,1,5,9" "0;2,1,2,3,4,5,6,7,8,9;1,5"
2011-12-29 22:50:22 +01:00
# Frame 0 = 0xca480000 = hi:0xca48 = lo:0x0000 = 0b11001010010010000000000000000000
# Frame 1 = 0x71500000 = hi:0x7150 = lo:0x0000 = 0b01110001010100000000000000000000
# Frame 2 = 0x18e07000 = hi:0x18e0 = lo:0x7000 = 0b00011000111000000111000000000000
# Frame 3 = 0xbc440000 = hi:0xbc44 = lo:0x0000 = 0b10111100010001000000000000000000
# Frame 4 = 0x0003fe10 = hi:0x0003 = lo:0xfe10 = 0b00000000000000111111111000010000
#
2012-01-15 00:29:34 +01:00
# perl ./frame2cube.pl "5;3,2,5,8" "5;3,3,5,7" "5;3,4,5,6;" "5;3,1,5,9" "15;2,2,5,8" "15;2,3,5,7" "15;2,4,5,6" "15;2,1,5,9" "30;1,2,5,8" "30;1,3,5,7" "30;1,4,5,6" "30;1,1,5,9"
2011-12-30 13:04:51 +01:00
#
use strict;
2011-12-30 13:04:51 +01:00
use Time::HiRes qw(usleep nanosleep);
for (my $i=0; $i<=$#ARGV; $i++)
{
2011-12-29 22:50:22 +01:00
printf("Frame %02d = ", $i);
2011-12-29 22:50:22 +01:00
my @list = split(";", $ARGV[$i]);
my $frame = 0;
my $status = 1;
foreach my $ele (@list)
{
2011-12-29 22:50:22 +01:00
my @list2 = split(",", $ele);
2011-12-29 22:50:22 +01:00
my $status2 = 1;
my $layer = 0;
my $bit = 0;
if ($status == 1) { # read the delay
$status = 0;
# minimum delay is 0 (equals to a delay of 255 ISR calls)
# maximum delay is 31 (equals to a delay of 31*8 ISR calls)
if ($ele > -1 && $ele < 32)
{
$frame |= $ele << 27;
}
} else {
if ($#list >= 0 && $#list <= 9)
{
my $ele = 0;
foreach my $ele2 (@list2)
{
2011-12-29 22:50:22 +01:00
if ($status2 == 1) # read the layer
{
# the layer has to be in range of 1 to 3
if ($ele2 > 0 && $ele2 < 4)
{
$layer = ($ele2 - 1) * 9;
$status2 = 0;
}
} else {
if ($ele2 > 0 && $ele2 < 10) # bit 1 to 9 allowed
{
$bit = $layer + $ele2-1;
$frame |= (1 << $bit);
}
}
}
}
}
}
2011-12-29 22:50:22 +01:00
printf("0x%08x = ", $frame);
printf("hi:0x%04x = ", $frame >> 16);
printf("lo:0x%04x = ", $frame & 0xffff);
printf("0b%032b\n", $frame);
2011-12-30 13:04:51 +01:00
my $tmp = "";
$tmp = sprintf("0x%08x", $frame);
2012-01-13 20:19:45 +01:00
system("../client/clcc --save --pos $i --delay ". ($frame >> 27)." --frame $tmp");
2011-12-31 18:24:05 +01:00
#print("../client/clcc --save $i ". ($frame >> 27)." $tmp\n");
2012-01-13 20:19:45 +01:00
usleep(250000);
#sleep 1;
}
2011-12-29 22:54:59 +01:00