Recently, I bought and hacked “Danboard mini Amazon.co.jp Box Version”. Now my Danboard is a XFD (eXtreme Feedback Device), which is controlled from Arduino.
Hardware
Parts:
Danboard already has two LEDs on the eyes. However it’s white and I want red and green. So I opened Danboard’s head and switched LEDs.
To open the head, You’ll need to remove 2 screws.
Software
Danboard XFD has 3 states:
- Green (initial and success)
- Red (failed)
- Blink (testing)
I wrote a little C++ code for Arduino. It’s so easy because Arduino has very simple C++ library. The below code is reading USB serial and switching 3 states.
int COLOR_LEDS[2][3] = {
{ 3, 5, 6 },
{ 9, 10, 11 },
};
int RED[] = { 0xff, 0, 0 };
int GREEN[] = { 0, 0xff, 0 };
int* Left = GREEN;
int* Right = GREEN;
int Counter = 0;
void colorWrite(int index, int* color) {
for (int i = 0; i < 3; i++) {
analogWrite(COLOR_LEDS[index][i], color[i]);
}
}
void readAndEval() {
int c = Serial.read();
switch (c) {
case 'r':
Left = Right = RED;
break;
case 'g':
Left = Right = GREEN;
break;
case 'B':
Left = RED;
Right = GREEN;
break;
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
readAndEval();
}
colorWrite(Counter & 1, Left);
colorWrite(!(Counter & 1), Right);
Counter++;
delay(200);
}
And I wrote a little wrapper for prove (1).
#! /bin/sh
device='/dev/cu.usbserial-A700651k'
prove='/usr/bin/prove'
echo B > $device
$prove "$*"
if [ $? == 0 ]; then
echo g > $device
else
echo r > $device
fi
XFD is usually used for Continuous Integration but prove (1) is not for CI. It’s just a demo :)
I saw a beautiful picture at my friends Flickr, and I remembered my project glitchcam.
glitchcam is a realtime glitch software for a webcam. It’s heavily inspired from GlitchMonkey. GlitchMonkey bend images on the browser, and glitchcam bend images which received from your webcam.
So I refined a little and pushed the code to my Bitbucket. Enjoy!
Previously I wrote “merge_graph” method to drawing inheritance tree with Class::Sniff. But now, new Class::Sniff shipped with “combine_graphs” method and make obsolete my code :D
So I rewrite my two scripts:
use strict;
use warnings;
use Class::Sniff;
sub package_of {
my ($path) = @_;
if ($path !~ m|/?lib/(.*)\.pm$|) {
die;
}
my $result = $1;
$result =~ s|/|::|g;
return $result;
}
my @sniffs = map {
my $package = package_of($_);
eval "use $package";
Class::Sniff->new({ class => $package });
} @ARGV;
my $sniff = pop @sniffs;
print $sniff->combine_graphs(@sniffs)->as_graphviz;
use strict;
use warnings;
use Class::Sniff;
sub package_of {
my ($path) = @_;
if ($path !~ m|/?lib/(.*)\.pm$|) {
die;
}
my $result = $1;
$result =~ s|/|::|g;
return $result;
}
sub new_methods {
my ($sniffer) = @_;
my %count_of;
for my $method ($sniffer->methods) {
$count_of{$method}++;
}
my $klass = $sniffer->target_class;
for my $method (keys %{ $sniffer->exported->{ $klass } }) {
$count_of{$method}--;
}
grep { $_ } map {
my $method = $_;
($count_of{$method} > 0)? $method : undef;
} (keys %count_of);
}
my @sniffs = map {
my $package = package_of($_);
eval "use $package";
Class::Sniff->new({ class => $package });
} @ARGV;
my $labels = join "\n", map {
my @methods = new_methods($_);
my $label = '{\N\n|' . join('\l', sort @methods) . '\l}';
$label =~ s/"/\\"/g;
sprintf('"%s" [label="%s"]', $_->target_class, $label);
} @sniffs;
my $sniff = pop @sniffs;
my $graphviz = $sniff->combine_graphs(@sniffs)->as_graphviz;
# it's dirty...
$graphviz =~ s/}/$labels }/g;
$graphviz =~ s/shape=box/shape=record/g;
print $graphviz;
And update my gist with second.