Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Halo.pl! #2

Merged
merged 34 commits into from Oct 24, 2014
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fb14306
Add halo reduced.pl
Lordnibbler Aug 17, 2014
70eac39
Reduce halo more; add serialport script
Lordnibbler Aug 17, 2014
ce2df92
Initial implementation with serialport
Lordnibbler Aug 17, 2014
694062b
Padd instruction with black if necessary
Lordnibbler Aug 18, 2014
c4cb423
Log err/results of .write
Lordnibbler Aug 18, 2014
a64c152
drain message
Lordnibbler Aug 18, 2014
1e72017
drain implementation 1
Lordnibbler Aug 18, 2014
40862b3
update wifiboot
Aug 18, 2014
5abd1a7
drain implementation 1.1
Lordnibbler Aug 18, 2014
5e09e44
writestream implementation 1.0
Lordnibbler Aug 18, 2014
a502631
Remove logger statements slowing everything down!
Lordnibbler Aug 18, 2014
a04ddb2
Fix wifiboot service
Lordnibbler Aug 18, 2014
9f968cc
update gitignore
Lordnibbler Aug 18, 2014
478f6b9
Change resolution to 30ms
Lordnibbler Aug 18, 2014
8041345
Remove serialport
Lordnibbler Aug 18, 2014
607887a
setTimeout w/ return
Lordnibbler Aug 19, 2014
97d8c4a
setInterval
Lordnibbler Aug 19, 2014
ee89ac8
Use properties instead of globals
Lordnibbler Aug 19, 2014
475612d
setImmediate
Lordnibbler Aug 19, 2014
b263cd8
longer timeout
Lordnibbler Aug 21, 2014
2476b6b
only allow setImmediate to be fired every 50ms
Lordnibbler Aug 21, 2014
f574998
document our approaches
Lordnibbler Aug 21, 2014
123d84d
use array for buffer, send instructions in separate commands
Lordnibbler Aug 22, 2014
923f404
345 implementation
Lordnibbler Aug 22, 2014
b881d0c
345 improvement
Lordnibbler Aug 22, 2014
c43ef2b
back to setTimeout
Lordnibbler Aug 23, 2014
1aaf3d4
Update to socket.io 1.1.0
Lordnibbler Sep 20, 2014
b35f891
Setup test suite
Lordnibbler Sep 26, 2014
ac00c24
Try to clear timeout inside timer
Lordnibbler Sep 26, 2014
6422d7d
Handle production/development writestream logic
Lordnibbler Oct 21, 2014
44156af
Ensure we clearTimeout when disconnecting
Lordnibbler Oct 21, 2014
84aa764
Update readme and angstrom systemctl service templates
Lordnibbler Oct 22, 2014
1e966c0
Actually invoke disconnected callback
Lordnibbler Oct 23, 2014
9afe9ec
Remove unnecessary clearTimeout
Lordnibbler Oct 24, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1,2 +1,3 @@
colors.txt
node_modules/*
npm-debug.log
@@ -3,7 +3,7 @@ node_js:
- "0.10.30"
before_install:
script:
- "which node"
- "npm test"

env:
- NODE_ENV=test
112 README.md
@@ -4,7 +4,7 @@ A socket.io 1.0 client that connects to a [colorpicker-server](http://github.com
Its main purpose is to write rgb color data to a colors.txt file for [halo](https://github.com/lordnibbler/halo) to read.

## Getting Started
You'll need a [colorpicker-server](http://github.com/lordnibbler/colorpicker-server) instance running before this client is useful:
You'll need a [colorpicker-server](http://github.com/lordnibbler/colorpicker-server) instance running before this client is useful. You can deploy this server to a free host like Heroku or Nodejitsu, or test locally.

```sh
# set up the GUI and server
@@ -22,3 +22,113 @@ npm start
You should see a `connected to socket at http://127.0.0.1:1337` message.

Browse to <http://localhost:1337> to use the GUI.

## Configuring a Beaglebone Black with Angstrom Distro
You'll need to do three things:

1. upgrade Node.js
2. configure `systemctl` to set up reliable network connectivity at boot
3. configure `systemctl` to start `colorpicker-beaglebone` Node service at boot

### 1. Upgrade Node.js
I refer you to the [wonderful instructions at speakinbytes.com](http://speakinbytes.com/2013/12/update-beaglebone-black-angstrom-node-js-version/). I recommend the current stable version of node, currently 0.10.32. You'll need at LEAST 0.10.0.

### 2. Network Connectivity
My findings have been that `connman` is very unreliable, so I fell back to using `/etc/network/interfaces`. To disable connman:

```sh
systemctl disable connman.service
# double check
systemctl status connman.service
```

Edit `/etc/network/interfaces` with your editor of choice. For ethernet/hardwired internet connectivity the only logic you need here is the loopback and the `eth0` configuration, but there's also some example wifi, USB, and bluetooth configs here:

```sh
# /etc/network/interfaces
# configuration file for ifup(8), ifdown(8)
# The loopback interface
auto lo
iface lo inet loopback
# Wireless interfaces
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
iface atml0 inet dhcp
# Wired or wireless interfaces
auto eth0
iface eth0 inet dhcp
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.0
network 192.168.7.0
gateway 192.168.7.1
# Bluetooth networking
iface bnep0 inet dhcp
```

If you want additional help setting up WiFi, [this article](http://octopusprotos.com/?p=37) is handy.

After setting up your interfaces, configure a `systemctl` service to start ethernet connectivity at boot, touch a new file located at `/etc/systemd/system/net.service`:

```sh
# /etc/systemd/system/net.service
[Unit]
Description=Network interfaces
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "sleep 5; ifup eth0"
ExecStop=/bin/sh -c "ifdown eth0"
[Install]
WantedBy=multi-user.target
```

Then enable the service!

```sh
systemctl enable net.service
# double check
systemctl status net.service
```

You can check your connectivity using `ifconfig`.

3. Starting `colorpicker-beaglebone` at boot

To start this Beaglebone colorpicker client at boot, you can follow a similar approach to the network connectivity service. I have provided an example in the `/angstrom` directory of this repository.

First, touch a new file at `/lib/systemd/system/colorpickerbeaglebone.service` (ensure your paths are correct, these are an example):

```sh
# /lib/systemd/system/colorpickerbeaglebone.service
[Unit]
Description=colorpicker-beaglebone automatic start
[Service]
WorkingDirectory=/home/root/colorpicker-beaglebone/angstrom
ExecStart=/home/root/colorpicker-beaglebone/angstrom/colorpickerbeaglebone.sh
[Install]
WantedBy=multi-user.target
```

You can copy the contents of `/angstrom/colorpickerbeaglebone.sh` from this repo if you intend to use UART + Arduino to power the LEDs.
@@ -0,0 +1,9 @@
[Unit]
Description=Wifi Startup Retry

[Service]
WorkingDirectory=/home/root/colorpicker-beaglebone/wifiboot
ExecStart=/home/root/colorpicker-beaglebone/wifiboot/wifiboot.sh

[Install]
WantedBy=multi-user.target
@@ -0,0 +1,12 @@
#!/bin/sh -
sleep 10

# enable the UART1 in the device tree
echo BB-UART1 > /sys/devices/bone_capemgr.9/slots

# Set proper UART settings with STTY
stty -F /dev/ttyO1 speed 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

# start the node client application
cd /home/root/colorpicker-beaglebone/
NODE_ENV=production npm start
File renamed without changes.
@@ -0,0 +1,121 @@
#!/usr/bin/perl

# use Device::SerialPort;
use Time::HiRes qw(usleep time);
use POSIX ":sys_wait_h";
#use LWP::Simple qw (get);

# @FIXME missing this dir in github!
$cmddir = "/home/root/halo_git/commands/";

our $NUM_LIGHTS = 5;
my $SYSTEM_ON = 0;
my $LIVE_PREVIEW = 1;

@oldRgb;
for($j = 0;$j < $NUM_LIGHTS; $j++){
push(@{$oldRgb[$j]},(0,0,0,0));
}

# system("echo 20 > /sys/kernel/debug/omap_mux/uart1_rxd");
# system("echo 0 > /sys/kernel/debug/omap_mux/uart1_txd");
system("echo BB-UART1 > /sys/devices/bone_capemgr.9/slots");
system("stty -F /dev/ttyO1 speed 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts");

$|=1;

# Opens file whose filename is given by EXPR (> /dev/tty01), and associates it with FILEHANDLE (SERIAL)
open(SERIAL, "> /dev/ttyO1");

sysopen(PREVIEW_DATA, "/home/root/colorpicker-beaglebone/colors.txt", O_RONLY)
or die "can't read pipe: $!";

{
my $previous_default = select(STDOUT); # save previous default
select(SERIAL);
$|++; # autoflush STDERR, to be sure
select($previous_default); # restore previous default
}

# set all black
for(my $address = 0; $address < $NUM_LIGHTS; $address ++){
&sendColor($address,0,0,0,0);
}

sub sendColor {
my($address,$r,$g,$b,$v)= @_;
$address = $address + 1;
print SERIAL "4,$address,$r,$g,$b,$v;";
}

sub turnOffAll {
while(waitpid(-1,WNOHANG ) >= 0) {}
for(my $address = 0; $address < $NUM_LIGHTS; $address ++){
&sendColor($address,0,0,0,0);
@{$oldRgb[$address]} = (0,0,0,0);
}
}



$start_time = time();

sub grabLiveData{
# print @preview_data;

$rin = '';
vec($rin, fileno(PREVIEW_DATA), 1) = 1;
$nfound = select($rin, undef, undef, 0); # just check
if ($nfound) {
@processed_data = ();
while($color = <PREVIEW_DATA>){
#print $color;
#print "Glen\n";
if($color =~ /.*END_LINE.*/){
# print "END_FILE FOUND\n";
last;
}
if($color =~ /([0-9]+)\,([0-9]+)\,([0-9]+)\,([0-9]+)/){
# print "$1, $2, $3, $4 found\n";
my @rgb = ($1,$2,$3,0);
push(@processed_data,[@rgb]);
}
}

