Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

working websockets broadcaster

  • Loading branch information...
commit a01d74056dde641591a9964ab9670e3cd09b5248 1 parent 54afb2a
@mhenstell mhenstell authored
Showing with 67 additions and 11 deletions.
  1. +30 −5 Dacwes.pde
  2. +37 −6 domeTransmitter.pde
View
35 Dacwes.pde
@@ -1,4 +1,6 @@
-import hypermedia.net.*;
+//import hypermedia.net.*;
+import muthesius.net.*;
+import org.webbitserver.*;
/**
* This class can be added to your sketches to make them compatible with the sign.
@@ -28,6 +30,13 @@ import hypermedia.net.*;
*
**/
+ protected static final byte[] Hexhars = {
+
+'0', '1', '2', '3', '4', '5',
+'6', '7', '8', '9', 'a', 'b',
+'c', 'd', 'e', 'f'
+};
+
public class Dacwes {
public static final int ADDRESSING_VERTICAL_NORMAL = 1;
public static final int ADDRESSING_VERTICAL_HALF = 2;
@@ -37,7 +46,6 @@ public class Dacwes {
public static final int ADDRESSING_HORIZONTAL_FLIPFLOP = 6;
PApplet parent;
- UDP udp;
String address;
int port;
int w;
@@ -45,10 +53,12 @@ public class Dacwes {
int addressingMode;
byte buffer[];
int pixelsPerChannel;
+
+
public Dacwes(PApplet parent, int w, int h) {
this.parent = parent;
- this.udp = new UDP(parent);
+
this.address = "192.168.1.130";
this.port = 58082;
this.w = w;
@@ -94,7 +104,7 @@ public class Dacwes {
modeBuffer[i+1] = (byte)modeName.charAt(i);
}
- udp.send(modeBuffer,address,port);
+ //udp.send(modeBuffer,address,port);
}
public void sendData() {
@@ -122,8 +132,23 @@ public class Dacwes {
buffer[(getAddress(x,y)*3)+3] = byte(b);
}
}
+
+ StringBuilder s = new StringBuilder(buffer.length *2);
+ for (int i=0; i < buffer.length; i++) {
+ int v = buffer[i] & 0xff;
+ s.append((char)Hexhars[v >> 4]);
+ s.append((char)Hexhars[v & 0xf]);
+ }
+
+
+// for (int i=0; i < buffer.length; i++) {
+// int v = buffer[i]
+// s.append((char)Hexhars[v >> 4]);
+// s.append((char)Hexhars[v & 0xf]);
+// }
- udp.send(buffer,address,port);
+ socket.broadcast(s.toString());
+ //udp.send(buffer,address,port);
}
}
View
43 domeTransmitter.pde
@@ -1,10 +1,11 @@
import codeanticode.gsvideo.*;
import processing.opengl.*;
import java.lang.reflect.Method;
-import hypermedia.net.*;
import java.io.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
+import muthesius.net.*;
+import org.webbitserver.*;
int WIDTH = 25;
int HEIGHT = 135;
@@ -14,6 +15,7 @@ int FRAMERATE = 30;
String hostname = "127.0.0.1"; //"192.168.1.130";
int TYPICAL_MODE_TIME = 30;
+
String[] enabledModes = new String[] {
"drawGreetz",
/* "drawBursts",
@@ -86,11 +88,15 @@ Minim minim;
AudioInput audioin;
FFT fft;
+WebSocketP5 socket;
+boolean connected = false;
void setup() {
+
+
// Had to enable OPENGL for some reason new fonts don't work in JAVA2D.
size(WIDTH,HEIGHT);
-
+
font = loadFont("Disorient-" + FONT_SIZE + ".vlw");
textFont(font, FONT_SIZE);
textMode(MODEL);
@@ -123,8 +129,8 @@ void setup() {
}
dacwes = new Dacwes(this, WIDTH, HEIGHT);
- dacwes.setAddress(hostname);
- dacwes.setAddressingMode(Dacwes.ADDRESSING_VERTICAL_NORMAL);
+// dacwes.setAddress(hostname);
+// dacwes.setAddressingMode(Dacwes.ADDRESSING_VERTICAL_NORMAL);
if (enabledAnimations.length > 0) {
animations = new Animation[enabledAnimations.length];
@@ -143,6 +149,31 @@ void setup() {
setMode(0);
smooth();
+
+ socket = new WebSocketP5(this,8080);
+}
+
+void stop(){
+ socket.stop();
+}
+
+void mousePressed(){
+ socket.broadcast("hello from processing!");
+}
+
+void websocketOnMessage(WebSocketConnection con, String msg){
+ println(msg);
+}
+
+void websocketOnOpen(WebSocketConnection con){
+ println("A client joined");
+ connected = true;
+
+}
+
+void websocketOnClosed(WebSocketConnection con){
+ println("A client left");
+ connected = false;
}
void setFadeLayer(int g) {
@@ -193,7 +224,7 @@ void newMode() {
}
setMode(newMode);
- dacwes.sendMode(enabledModes[newMode]);
+ //dacwes.sendMode(enabledModes[newMode]);
}
void draw() {
@@ -223,7 +254,7 @@ void draw() {
fadeInFrames--;
}
- dacwes.sendData();
+ if (connected) dacwes.sendData();
}
void drawGreetz() {
Please sign in to comment.
Something went wrong with that request. Please try again.