Permalink
Browse files

merged bbb and strongbox versions

  • Loading branch information...
2 parents 74b1df5 + 0d7de15 commit e83f4b7e809db05d89a2527d58839309eee64a48 @osresearch committed Aug 11, 2013
Showing with 169 additions and 73 deletions.
  1. +1 −1 Makefile
  2. +1 −1 VideoDisplay/VideoDisplay.ino
  3. +48 −0 checkerboard
  4. +5 −5 rainbow
  5. +2 −52 teensy-udp-rx.c
  6. +92 −0 util.c
  7. +20 −14 util.h
View
@@ -6,7 +6,7 @@ TARGETS += teensy-udp-rx
TARGETS += rgb-test
TARGETS += udp-rx
-LEDSCAPE_OBJS = ledscape.o pru.o bitslice.o
+LEDSCAPE_OBJS = ledscape.o pru.o bitslice.o util.o
LEDSCAPE_LIB := libledscape.a
all: $(TARGETS) ws281x.bin
@@ -73,7 +73,7 @@
// Since the receiving program on the host is slicing the image,
// only the width matters. The height is always 8.
//
-#define LED_WIDTH 10 // number of LEDs horizontally
+#define LED_WIDTH 210 // number of LEDs horizontally
#define LED_HEIGHT 8 // number of LEDs vertically (must be 8)
#define LED_LAYOUT 0 // 0 = even rows left->right, 1 = even rows right->left
View
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use IO::Socket;
+use Time::HiRes 'usleep';
+
+# Make an RGB checkerboard
+my $host = '192.168.7.2:9999';
+
+my $sock = IO::Socket::INET->new(
+ PeerAddr => $host,
+ Proto => 'udp',
+) or die "Socket failed: $!\n";
+
+
+my $width = 64;
+my $height = 210;
+my $offset = 0;
+
+my $i = 0;
+
+while (1)
+{
+ $offset++;
+ my $s = chr(1);
+ my $bright = 0x30;
+
+ for(my $y = 0 ; $y < $height ; $y++)
+ {
+ for(my $x = 0; $x < $width ; $x++)
+ {
+ my $c = $i % 7;
+ my $r = ($c == 0 || $c == 2) ? $bright : 0;
+ my $g = ($c == 1 || $c == 2) ? $bright : 0;
+ my $b = 0; #($i % 7 == 2) ? $bright : 0;
+
+ $s .= chr($r);
+ $s .= chr($g);
+ $s .= chr($b);
+ $i++;
+ }
+ }
+
+ $sock->send($s);
+ usleep(1e6/4);
+ #usleep(10);
+ $i++;
+}
View
10 rainbow
@@ -13,19 +13,19 @@ my $sock = IO::Socket::INET->new(
) or die "Socket failed: $!\n";
-my $width = 10;
-my $height = 32;
+my $width = 64;
+my $height = 210;
my $offset = 0;
while (1)
{
$offset++;
- my $s = '1';
- my $bright = 0x10;
+ my $s = chr(1);
+ my $bright = 0x30;
for(my $y = 0 ; $y < $height ; $y++)
{
- for(my $x =0 ; $x < $width ; $x++)
+ for(my $x = 0; $x < $width ; $x++)
{
my $r = (($x + $offset) % $width) * $bright / $width;
my $g = 0;
View
@@ -54,58 +54,6 @@ udp_socket(
}
-/** Write all the bytes to a fd, even if there is a brief interruption.
- * \return number of bytes written or -1 on any fatal error.
- */
-static ssize_t
-write_all(
- const int fd,
- const void * const buf_ptr,
- const size_t len
-)
-{
- const uint8_t * const buf = buf_ptr;
- size_t offset = 0;
-
- while (offset < len)
- {
- const ssize_t rc = write(fd, buf + offset, len - offset);
- if (rc < 0)
- {
- if (errno == EAGAIN)
- continue;
- return -1;
- }
-
- if (rc == 0)
- return -1;
-
- offset += rc;
- }
-
- return len;
-}
-
-
-static int
-serial_open(
- const char * const dev
-)
-{
- const int fd = open(dev, O_RDWR | O_NONBLOCK | O_NOCTTY, 0666);
- if (fd < 0)
- return -1;
-
- // Disable modem control signals
- struct termios attr;
- tcgetattr(fd, &attr);
- attr.c_cflag |= CLOCAL | CREAD;
- tcsetattr(fd, TCSANOW, &attr);
-
- return fd;
-}
-
-
typedef struct
{
const char * dev;
@@ -514,6 +462,8 @@ main(
strip->x_offset
);
+ hexdump(stderr, slice+3, slice_size-3);
+
const ssize_t rc
= write_all(dev->fd, slice, slice_size);
View
92 util.c
@@ -0,0 +1,92 @@
+/** \file
+ * Various utility functions
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <netinet/in.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <string.h>
+#include <pthread.h>
+#include "util.h"
+#include "bitslice.h"
+
+/** Write all the bytes to a fd, even if there is a brief interruption.
+ * \return number of bytes written or -1 on any fatal error.
+ */
+ssize_t
+write_all(
+ const int fd,
+ const void * const buf_ptr,
+ const size_t len
+)
+{
+ const uint8_t * const buf = buf_ptr;
+ size_t offset = 0;
+
+ while (offset < len)
+ {
+ const ssize_t rc = write(fd, buf + offset, len - offset);
+ if (rc < 0)
+ {
+ if (errno == EAGAIN)
+ continue;
+ return -1;
+ }
+
+ if (rc == 0)
+ return -1;
+
+ offset += rc;
+ }
+
+ return len;
+}
+
+
+int
+serial_open(
+ const char * const dev
+)
+{
+ const int fd = open(dev, O_RDWR | O_NONBLOCK | O_NOCTTY, 0666);
+ if (fd < 0)
+ return -1;
+
+ // Disable modem control signals
+ struct termios attr;
+ tcgetattr(fd, &attr);
+ attr.c_cflag |= CLOCAL | CREAD;
+ tcsetattr(fd, TCSANOW, &attr);
+
+ return fd;
+}
+
+
+void
+hexdump(
+ FILE * const outfile,
+ const void * const buf,
+ const size_t len
+)
+{
+ const uint8_t * const p = buf;
+
+ for(size_t i = 0 ; i < len ; i++)
+ {
+ if (i % 8 == 0)
+ fprintf(outfile, "%s%04zu:", i == 0 ? "": "\n", i);
+ fprintf(outfile, " %02x", p[i]);
+ }
+
+ fprintf(outfile, "\n");
+}
+
View
34 util.h
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <unistd.h>
@@ -32,23 +33,28 @@
} while(0)
-static inline void
+extern void
hexdump(
FILE * const outfile,
const void * const buf,
const size_t len
-)
-{
- const uint8_t * const p = buf;
-
- for(size_t i = 0 ; i < len ; i++)
- {
- if (i % 16 == 0)
- fprintf(outfile, "%s%04zu:", i == 0 ? "": "\n", i);
- fprintf(outfile, " %02x", p[i]);
- }
-
- fprintf(outfile, "\n");
-}
+);
+
+
+extern int
+serial_open(
+ const char * const dev
+);
+
+
+/** Write all the bytes to a fd, even if there is a brief interruption.
+ * \return number of bytes written or -1 on any fatal error.
+ */
+extern ssize_t
+write_all(
+ const int fd,
+ const void * const buf_ptr,
+ const size_t len
+);
#endif

0 comments on commit e83f4b7

Please sign in to comment.