# close PREVIEW_DATA or die "bad netstat: $! $?";
$previewLength = @processed_data;
if( $previewLength > 0){
my $end_time = time();
printf("%d %.6f\n", $previewLength,$end_time - $start_time);
$start_time = time();
# print "$previewLength data chunks\n";
$start =0;
if($previewLength > $NUM_LIGHTS){
$start = $previewLength - $NUM_LIGHTS;
}else{
$start = 0;
}
# print "i is $i, total size is $previewLength";
$address = 0;
for($i = $start;$i< $previewLength; $i ++){
my @rgb = @{$processed_data[$i]};
# print @rgb;
# printf("address %d R= %d G=%d B=%d\n",$address,$rgb[0],$rgb[1],$rgb[2],$rgb[3]);
&sendColor($address,$rgb[0],$rgb[1],$rgb[2],$rgb[3]);
$address ++;
}
if($previewLength < $NUM_LIGHTS){
while($address < $NUM_LIGHTS){
&sendColor($address,0,0,0,0);
$address ++;
}
}
}
}
}

while(1){
if($LIVE_PREVIEW == 1){
&grabLiveData();
}
}
File renamed without changes.
File renamed without changes.
@@ -1,10 +1,10 @@
{
"name": "colorpicker-beaglebone",
"version": "1.0.6",
"version": "1.1.0",
"description": "A beaglebone Node.js client to listen to colorpicker, and pipe current color data into a writeStream.",
"scripts": {
"start": "coffee index.coffee",
"test": "npm test"
"test": "mocha"
},
"repository": {
"type": "git",
@@ -16,13 +16,18 @@
"url": "https://github.com/Lordnibbler/colorpicker-beaglebone/issues"
},
"dependencies": {
"log": "~1.4.0",
"coffee-script": "~1.7",
"socket.io": "~1.0.6",
"socket.io-client": "~1.0.6"
"log": "~1.4.0",
"socket.io": "~1.1.0",
"socket.io-client": "~1.1.0"
},
"engines": {
"node": "0.10.x",
"node": "0.10.32",
"npm": "1.3.x"
},
"devDependencies": {
"chai": "^1.9.1",
"mocha": "^1.21.4",
"sinon": "^1.10.3"
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.