From fb14306e0d5f3e33ffe24b7db6c18e5871545122 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 12:03:49 -0700 Subject: [PATCH 01/34] Add halo reduced.pl --- wifiboot/halo-reduced.pl | 164 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 wifiboot/halo-reduced.pl diff --git a/wifiboot/halo-reduced.pl b/wifiboot/halo-reduced.pl new file mode 100644 index 0000000..a90d0de --- /dev/null +++ b/wifiboot/halo-reduced.pl @@ -0,0 +1,164 @@ +#!/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); + } +} + +sub handleCommands{ + opendir my($dh), $cmddir or die "Couldn't open dir '$dirname': $!"; + my @files = grep { !/^\./ } readdir $dh; + closedir $dh; + usleep(1000); + foreach $filename (@files){ + print "$filename found, opening...\n"; + $fullname = "$cmddir$filename"; + open (COMMAND_FILE, "< $fullname"); + $command = ; + print "read $command\n"; + + if ($command =~ /POWER\s+([0-1])/){ + $SYSTEM_ON = $1; + if($SYSTEM_ON == 0){ + &turnOffAll(); + } + }elsif ($command =~ /ACTIVE_PLAYLIST\s+([\w0-9]*)/){ + openPlaylist($1); + }elsif ($command =~ /CHANGE_LIGHT/){ + print "Previewing\n"; + $SYSTEM_ON = 0; + while($color = ){ + # for(my $address = 0; $address < $NUM_LIGHTS; $address ++){ + if($color =~ /([0-9]+)\,([0-9]+)\,([0-9]+)\,([0-9]+)/){ + print "$1, $2, $3, $4 found\n"; + &sendColor($address,$1,$2,$3,$4); + } + + } + }elsif ($command =~ /LIVE_PREVIEW\s+([\w0-9]*)/){ + $LIVE_PREVIEW = $1; + $SYSTEM_ON = 0; + } + close(COMMAND_FILE); + unlink($fullname); + + } + +} + +$start_time = time(); + +sub grabLiveData{ + # open(COLORS, '|-', "wget -q -O- http://colorpicker.herokuapp.com/api/redis_get_colors"); + # open(PREVIEW_DATA, "wget -q -O- http://colorpicker.herokuapp.com/api/redis_get_colors 2>/dev/null |"); + # 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 = ){ + #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){ + &handleCommands(); + if($LIVE_PREVIEW == 1){ + &grabLiveData(); + } +} From 70eac3934b6f6ea79afd2b72eb04536034b563b7 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 15:58:23 -0700 Subject: [PATCH 02/34] Reduce halo more; add serialport script --- node-serialport.js | 18 +++++++++++++++ wifiboot/halo-reduced.pl | 47 ++-------------------------------------- 2 files changed, 20 insertions(+), 45 deletions(-) create mode 100644 node-serialport.js diff --git a/node-serialport.js b/node-serialport.js new file mode 100644 index 0000000..35bfc6d --- /dev/null +++ b/node-serialport.js @@ -0,0 +1,18 @@ +// npm install node-serialport + + +var SerialPort = require("serialport").SerialPort; +var serialPort = new SerialPort("/dev/tty01", { + baudrate: 115200 +}); + +serialPort.on("open", function () { + console.log('open'); + serialPort.on('data', function(data) { + console.log('data received: ' + data); + }); + serialPort.write('4,1,255,000,000,000;', function(err, results) { + console.log('err ' + err); + console.log('results ' + results); + }); +}); diff --git a/wifiboot/halo-reduced.pl b/wifiboot/halo-reduced.pl index a90d0de..0dc237b 100644 --- a/wifiboot/halo-reduced.pl +++ b/wifiboot/halo-reduced.pl @@ -5,8 +5,7 @@ use POSIX ":sys_wait_h"; #use LWP::Simple qw (get); -# @FIXME -# missing this dir in github! +# @FIXME missing this dir in github! $cmddir = "/home/root/halo_git/commands/"; our $NUM_LIGHTS = 5; @@ -57,52 +56,11 @@ sub turnOffAll { } } -sub handleCommands{ - opendir my($dh), $cmddir or die "Couldn't open dir '$dirname': $!"; - my @files = grep { !/^\./ } readdir $dh; - closedir $dh; - usleep(1000); - foreach $filename (@files){ - print "$filename found, opening...\n"; - $fullname = "$cmddir$filename"; - open (COMMAND_FILE, "< $fullname"); - $command = ; - print "read $command\n"; - - if ($command =~ /POWER\s+([0-1])/){ - $SYSTEM_ON = $1; - if($SYSTEM_ON == 0){ - &turnOffAll(); - } - }elsif ($command =~ /ACTIVE_PLAYLIST\s+([\w0-9]*)/){ - openPlaylist($1); - }elsif ($command =~ /CHANGE_LIGHT/){ - print "Previewing\n"; - $SYSTEM_ON = 0; - while($color = ){ - # for(my $address = 0; $address < $NUM_LIGHTS; $address ++){ - if($color =~ /([0-9]+)\,([0-9]+)\,([0-9]+)\,([0-9]+)/){ - print "$1, $2, $3, $4 found\n"; - &sendColor($address,$1,$2,$3,$4); - } - - } - }elsif ($command =~ /LIVE_PREVIEW\s+([\w0-9]*)/){ - $LIVE_PREVIEW = $1; - $SYSTEM_ON = 0; - } - close(COMMAND_FILE); - unlink($fullname); - - } -} $start_time = time(); sub grabLiveData{ - # open(COLORS, '|-', "wget -q -O- http://colorpicker.herokuapp.com/api/redis_get_colors"); - # open(PREVIEW_DATA, "wget -q -O- http://colorpicker.herokuapp.com/api/redis_get_colors 2>/dev/null |"); # print @preview_data; $rin = ''; @@ -157,8 +115,7 @@ sub grabLiveData{ } while(1){ - &handleCommands(); if($LIVE_PREVIEW == 1){ - &grabLiveData(); + &grabLiveData(); } } From ce2df92ee3ff6fbcd9a36b4a4a6d9fe1ed7f1964 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 16:28:38 -0700 Subject: [PATCH 03/34] Initial implementation with serialport --- node-serialport.js | 2 +- package.json | 3 +- src/server.coffee | 73 +++++++++++++++++++++++++++++++++------------- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/node-serialport.js b/node-serialport.js index 35bfc6d..4ad0a78 100644 --- a/node-serialport.js +++ b/node-serialport.js @@ -2,7 +2,7 @@ var SerialPort = require("serialport").SerialPort; -var serialPort = new SerialPort("/dev/tty01", { +var serialPort = new SerialPort("/dev/ttyO1", { baudrate: 115200 }); diff --git a/package.json b/package.json index 5fa5e48..2294d60 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "url": "https://github.com/Lordnibbler/colorpicker-beaglebone/issues" }, "dependencies": { - "log": "~1.4.0", "coffee-script": "~1.7", + "log": "~1.4.0", + "serialport": "~1.4.5", "socket.io": "~1.0.6", "socket.io-client": "~1.0.6" }, diff --git a/src/server.coffee b/src/server.coffee index a7a2ca6..b40cfc6 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -1,40 +1,73 @@ -Http = require 'http' -io = require 'socket.io-client' -logger = require './logger' -FS = require 'fs' +Http = require 'http' +io = require 'socket.io-client' +SerialPort = require('serialport').SerialPort +logger = require './logger' +FS = require 'fs' +serial_port = undefined class Server constructor: (@host, @port, @options = {}) -> + # + # connect to tty and socket.io + # + run: (callback) -> + # @_setup_sio() + @_setup_serialport() + # # @return [String] URL based on config # - url: -> + _url: -> "http://#{ @host }#{ if @port? then ":#{@port}" else '' }/#{ @options.namespace }" # # connect socket.io client to url, bind to socket.io events and our custom events # - run: (callback) -> - logger.debug "Connecting to url #{@url()}" - socket = new io(@url(), {}) - - socket.on 'connect', => console.log "connected to socket at #{@url()}" + _setup_sio: -> + logger.debug "Socket.io connecting to url #{@_url()}" + socket = new io(@_url(), {}) + socket.on 'connect', => console.log "connected to socket at #{@_url()}" socket.on 'connect_error', (obj) => console.log 'connect error', obj - socket.on 'disconnect', => console.log "socket at #{@url()} disconnected" - socket.on 'colorChanged', @_write_colors_data_to_file - socket.on 'colorSet', @_write_colors_data_to_file + socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" + socket.on 'colorChanged', @_write_colors_over_tty + socket.on 'colorSet', @_write_colors_over_tty # - # write our preformatted backbone.js color data to colors.txt + # connect to /dev/ttyO1, on success fire a call to _setup_sio() # - _write_colors_data_to_file: (data) -> - logger.debug JSON.stringify(data, null, 2) + _setup_serialport: -> + tty = '/dev/ttyO1' + logger.debug "Node serialport connecting to #{tty}" - ws = FS.createWriteStream("#{__dirname}/../colors.txt", { flags: "w+" }) - ws.write(data.color, (err, written) -> - throw err if err - ws.end() + serial_port = new SerialPort(tty, + baudrate: 115200 ) + serial_port.on "open", => + console.log "Node serialport connected to #{tty}" + + @_setup_sio() + + serial_port.on 'data', (data) -> + console.log 'data received: ' + data + + # + # break our colors string into array, write each color to the appropriate address + # @example data + # { color: '000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n' } + # + _write_colors_over_tty: (data) -> + logger.debug '_write_colors_over_tty' + + colors = data.color.split '\n' + colors.pop() + + logger.debug "colors: #{colors} length: #{colors.length}" + instruction = '' + for color, i in colors + instruction += "4,#{i+1},#{color};" + logger.debug "writing to serial port: #{instruction}" + serial_port.write instruction + module.exports = Server From 694062b7884f24711b017af9a4a4e3a0db323805 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 18:42:40 -0700 Subject: [PATCH 04/34] Padd instruction with black if necessary --- src/server.coffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index b40cfc6..aae9822 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -60,13 +60,20 @@ class Server _write_colors_over_tty: (data) -> logger.debug '_write_colors_over_tty' + # break colors string into array colors = data.color.split '\n' colors.pop() + # build our TTY instruction, padding with black if necessary logger.debug "colors: #{colors} length: #{colors.length}" instruction = '' - for color, i in colors - instruction += "4,#{i+1},#{color};" + instruction += "4,#{i+1},#{color};" for color, i in colors + + instruction_count = (instruction.match(/;/g)||[]).length + for i in [instruction_count...5] + instruction += "4,#{i+1},000,000,000,000;" + + # write over TTY logger.debug "writing to serial port: #{instruction}" serial_port.write instruction From c4cb4235378a1fdd6c1071a8c00f77c162161e15 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 18:59:33 -0700 Subject: [PATCH 05/34] Log err/results of .write --- src/server.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server.coffee b/src/server.coffee index aae9822..6341e57 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -75,6 +75,8 @@ class Server # write over TTY logger.debug "writing to serial port: #{instruction}" - serial_port.write instruction + serial_port.write instruction, (err, results) -> + logger.debug 'serial_port.write err: ' + err if err + logger.debug 'serial_port.write results: ' + results if results module.exports = Server From a64c152af8535c9e4dc3c2278dc0f9d99085d41f Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 19:22:22 -0700 Subject: [PATCH 06/34] drain message --- src/server.coffee | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 6341e57..1ee8497 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -30,7 +30,9 @@ class Server socket.on 'connect', => console.log "connected to socket at #{@_url()}" socket.on 'connect_error', (obj) => console.log 'connect error', obj socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" - socket.on 'colorChanged', @_write_colors_over_tty + socket.on 'colorChanged', (data) => + @_write_colors_over_tty(data) + socket.on 'colorSet', @_write_colors_over_tty # @@ -45,12 +47,13 @@ class Server ) serial_port.on "open", => - console.log "Node serialport connected to #{tty}" + logger.info "Node serialport connected to #{tty}" + logger.debug serial_port @_setup_sio() serial_port.on 'data', (data) -> - console.log 'data received: ' + data + logger.info 'data received: ' + data # # break our colors string into array, write each color to the appropriate address @@ -64,11 +67,12 @@ class Server colors = data.color.split '\n' colors.pop() - # build our TTY instruction, padding with black if necessary + # build our TTY instruction logger.debug "colors: #{colors} length: #{colors.length}" instruction = '' instruction += "4,#{i+1},#{color};" for color, i in colors + # padding with black if necessary instruction_count = (instruction.match(/;/g)||[]).length for i in [instruction_count...5] instruction += "4,#{i+1},000,000,000,000;" @@ -78,5 +82,8 @@ class Server serial_port.write instruction, (err, results) -> logger.debug 'serial_port.write err: ' + err if err logger.debug 'serial_port.write results: ' + results if results + serial_port.drain( (error) -> + logger.debug "serial_port drained! with error: #{error}" + ) module.exports = Server From 1e720171aa7f5dc983e60e23256ec2563fb50c8e Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 21:15:33 -0700 Subject: [PATCH 07/34] drain implementation 1 --- src/server.coffee | 97 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 1ee8497..a07323b 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -1,10 +1,10 @@ -Http = require 'http' -io = require 'socket.io-client' -SerialPort = require('serialport').SerialPort -logger = require './logger' -FS = require 'fs' +Http = require 'http' +io = require 'socket.io-client' +SerialPort = require('serialport').SerialPort +logger = require './logger' +FS = require 'fs' serial_port = undefined - +buffer = '' class Server constructor: (@host, @port, @options = {}) -> @@ -12,7 +12,6 @@ class Server # connect to tty and socket.io # run: (callback) -> - # @_setup_sio() @_setup_serialport() # @@ -27,13 +26,16 @@ class Server _setup_sio: -> logger.debug "Socket.io connecting to url #{@_url()}" socket = new io(@_url(), {}) - socket.on 'connect', => console.log "connected to socket at #{@_url()}" + socket.on 'connect', => + console.log "connected to socket at #{@_url()}" + + # make an initial call to our recursive serialport write method + @_write_buffer() + socket.on 'connect_error', (obj) => console.log 'connect error', obj socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" - socket.on 'colorChanged', (data) => - @_write_colors_over_tty(data) - - socket.on 'colorSet', @_write_colors_over_tty + socket.on 'colorChanged', @_to_buffer + socket.on 'colorSet', @_to_buffer # # connect to /dev/ttyO1, on success fire a call to _setup_sio() @@ -56,13 +58,12 @@ class Server logger.info 'data received: ' + data # - # break our colors string into array, write each color to the appropriate address - # @example data - # { color: '000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n' } + # convert halo rgba string to a UART instruction + # @example + # _data_to_instruction({ color: '000,110,255,000\n' }) + # # => '4,1,000,110,255,000;' # - _write_colors_over_tty: (data) -> - logger.debug '_write_colors_over_tty' - + _data_to_instruction: (data) -> # break colors string into array colors = data.color.split '\n' colors.pop() @@ -74,16 +75,54 @@ class Server # padding with black if necessary instruction_count = (instruction.match(/;/g)||[]).length - for i in [instruction_count...5] - instruction += "4,#{i+1},000,000,000,000;" - - # write over TTY - logger.debug "writing to serial port: #{instruction}" - serial_port.write instruction, (err, results) -> - logger.debug 'serial_port.write err: ' + err if err - logger.debug 'serial_port.write results: ' + results if results - serial_port.drain( (error) -> - logger.debug "serial_port drained! with error: #{error}" - ) + instruction += "4,#{i+1},000,000,000,000;" for i in [instruction_count...5] + return instruction + + # + # write contents (UART instruction) of buffer to serial port. + # when serial port drains, clear the buffer and recursively call the function again + # + _write_buffer: -> + setTimeout (=> + logger.info "writing buffer '#{buffer}' to serial port" + serial_port.write buffer, (err, results) => + logger.info "serial port written" + + serial_port.drain((error) => + logger.info "serial port drained" + @_clear_buffer() + @_write_buffer() + ) + ), 1000 + + # + # write socket.io color data to buffer as UART instruction + # + _to_buffer: (data) -> + logger.info "writing to buffer #{data.color}" + buffer += @_data_to_instruction(data) + + _clear_buffer: -> + logger.info "clearing buffer" + buffer = '' + + # + # break our colors string into array, write each color to the appropriate address + # @example data + # { color: '000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n' } + # + # _write_colors_over_tty: (data) -> + # logger.debug '_write_colors_over_tty' + # instruction = @_data_to_instruction(data) + # + # # write over TTY + # logger.debug "writing to serial port: #{instruction}" + # serial_port.write instruction, (err, results) -> + # logger.debug 'serial_port.write err: ' + err if err + # logger.debug 'serial_port.write results: ' + results if results + # serial_port.drain( (error) -> + # logger.debug "serial_port drained! with error: #{error}" + # ) + module.exports = Server From 40862b351dd2a5c31339f750ed0c687ca6d50199 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Aug 2014 22:28:31 -0700 Subject: [PATCH 08/34] update wifiboot --- wifiboot.service | 9 --------- wifiboot/wifiboot.sh | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 wifiboot.service diff --git a/wifiboot.service b/wifiboot.service deleted file mode 100644 index 1c95343..0000000 --- a/wifiboot.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Wifi Startup Retry - -[Service] -WorkingDirectory=/home/root/wifiboot/ -ExecStart=/home/root/wifiboot/wifiboot.sh - -[Install] -WantedBy=multi-user.target diff --git a/wifiboot/wifiboot.sh b/wifiboot/wifiboot.sh index a1dfd98..d9ecc9d 100755 --- a/wifiboot/wifiboot.sh +++ b/wifiboot/wifiboot.sh @@ -2,13 +2,23 @@ sleep 10 #systemctl restart connman.service +#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 + #python ping_test.py >/dev/null & cd /home/root/halo_git/ -./Halo_Master.pl > /dev/null & +#./Halo_Master.pl > /dev/null & cd /home/root/colorpicker-beaglebone/ -NODE_ENV=production npm start +#NODE_ENV=production npm start From 5abd1a71b977196e42cbbf3af0ab0b5273ce799f Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 22:33:13 -0700 Subject: [PATCH 09/34] drain implementation 1.1 --- src/server.coffee | 60 +++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index a07323b..fc36712 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -34,8 +34,11 @@ class Server socket.on 'connect_error', (obj) => console.log 'connect error', obj socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" - socket.on 'colorChanged', @_to_buffer - socket.on 'colorSet', @_to_buffer + socket.on 'colorChanged', (data) => + @_to_buffer(data) + + socket.on 'colorSet', (data) => + @_to_buffer(data) # # connect to /dev/ttyO1, on success fire a call to _setup_sio() @@ -64,6 +67,7 @@ class Server # # => '4,1,000,110,255,000;' # _data_to_instruction: (data) -> + console.log "called _data_to_instruction" # break colors string into array colors = data.color.split '\n' colors.pop() @@ -75,7 +79,8 @@ class Server # padding with black if necessary instruction_count = (instruction.match(/;/g)||[]).length - instruction += "4,#{i+1},000,000,000,000;" for i in [instruction_count...5] + for i in [instruction_count...5] + instruction += "4,#{i+1},000,000,000,000;" return instruction # @@ -84,45 +89,34 @@ class Server # _write_buffer: -> setTimeout (=> - logger.info "writing buffer '#{buffer}' to serial port" - serial_port.write buffer, (err, results) => - logger.info "serial port written" - - serial_port.drain((error) => - logger.info "serial port drained" - @_clear_buffer() - @_write_buffer() - ) - ), 1000 + if buffer.length == 0 + @_write_buffer() + return + else + logger.info "writing buffer '#{buffer}' to serial port" + serial_port.write buffer, (err, results) => + logger.info "serial port written" + + serial_port.drain((error) => + logger.info "serial port drained" + @_clear_buffer() + @_write_buffer() + ) + ), 50 # # write socket.io color data to buffer as UART instruction # _to_buffer: (data) -> + # @_clear_buffer(); logger.info "writing to buffer #{data.color}" - buffer += @_data_to_instruction(data) + buffer = @_data_to_instruction(data) + # + # empty the buffer + # _clear_buffer: -> logger.info "clearing buffer" buffer = '' - # - # break our colors string into array, write each color to the appropriate address - # @example data - # { color: '000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n000,110,255,000\n' } - # - # _write_colors_over_tty: (data) -> - # logger.debug '_write_colors_over_tty' - # instruction = @_data_to_instruction(data) - # - # # write over TTY - # logger.debug "writing to serial port: #{instruction}" - # serial_port.write instruction, (err, results) -> - # logger.debug 'serial_port.write err: ' + err if err - # logger.debug 'serial_port.write results: ' + results if results - # serial_port.drain( (error) -> - # logger.debug "serial_port drained! with error: #{error}" - # ) - - module.exports = Server From 5e09e44174d32d42114c983d650d7182426fa064 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 23:19:49 -0700 Subject: [PATCH 10/34] writestream implementation 1.0 --- src/server.coffee | 70 ++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index fc36712..c97e787 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -5,6 +5,8 @@ logger = require './logger' FS = require 'fs' serial_port = undefined buffer = '' +ws = undefined + class Server constructor: (@host, @port, @options = {}) -> @@ -12,7 +14,8 @@ class Server # connect to tty and socket.io # run: (callback) -> - @_setup_serialport() + @_setup_writestream() + @_setup_sio() # # @return [String] URL based on config @@ -30,35 +33,31 @@ class Server console.log "connected to socket at #{@_url()}" # make an initial call to our recursive serialport write method - @_write_buffer() + @_write_file() socket.on 'connect_error', (obj) => console.log 'connect error', obj socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" - socket.on 'colorChanged', (data) => - @_to_buffer(data) - - socket.on 'colorSet', (data) => - @_to_buffer(data) + socket.on 'colorChanged', (data) => @_to_buffer(data) + socket.on 'colorSet', (data) => @_to_buffer(data) # # connect to /dev/ttyO1, on success fire a call to _setup_sio() # - _setup_serialport: -> - tty = '/dev/ttyO1' - logger.debug "Node serialport connecting to #{tty}" - - serial_port = new SerialPort(tty, - baudrate: 115200 - ) - - serial_port.on "open", => - logger.info "Node serialport connected to #{tty}" - logger.debug serial_port - - @_setup_sio() + _setup_writestream: -> + ws = FS.createWriteStream("/dev/ttyO1", { flags: "w+" }); - serial_port.on 'data', (data) -> - logger.info 'data received: ' + data + _write_file: -> + setTimeout (=> + if buffer.length == 0 + @_write_file() + return + else + ws.write(buffer, (err, written) => + throw err if err + # ws.end() + @_write_file() + ) + ), 25 # # convert halo rgba string to a UART instruction @@ -68,6 +67,8 @@ class Server # _data_to_instruction: (data) -> console.log "called _data_to_instruction" + console.log data + # break colors string into array colors = data.color.split '\n' colors.pop() @@ -79,36 +80,13 @@ class Server # padding with black if necessary instruction_count = (instruction.match(/;/g)||[]).length - for i in [instruction_count...5] - instruction += "4,#{i+1},000,000,000,000;" + instruction += "4,#{i+1},000,000,000,000;" for i in [instruction_count...5] return instruction - # - # write contents (UART instruction) of buffer to serial port. - # when serial port drains, clear the buffer and recursively call the function again - # - _write_buffer: -> - setTimeout (=> - if buffer.length == 0 - @_write_buffer() - return - else - logger.info "writing buffer '#{buffer}' to serial port" - serial_port.write buffer, (err, results) => - logger.info "serial port written" - - serial_port.drain((error) => - logger.info "serial port drained" - @_clear_buffer() - @_write_buffer() - ) - ), 50 - # # write socket.io color data to buffer as UART instruction # _to_buffer: (data) -> - # @_clear_buffer(); logger.info "writing to buffer #{data.color}" buffer = @_data_to_instruction(data) From a502631c91abd86a3f4cdbc30af83acacf19b59d Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 23:45:18 -0700 Subject: [PATCH 11/34] Remove logger statements slowing everything down! --- src/server.coffee | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index c97e787..ca95c6e 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -27,7 +27,7 @@ class Server # connect socket.io client to url, bind to socket.io events and our custom events # _setup_sio: -> - logger.debug "Socket.io connecting to url #{@_url()}" + # logger.debug "Socket.io connecting to url #{@_url()}" socket = new io(@_url(), {}) socket.on 'connect', => console.log "connected to socket at #{@_url()}" @@ -52,12 +52,14 @@ class Server @_write_file() return else + console.log "writing to file" + console.log buffer ws.write(buffer, (err, written) => throw err if err - # ws.end() + buffer = '' @_write_file() ) - ), 25 + ), 15 # # convert halo rgba string to a UART instruction @@ -66,15 +68,15 @@ class Server # # => '4,1,000,110,255,000;' # _data_to_instruction: (data) -> - console.log "called _data_to_instruction" - console.log data + # console.log "called _data_to_instruction" + # console.log data # break colors string into array colors = data.color.split '\n' colors.pop() # build our TTY instruction - logger.debug "colors: #{colors} length: #{colors.length}" + # logger.debug "colors: #{colors} length: #{colors.length}" instruction = '' instruction += "4,#{i+1},#{color};" for color, i in colors @@ -87,14 +89,14 @@ class Server # write socket.io color data to buffer as UART instruction # _to_buffer: (data) -> - logger.info "writing to buffer #{data.color}" + # logger.info "writing to buffer #{data.color}" buffer = @_data_to_instruction(data) # # empty the buffer # _clear_buffer: -> - logger.info "clearing buffer" + # logger.info "clearing buffer" buffer = '' module.exports = Server From a04ddb26379e35bd149feaa09a5bf6ac656e9822 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Sun, 17 Aug 2014 23:57:58 -0700 Subject: [PATCH 12/34] Fix wifiboot service --- src/server.coffee | 33 +++++++++++++-------------------- wifiboot/wifiboot.sh | 21 +++++---------------- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index ca95c6e..cf96209 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -11,7 +11,7 @@ class Server constructor: (@host, @port, @options = {}) -> # - # connect to tty and socket.io + # connect to kernel and socket.io # run: (callback) -> @_setup_writestream() @@ -32,8 +32,8 @@ class Server socket.on 'connect', => console.log "connected to socket at #{@_url()}" - # make an initial call to our recursive serialport write method - @_write_file() + # make an initial call to our recursive _write_pipe() method + @_write_pipe() socket.on 'connect_error', (obj) => console.log 'connect error', obj socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" @@ -41,23 +41,26 @@ class Server socket.on 'colorSet', (data) => @_to_buffer(data) # - # connect to /dev/ttyO1, on success fire a call to _setup_sio() + # create writestream to kernel at /dev/ttyO1 # _setup_writestream: -> - ws = FS.createWriteStream("/dev/ttyO1", { flags: "w+" }); + ws = FS.createWriteStream "/dev/ttyO1", + flags: "w+" - _write_file: -> + # + # write buffer directly to the kernel via /dev/ttyO1 pipe + # if buffer has content, at 15ms resolution. recursively call this function on success + # + _write_pipe: -> setTimeout (=> if buffer.length == 0 - @_write_file() + @_write_pipe() return else - console.log "writing to file" - console.log buffer ws.write(buffer, (err, written) => throw err if err buffer = '' - @_write_file() + @_write_pipe() ) ), 15 @@ -68,9 +71,6 @@ class Server # # => '4,1,000,110,255,000;' # _data_to_instruction: (data) -> - # console.log "called _data_to_instruction" - # console.log data - # break colors string into array colors = data.color.split '\n' colors.pop() @@ -92,11 +92,4 @@ class Server # logger.info "writing to buffer #{data.color}" buffer = @_data_to_instruction(data) - # - # empty the buffer - # - _clear_buffer: -> - # logger.info "clearing buffer" - buffer = '' - module.exports = Server diff --git a/wifiboot/wifiboot.sh b/wifiboot/wifiboot.sh index d9ecc9d..95b908c 100755 --- a/wifiboot/wifiboot.sh +++ b/wifiboot/wifiboot.sh @@ -1,24 +1,13 @@ #!/bin/sh - sleep 10 -#systemctl restart connman.service -#enable the UART1 in the device tree +# 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 - -#python ping_test.py >/dev/null & - -cd /home/root/halo_git/ - -#./Halo_Master.pl > /dev/null & +# 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 cd /home/root/colorpicker-beaglebone/ -#NODE_ENV=production npm start - +# start the node client application +NODE_ENV=production npm start From 9f968cc2f340fb7c6e2ed4ac1aa98808c8d8be01 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 00:35:41 -0700 Subject: [PATCH 13/34] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bca4155..d3904c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ colors.txt node_modules/* +npm-debug.log From 478f6b9b8d2b8e660746813ebc450a18d79a4672 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 10:59:31 -0700 Subject: [PATCH 14/34] Change resolution to 30ms --- src/server.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index cf96209..adf54bd 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -49,7 +49,7 @@ class Server # # write buffer directly to the kernel via /dev/ttyO1 pipe - # if buffer has content, at 15ms resolution. recursively call this function on success + # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> setTimeout (=> @@ -62,7 +62,7 @@ class Server buffer = '' @_write_pipe() ) - ), 15 + ), 30 # # convert halo rgba string to a UART instruction From 8041345751ab69bcf91919e68bc996c08198ee68 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 11:00:15 -0700 Subject: [PATCH 15/34] Remove serialport --- node-serialport.js | 18 ------------------ package.json | 1 - src/server.coffee | 14 ++++++-------- 3 files changed, 6 insertions(+), 27 deletions(-) delete mode 100644 node-serialport.js diff --git a/node-serialport.js b/node-serialport.js deleted file mode 100644 index 4ad0a78..0000000 --- a/node-serialport.js +++ /dev/null @@ -1,18 +0,0 @@ -// npm install node-serialport - - -var SerialPort = require("serialport").SerialPort; -var serialPort = new SerialPort("/dev/ttyO1", { - baudrate: 115200 -}); - -serialPort.on("open", function () { - console.log('open'); - serialPort.on('data', function(data) { - console.log('data received: ' + data); - }); - serialPort.write('4,1,255,000,000,000;', function(err, results) { - console.log('err ' + err); - console.log('results ' + results); - }); -}); diff --git a/package.json b/package.json index 2294d60..00f7ef7 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "dependencies": { "coffee-script": "~1.7", "log": "~1.4.0", - "serialport": "~1.4.5", "socket.io": "~1.0.6", "socket.io-client": "~1.0.6" }, diff --git a/src/server.coffee b/src/server.coffee index adf54bd..a9b471c 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -1,11 +1,9 @@ -Http = require 'http' -io = require 'socket.io-client' -SerialPort = require('serialport').SerialPort -logger = require './logger' -FS = require 'fs' -serial_port = undefined -buffer = '' -ws = undefined +Http = require 'http' +io = require 'socket.io-client' +logger = require './logger' +FS = require 'fs' +buffer = '' +ws = undefined class Server constructor: (@host, @port, @options = {}) -> From 607887a7a58a64489c5162d7302b3b5c6ae8bd22 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 19:10:01 -0700 Subject: [PATCH 16/34] setTimeout w/ return --- src/server.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server.coffee b/src/server.coffee index a9b471c..4894986 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -51,6 +51,7 @@ class Server # _write_pipe: -> setTimeout (=> + console.log "setTimeout called with buffer #{buffer}" if buffer.length == 0 @_write_pipe() return @@ -60,6 +61,7 @@ class Server buffer = '' @_write_pipe() ) + return ), 30 # From 97d8c4a926049d5d88340392e44d7372a0860f0e Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 19:15:19 -0700 Subject: [PATCH 17/34] setInterval --- src/server.coffee | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 4894986..e948b62 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,19 +50,16 @@ class Server # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> - setTimeout (=> - console.log "setTimeout called with buffer #{buffer}" - if buffer.length == 0 - @_write_pipe() - return - else - ws.write(buffer, (err, written) => - throw err if err - buffer = '' - @_write_pipe() - ) - return - ), 30 + setInterval (=> + # console.log "setInterval called with buffer #{buffer}" + return if buffer.length == 0 + ws.write(buffer, (err, written) => + throw err if err + buffer = '' + # @_write_pipe() + ) + # return + ), 15 # # convert halo rgba string to a UART instruction From ee89ac8a8d3ab4bd864331fa1bf497017a474560 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 18 Aug 2014 22:19:43 -0700 Subject: [PATCH 18/34] Use properties instead of globals --- src/server.coffee | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index e948b62..9c293ac 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -2,10 +2,11 @@ Http = require 'http' io = require 'socket.io-client' logger = require './logger' FS = require 'fs' -buffer = '' -ws = undefined class Server + buffer: '' + ws: undefined + constructor: (@host, @port, @options = {}) -> # @@ -25,10 +26,9 @@ class Server # connect socket.io client to url, bind to socket.io events and our custom events # _setup_sio: -> - # logger.debug "Socket.io connecting to url #{@_url()}" socket = new io(@_url(), {}) socket.on 'connect', => - console.log "connected to socket at #{@_url()}" + logger.info "connected to socket at #{@_url()}" # make an initial call to our recursive _write_pipe() method @_write_pipe() @@ -42,23 +42,20 @@ class Server # create writestream to kernel at /dev/ttyO1 # _setup_writestream: -> - ws = FS.createWriteStream "/dev/ttyO1", + @ws = FS.createWriteStream "/dev/ttyO1", flags: "w+" # - # write buffer directly to the kernel via /dev/ttyO1 pipe - # if buffer has content, at 30ms resolution. recursively call this function on success + # if buffer has content, write buffer directly to the kernel via /dev/ttyO1 pipe + # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> setInterval (=> - # console.log "setInterval called with buffer #{buffer}" - return if buffer.length == 0 - ws.write(buffer, (err, written) => + return if @buffer.length == 0 + @ws.write(@buffer, (err, written) => throw err if err - buffer = '' - # @_write_pipe() + @buffer = '' ) - # return ), 15 # @@ -68,12 +65,11 @@ class Server # # => '4,1,000,110,255,000;' # _data_to_instruction: (data) -> - # break colors string into array + # break colors string into array, pop empty last value colors = data.color.split '\n' colors.pop() # build our TTY instruction - # logger.debug "colors: #{colors} length: #{colors.length}" instruction = '' instruction += "4,#{i+1},#{color};" for color, i in colors @@ -86,7 +82,6 @@ class Server # write socket.io color data to buffer as UART instruction # _to_buffer: (data) -> - # logger.info "writing to buffer #{data.color}" - buffer = @_data_to_instruction(data) + @buffer = @_data_to_instruction(data) module.exports = Server From 475612d7b0c57e5c4b074f5389c58c9a536e8fec Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Tue, 19 Aug 2014 09:36:37 -0700 Subject: [PATCH 19/34] setImmediate --- src/server.coffee | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 9c293ac..187c0d0 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,13 +50,27 @@ class Server # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> - setInterval (=> - return if @buffer.length == 0 - @ws.write(@buffer, (err, written) => - throw err if err - @buffer = '' - ) - ), 15 + setImmediate (=> + if @buffer.length == 0 + @_write_pipe() + else + ok = @ws.write @buffer + if ok + @buffer = '' + @_write_pipe() + else + @ws.once('drain', => + @buffer = '' + @_write_pipe + ) + ) + + # setImmediate(=> + # @ws.write(@buffer, (err, written) => + # throw err if err + # @buffer = '' + # ) + # ) # # convert halo rgba string to a UART instruction @@ -83,5 +97,6 @@ class Server # _to_buffer: (data) -> @buffer = @_data_to_instruction(data) + @_write_pipe() module.exports = Server From b263cd8dbe1dc81a98f54115dfe5969ae37b234c Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Wed, 20 Aug 2014 19:22:26 -0700 Subject: [PATCH 20/34] longer timeout --- src/server.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 187c0d0..c3c4a4f 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,7 +50,7 @@ class Server # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> - setImmediate (=> + setTimeout (=> if @buffer.length == 0 @_write_pipe() else @@ -63,7 +63,7 @@ class Server @buffer = '' @_write_pipe ) - ) + ), 100 # setImmediate(=> # @ws.write(@buffer, (err, written) => From 2476b6b608cbb691e59001f8941a68c592906715 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Wed, 20 Aug 2014 19:25:19 -0700 Subject: [PATCH 21/34] only allow setImmediate to be fired every 50ms --- src/server.coffee | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index c3c4a4f..604478d 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,7 +50,23 @@ class Server # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> - setTimeout (=> + # setTimeout (=> + # if @buffer.length == 0 + # @_write_pipe() + # else + # ok = @ws.write @buffer + # if ok + # @buffer = '' + # @_write_pipe() + # else + # @ws.once('drain', => + # @buffer = '' + # @_write_pipe + # ) + # ), 100 + + # setTimeout (=> + setImmediate (=> if @buffer.length == 0 @_write_pipe() else @@ -63,14 +79,12 @@ class Server @buffer = '' @_write_pipe ) - ), 100 - - # setImmediate(=> - # @ws.write(@buffer, (err, written) => - # throw err if err - # @buffer = '' - # ) - # ) + ) + # ), 50 + + + + # # convert halo rgba string to a UART instruction From f574998613e50b21a08cb3eb1c65ba841b5db947 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Wed, 20 Aug 2014 19:35:57 -0700 Subject: [PATCH 22/34] document our approaches --- src/server.coffee | 55 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 604478d..5d9c9d7 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,6 +50,32 @@ class Server # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> + # setInterval is recursive by default + setInterval (=> + # console.log "setInterval called with buffer #{buffer}" + return if @buffer.length == 0 + @ws.write(@buffer, (err, written) => + throw err if err + @buffer = '' + # @_write_pipe() + ) + # return + ), 15 + + # setInterval (=> + # # console.log "setInterval called with buffer #{buffer}" + # return if @buffer.length == 0 + # @ws.write(@buffer, (err, written) => + # throw err if err + # @buffer = '' + # # @_write_pipe() + # ) + # # return + # ), 50 + + + + # normal recursive setTimeout method # setTimeout (=> # if @buffer.length == 0 # @_write_pipe() @@ -65,21 +91,22 @@ class Server # ) # ), 100 + # ensure setImmediate is only called every 50ms # setTimeout (=> - setImmediate (=> - if @buffer.length == 0 - @_write_pipe() - else - ok = @ws.write @buffer - if ok - @buffer = '' - @_write_pipe() - else - @ws.once('drain', => - @buffer = '' - @_write_pipe - ) - ) + # setImmediate (=> + # if @buffer.length == 0 + # @_write_pipe() + # else + # ok = @ws.write @buffer + # if ok + # @buffer = '' + # @_write_pipe() + # else + # @ws.once('drain', => + # @buffer = '' + # @_write_pipe + # ) + # ) # ), 50 From 123d84d30a671b1573fb18024996d54315ee6489 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 21 Aug 2014 20:57:20 -0700 Subject: [PATCH 23/34] use array for buffer, send instructions in separate commands --- src/server.coffee | 91 +++++++---------------------------------------- 1 file changed, 12 insertions(+), 79 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 5d9c9d7..ca63cf1 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -4,7 +4,7 @@ logger = require './logger' FS = require 'fs' class Server - buffer: '' + buffer: [] ws: undefined constructor: (@host, @port, @options = {}) -> @@ -50,94 +50,27 @@ class Server # at 15ms resolution. recursively call this function using setInterval() # _write_pipe: -> - # setInterval is recursive by default setInterval (=> - # console.log "setInterval called with buffer #{buffer}" - return if @buffer.length == 0 - @ws.write(@buffer, (err, written) => - throw err if err - @buffer = '' - # @_write_pipe() - ) - # return - ), 15 - - # setInterval (=> - # # console.log "setInterval called with buffer #{buffer}" - # return if @buffer.length == 0 - # @ws.write(@buffer, (err, written) => - # throw err if err - # @buffer = '' - # # @_write_pipe() - # ) - # # return - # ), 50 - - - - # normal recursive setTimeout method - # setTimeout (=> - # if @buffer.length == 0 - # @_write_pipe() - # else - # ok = @ws.write @buffer - # if ok - # @buffer = '' - # @_write_pipe() - # else - # @ws.once('drain', => - # @buffer = '' - # @_write_pipe - # ) - # ), 100 - - # ensure setImmediate is only called every 50ms - # setTimeout (=> - # setImmediate (=> - # if @buffer.length == 0 - # @_write_pipe() - # else - # ok = @ws.write @buffer - # if ok - # @buffer = '' - # @_write_pipe() - # else - # @ws.once('drain', => - # @buffer = '' - # @_write_pipe - # ) - # ) - # ), 50 - - - - + if @buffer.length > 0 + instruction = @buffer.shift() + @ws.write(instruction) + ), 1 # - # convert halo rgba string to a UART instruction + # convert halo rgba string to a UART instruction and push to buffer, padding with black if needed # @example - # _data_to_instruction({ color: '000,110,255,000\n' }) - # # => '4,1,000,110,255,000;' + # _data_to_buffer({ color: '000,110,255,000\n000,110,255,000\n' }) # - _data_to_instruction: (data) -> + _to_buffer: (data) -> # break colors string into array, pop empty last value colors = data.color.split '\n' colors.pop() + instruction_count = colors.length # build our TTY instruction - instruction = '' - instruction += "4,#{i+1},#{color};" for color, i in colors - - # padding with black if necessary - instruction_count = (instruction.match(/;/g)||[]).length - instruction += "4,#{i+1},000,000,000,000;" for i in [instruction_count...5] - return instruction + @buffer.push("4,#{i+1},#{color};") for color, i in colors - # - # write socket.io color data to buffer as UART instruction - # - _to_buffer: (data) -> - @buffer = @_data_to_instruction(data) - @_write_pipe() + # pad with black if necessary + @buffer.push("4,#{i+1},000,000,000,000;") for i in [instruction_count...5] module.exports = Server From 923f404b90db10d134cefd968dc159ea16aa1fa0 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 21 Aug 2014 21:31:34 -0700 Subject: [PATCH 24/34] 345 implementation --- src/server.coffee | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index ca63cf1..18e51b8 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -46,31 +46,47 @@ class Server flags: "w+" # - # if buffer has content, write buffer directly to the kernel via /dev/ttyO1 pipe - # at 15ms resolution. recursively call this function using setInterval() + # write buffer directly to the kernel via /dev/ttyO1 pipe + # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> setInterval (=> - if @buffer.length > 0 - instruction = @buffer.shift() - @ws.write(instruction) - ), 1 + return if @buffer.length == 0 + console.log "writing buffer #{@buffer}" + @ws.write(@buffer, (err, written) => + throw err if err + @buffer = '' + ) + ), 15 # - # convert halo rgba string to a UART instruction and push to buffer, padding with black if needed + # convert halo rgba string to a UART instruction # @example - # _data_to_buffer({ color: '000,110,255,000\n000,110,255,000\n' }) + # _data_to_instruction({ color: '000,110,255,000\n' }) + # # => '4,1,000,110,255,000;' # - _to_buffer: (data) -> - # break colors string into array, pop empty last value + _data_to_instruction: (data) -> + # break colors string into array colors = data.color.split '\n' colors.pop() - instruction_count = colors.length + + # remove `v` value from each color + colors = colors.map (c) -> c.slice(0,-4) # build our TTY instruction - @buffer.push("4,#{i+1},#{color};") for color, i in colors + instruction = '345,5,' + instruction += "#{i+1},#{color};" for color, i in colors + + # padding with black if necessary + instruction_count = (instruction.match(/;/g)||[]).length + instruction += "#{i+1},000,000,000;" for i in [instruction_count...5] + return instruction + + # + # write socket.io color data to buffer as UART instruction + # + _to_buffer: (data) -> + @buffer = @_data_to_instruction(data) - # pad with black if necessary - @buffer.push("4,#{i+1},000,000,000,000;") for i in [instruction_count...5] module.exports = Server From b881d0cdeaf26bcf4e0a4650207de8620903ef75 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 21 Aug 2014 22:05:17 -0700 Subject: [PATCH 25/34] 345 improvement --- src/server.coffee | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 18e51b8..63c5b8b 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -51,19 +51,19 @@ class Server # _write_pipe: -> setInterval (=> - return if @buffer.length == 0 - console.log "writing buffer #{@buffer}" - @ws.write(@buffer, (err, written) => - throw err if err - @buffer = '' - ) + if @buffer.length > 0 + @ws.write(@buffer, (err, written) => + throw err if err + # @ws.flush() + @buffer = '' + ) ), 15 # # convert halo rgba string to a UART instruction # @example - # _data_to_instruction({ color: '000,110,255,000\n' }) - # # => '4,1,000,110,255,000;' + # _data_to_instruction({ color: '000,110,255,000\n255,000,000,000' }) + # # => '345,5,1,255,000,000;2,255,000,000,3,000,000,000,4,000,000,000,5,000,000,000;' # _data_to_instruction: (data) -> # break colors string into array From c43ef2bb7002a08339dfa9d9e79940bf2ecacff7 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Fri, 22 Aug 2014 21:13:28 -0700 Subject: [PATCH 26/34] back to setTimeout --- src/server.coffee | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 63c5b8b..a8f26a6 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,14 +50,25 @@ class Server # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> - setInterval (=> - if @buffer.length > 0 + setTimeout (=> + if @buffer.length == 0 + @_write_pipe() + else @ws.write(@buffer, (err, written) => throw err if err - # @ws.flush() @buffer = '' + @_write_pipe() ) - ), 15 + ), 30 + + # setInterval (=> + # if @buffer.length > 0 + # @ws.write(@buffer, (err, written) => + # # writestream flushed + # throw err if err + # @buffer = '' + # ) + # ), 15 # # convert halo rgba string to a UART instruction From 1aaf3d4e1c616ceb3325e72f28815de2a4f15cd7 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Fri, 19 Sep 2014 23:26:10 -0700 Subject: [PATCH 27/34] Update to socket.io 1.1.0 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 00f7ef7..74c24de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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", @@ -18,8 +18,8 @@ "dependencies": { "coffee-script": "~1.7", "log": "~1.4.0", - "socket.io": "~1.0.6", - "socket.io-client": "~1.0.6" + "socket.io": "~1.1.0", + "socket.io-client": "~1.1.0" }, "engines": { "node": "0.10.x", From b35f891fe52998f9152f4f2ac38207e85f0d461e Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 25 Sep 2014 22:43:11 -0700 Subject: [PATCH 28/34] Setup test suite --- .travis.yml | 2 +- package.json | 7 ++++++- test/server_test.coffee | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/server_test.coffee diff --git a/.travis.yml b/.travis.yml index 7f4dc12..d85d56d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - "0.10.30" before_install: script: - - "which node" + - "npm test" env: - NODE_ENV=test diff --git a/package.json b/package.json index 74c24de..1593aed 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "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", @@ -24,5 +24,10 @@ "engines": { "node": "0.10.x", "npm": "1.3.x" + }, + "devDependencies": { + "chai": "^1.9.1", + "mocha": "^1.21.4", + "sinon": "^1.10.3" } } diff --git a/test/server_test.coffee b/test/server_test.coffee new file mode 100644 index 0000000..e21032f --- /dev/null +++ b/test/server_test.coffee @@ -0,0 +1,3 @@ +server = require '../src/server' + +describe 'Server', -> From ac00c24a5e25351070a536243de6398b511b9f15 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 25 Sep 2014 23:28:25 -0700 Subject: [PATCH 29/34] Try to clear timeout inside timer --- src/server.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server.coffee b/src/server.coffee index a8f26a6..21e4685 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -50,7 +50,11 @@ class Server # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> - setTimeout (=> + timer = setTimeout (=> + # clear timer (memory leak!) + clearTimeout(timer) + + # recurse if @buffer.length == 0 @_write_pipe() else From 6422d7d59a277f087e8e75b84b9e596e64863294 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 20 Oct 2014 18:51:08 -0700 Subject: [PATCH 30/34] Handle production/development writestream logic --- src/server.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.coffee b/src/server.coffee index 21e4685..4a7c97c 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -42,7 +42,7 @@ class Server # create writestream to kernel at /dev/ttyO1 # _setup_writestream: -> - @ws = FS.createWriteStream "/dev/ttyO1", + @ws = FS.createWriteStream (if process.env.NODE_ENV == 'production' then '/dev/ttyO1' else '/dev/null'), flags: "w+" # From 44156af5b256d2681b548e83c3a8244bd0dfbd72 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Mon, 20 Oct 2014 18:54:13 -0700 Subject: [PATCH 31/34] Ensure we clearTimeout when disconnecting --- src/server.coffee | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 4a7c97c..74b4587 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -6,6 +6,7 @@ FS = require 'fs' class Server buffer: [] ws: undefined + timer: undefined constructor: (@host, @port, @options = {}) -> @@ -33,11 +34,19 @@ class Server # make an initial call to our recursive _write_pipe() method @_write_pipe() - socket.on 'connect_error', (obj) => console.log 'connect error', obj - socket.on 'disconnect', => console.log "socket at #{@_url()} disconnected" + socket.on 'connect_error', (obj) => logger.info 'connect error', obj + socket.on 'disconnect', => @_disconnected socket.on 'colorChanged', (data) => @_to_buffer(data) socket.on 'colorSet', (data) => @_to_buffer(data) + # + # when a client disconnects, clear any timer in memory to avoid memory leak or multiple + # messages being sent in the future! + # + _disconnected: -> + logger.info "socket at #{@_url()} disconnected" + clearTimeout(@timer) + # # create writestream to kernel at /dev/ttyO1 # @@ -50,9 +59,9 @@ class Server # if buffer has content, at 30ms resolution. recursively call this function on success # _write_pipe: -> - timer = setTimeout (=> - # clear timer (memory leak!) - clearTimeout(timer) + @timer = setTimeout (=> + # clear @timer (memory leak!) + clearTimeout(@timer) # recurse if @buffer.length == 0 From 84aa76491dcb5f513279420469874920ef4a8ed0 Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Tue, 21 Oct 2014 21:26:40 -0700 Subject: [PATCH 32/34] Update readme and angstrom systemctl service templates --- README.md | 112 +++++++++++++++++- angstrom/colorpickerbeaglebone.service | 9 ++ .../colorpickerbeaglebone.sh | 3 +- {wifiboot => angstrom}/cp_service | 0 {wifiboot => angstrom}/halo-reduced.pl | 0 {wifiboot => angstrom}/last_ping.txt | 0 {wifiboot => angstrom}/ping_test.py | 0 package.json | 2 +- wifiboot/wifiboot.service | 9 -- 9 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 angstrom/colorpickerbeaglebone.service rename wifiboot/wifiboot.sh => angstrom/colorpickerbeaglebone.sh (99%) rename {wifiboot => angstrom}/cp_service (100%) rename {wifiboot => angstrom}/halo-reduced.pl (100%) rename {wifiboot => angstrom}/last_ping.txt (100%) rename {wifiboot => angstrom}/ping_test.py (100%) delete mode 100644 wifiboot/wifiboot.service diff --git a/README.md b/README.md index a9c3f1e..f379c54 100644 --- a/README.md +++ b/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 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. diff --git a/angstrom/colorpickerbeaglebone.service b/angstrom/colorpickerbeaglebone.service new file mode 100644 index 0000000..a762387 --- /dev/null +++ b/angstrom/colorpickerbeaglebone.service @@ -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 diff --git a/wifiboot/wifiboot.sh b/angstrom/colorpickerbeaglebone.sh similarity index 99% rename from wifiboot/wifiboot.sh rename to angstrom/colorpickerbeaglebone.sh index 95b908c..1c9e735 100755 --- a/wifiboot/wifiboot.sh +++ b/angstrom/colorpickerbeaglebone.sh @@ -7,7 +7,6 @@ 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 -cd /home/root/colorpicker-beaglebone/ - # start the node client application +cd /home/root/colorpicker-beaglebone/ NODE_ENV=production npm start diff --git a/wifiboot/cp_service b/angstrom/cp_service similarity index 100% rename from wifiboot/cp_service rename to angstrom/cp_service diff --git a/wifiboot/halo-reduced.pl b/angstrom/halo-reduced.pl similarity index 100% rename from wifiboot/halo-reduced.pl rename to angstrom/halo-reduced.pl diff --git a/wifiboot/last_ping.txt b/angstrom/last_ping.txt similarity index 100% rename from wifiboot/last_ping.txt rename to angstrom/last_ping.txt diff --git a/wifiboot/ping_test.py b/angstrom/ping_test.py similarity index 100% rename from wifiboot/ping_test.py rename to angstrom/ping_test.py diff --git a/package.json b/package.json index 1593aed..55dea66 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "socket.io-client": "~1.1.0" }, "engines": { - "node": "0.10.x", + "node": "0.10.32", "npm": "1.3.x" }, "devDependencies": { diff --git a/wifiboot/wifiboot.service b/wifiboot/wifiboot.service deleted file mode 100644 index 1c95343..0000000 --- a/wifiboot/wifiboot.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Wifi Startup Retry - -[Service] -WorkingDirectory=/home/root/wifiboot/ -ExecStart=/home/root/wifiboot/wifiboot.sh - -[Install] -WantedBy=multi-user.target From 1e966c091d8ff0f96a4cff328b1acfb0671988cb Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Wed, 22 Oct 2014 23:51:30 -0700 Subject: [PATCH 33/34] Actually invoke disconnected callback - cleanup dead code comment - only clear timer if timer is defined --- src/server.coffee | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 74b4587..4437c5f 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -35,7 +35,7 @@ class Server @_write_pipe() socket.on 'connect_error', (obj) => logger.info 'connect error', obj - socket.on 'disconnect', => @_disconnected + socket.on 'disconnect', => @_disconnected() socket.on 'colorChanged', (data) => @_to_buffer(data) socket.on 'colorSet', (data) => @_to_buffer(data) @@ -45,7 +45,7 @@ class Server # _disconnected: -> logger.info "socket at #{@_url()} disconnected" - clearTimeout(@timer) + clearTimeout(@timer) if @timer? # # create writestream to kernel at /dev/ttyO1 @@ -74,15 +74,6 @@ class Server ) ), 30 - # setInterval (=> - # if @buffer.length > 0 - # @ws.write(@buffer, (err, written) => - # # writestream flushed - # throw err if err - # @buffer = '' - # ) - # ), 15 - # # convert halo rgba string to a UART instruction # @example From 9afe9ec868ac8783291a459002ba91ca574d003a Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 23 Oct 2014 18:57:48 -0700 Subject: [PATCH 34/34] Remove unnecessary clearTimeout --- src/server.coffee | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/server.coffee b/src/server.coffee index 4437c5f..4eee408 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -60,9 +60,6 @@ class Server # _write_pipe: -> @timer = setTimeout (=> - # clear @timer (memory leak!) - clearTimeout(@timer) - # recurse if @buffer.length == 0 @_write_pipe() @@ -103,5 +100,4 @@ class Server _to_buffer: (data) -> @buffer = @_data_to_instruction(data) - module.exports = Server