Close

TCL-ish Scripting

A project log for AND!XOR DC25 Badge

We're going bigger, better, more Bender.

hyr0nHyr0n 06/25/2017 at 17:321 Comment
                       `. ___
                        __,' __`.                _..----....____
            __...--.'``;.   ,.   ;``--..__     .'    ,-._    _.-'
      _..-''-------'   `'   `'   `'     O ``-''._   (,;') _,'
    ,'________________                          \`-._`-','
     `._              ```````````------...___   '-.._'-:
        ```--.._      ,.                     ````--...__\-.
                `.--. `-`   AND!XOR             ____    |  |`
                  `. `.                       ,'`````.  ;  ;`
                    `._`.        __________   `.      \'__/`
                       `-:._____/______/___/____`.     \  `
                                   |       `._    `.    \
                                   `._________`-.   `.   `.___
                                                      `------'`

We wanted to build upon what we did at DC24 with an even more hackable badge. But we’re taking a different route from last year. No POS Arduino IDE, no specialized STM32 framework, no USB, or special drivers. This year the badge is scriptable. We didn’t want hackers spending their con configuring an arcane build environment. We want you to hack the badge on day 1, share you hacks during the con, and show us all the great things you can do. So what have we done? We’ve embedded a scripting engine. Not only that but we’ve created basic, easy-to-understand APIs for almost everything in the badge. As much as we could come up with. We looked at Python but was not impressed with anything out there. We even had a Javascript engine running on the badge at one point, but it used 25% of the flash space, we needed that for bling. We ended up adopting a very limited TCL engine. Your favorite TCL scripts won’t run on the badge, that’s not the point.

Badge TCL Language Support

The following commands are supported:

Special Commands

Color support

Graphics and fonts support 8 bit color. Format is RRRGGGBB. See:

https://en.wikipedia.org/wiki/8-bit_color

Some examples:

0: Black

3: Blue

28: Green

252: Yellow

224: Red

GPIO

Basic GPIO io_read and io_write commands have been implemented. The PCB has a total of five IO exposed. This was all that was left after all the bling was done. Each IO is referred to as 0 through 4 in the TCL code. Note 3.3v power is also provided for addons if you desire.

Examples

There are examples included on the badge, here is their source code.

They are located in: /SD Image/TCL/

Drop any TCLish scripts you create in this directory.

EXAMPLE1.TCL: Prints blue and green text to the screen just like your first BASIC program.

cls;

print 10 10 "Hello World!";
delay 500;

set_color 3;
print 30 30 "Blue";
delay 1000;

set_color 28;
print 30 60 "Green";
delay 5000;

EXAMPLE2.TCL: Scrolls a message on the screen.

scroll "Hello World! This is MAN BEAR PIG TCL!";

EXAMPLE3.TCL: Plays Rick Roll until user holds a button

cls;
print 0 0 "Hold any button to quit rick roll";
delay 2000;

while {== [button_state] 0} {
	play "/BLING/AND!XOR/RICKROLL.RAW";
};

EXAMPLE4.TCL: Cycles the eye color hues.

cls;
print 0, 60 "The Eyes!";

for {set h 0} {< $h 100} {incr h} {
	led_set_hsv 12 $h 100 100; 
	led_set_hsv 13 $h 100 100;
	delay 100;	
};

EXAMPLE5.TCL: Prints text in the middle of the screen using ascii conversions

cls;

set base 42;
set w 4;
set x 0;
set y 60;
print [* $w $x] $y [chr [+ $base 79]];
incr x;
print [* $w $x] $y [chr [+ $base 53]];
incr x;
print [* $w $x] $y [chr [+ $base 23]];
incr x;
print [* $w $x] $y [chr [+ $base 36]];
incr x;
print [* $w $x] $y [chr [- 100 $base]];
incr x;
print [* $w $x] $y [chr [+ 66 $base]];
incr x;
print [* $w $x] $y [chr [+ 72 $base]];
incr x;
print [* $w $x] $y [chr [+ 36 $base]];
incr x;

delay 5000;

EXAMPLE6.TCL: Demonstrates drawing graphics to the display

cls;

for {set c 0} {< $c 256} {incr c} {
	fill_rect 0 0 128 128 $c;
	print 0 0 $c;
	delay 100;
}

image 0 0 128 128 "TCL/BENDER4.RAW";

line 128 0 0 128 252;
line 0 0 128 128 224;
line 0 62 128 62 3;

circle 96 32 8 224;

triangle 12 12 48 48 0 50 255;

rect 80 80 40 20 150;

fill_rect 10 80 10 40 100; 

delay 5000;

EXAMPLE7.TCL: Toggles IO 0 on and off

cls;
print 0 0 "Toggling IO 0 Low/High 100 times"

for {set i 0} {< $i 100} {incr i} {
	fill_rect 0 64 128 20 0
	print 0 64 $i
	io_write 0 HIGH;
	delay 400;
	io_write 0 LOW;
	delay 400;
}

EXAMPLE8.TCL: Prints random numbers to the screen

print 0, 0 "Random numbers"
print 0, 10 "< 100"
print 64, 10 [rand 100];
print 0, 20 "< 20"
print 64, 20 [rand 20];
print 0, 30 "< 100000"
print 64, 30 [rand 100000];
print 0, 64 "Press any button to continue"
button_wait;

Discussions

int3grate wrote 07/16/2017 at 03:00 point

anyway you could make it easy to do i2c on the GPIO pins? I'd like to hook up an RTC.

  Are you sure? yes | no