Skip to content
Snippets Groups Projects
Commit 0dce199f authored by daniel's avatar daniel
Browse files

Merge remote-tracking branch 'origin/multipart'

parents ff774e36 1a4f003f
No related branches found
No related tags found
No related merge requests found
flash: flash.o
g++ -lzmq -o $@ $<
snow: snow.o
g++ -lzmq -o $@ $<
client: client.o
g++ -lzmq -o $@ $<
%.o: %.c
g++ -W -Wall -Wextra -pedantic -std=c++11 -c -o $@ $<
// Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <vector>
#define WIDTH 480
#define HEIGHT 70
#define CMD_PIXEL 0
#define CMD_BLIT 1
struct msgSetPixel {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint8_t on;
} __attribute__ ((packed));
struct msgBlit {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint32_t w;
uint32_t h;
uint8_t data[0];
} __attribute__ ((packed));
int main (void) {
void *context = zmq_ctx_new ();
void *requester;
requester = zmq_socket (context, ZMQ_REQ);
zmq_connect(requester, "tcp://mensadisplay:5556");
// zmq_connect(requester, "tcp://192.168.178.147:5570");
// zmq_connect(requester, "tcp://localhost:5556");
int x = 0;
msgBlit *onLine = reinterpret_cast<msgBlit *>(malloc(sizeof(msgBlit) + 70));
onLine->cmd = CMD_BLIT;
onLine->y = 0;
onLine->w = 1;
onLine->h = HEIGHT;
for(int i = 0; i < 70; ++i) onLine->data[i] = 255;
msgBlit *offLine = reinterpret_cast<msgBlit *>(malloc(sizeof(msgBlit) + 70));
offLine->cmd = CMD_BLIT;
offLine->y = 0;
offLine->w = 1;
offLine->h = HEIGHT;
for(int i = 0; i < 70; ++i) offLine->data[i] = 0;
while(1) {
zmq_msg_t msg;
// for(int i = 0; i < HEIGHT; ++i) {
// zmq_msg_init_size(&msg, sizeof(msgSetPixel));
// msgSetPixel set = { CMD_PIXEL, static_cast<uint32_t>((x + 1) % 480), static_cast<uint32_t>(i), 1 };
// memcpy(zmq_msg_data(&msg), &set, sizeof(set));
// zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
// }
//
// for(int i = HEIGHT; i < HEIGHT * 2; ++i) {
// zmq_msg_init_size(&msg, sizeof(msgSetPixel));
// msgSetPixel set = { CMD_PIXEL, static_cast<uint32_t>(x % 480), static_cast<uint32_t>(i - HEIGHT), 0 };
// memcpy(zmq_msg_data(&msg), &set, sizeof(set));
// zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
// }
zmq_msg_init_size(&msg, sizeof(msgBlit) + 70);
onLine->x = (x + 1) % 480;
memcpy(zmq_msg_data(&msg), onLine, sizeof(msgBlit) + 70);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, sizeof(msgBlit) + 70);
offLine->x = x % 480;
memcpy(zmq_msg_data(&msg), offLine, sizeof(msgBlit) + 70);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, 0);
zmq_msg_send(&msg, requester, 0);
zmq_recv(requester, NULL, 0, 0);
x = (x + 1) % 480;
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}
// Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#define WIDTH 480
#define HEIGHT 70
#define CMD_PIXEL 0
#define CMD_BLIT 1
struct msgSetPixel {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint8_t on;
} __attribute__ ((packed));
struct msgBlit {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint32_t w;
uint32_t h;
uint8_t data[0];
} __attribute__ ((packed));
int main (void) {
void *context = zmq_ctx_new ();
void *requester;
requester = zmq_socket (context, ZMQ_REQ);
zmq_connect(requester, "tcp://mensadisplay:5556");
// zmq_connect(requester, "tcp://192.168.178.147:5570");
// zmq_connect(requester, "tcp://localhost:5556");
msgBlit *snow = reinterpret_cast<msgBlit *>(malloc(sizeof(msgBlit) + WIDTH * HEIGHT));
snow->cmd = CMD_BLIT;
snow->x = 0;
snow->y = 0;
snow->w = WIDTH;
snow->h = HEIGHT;
int on = 0;
while(1) {
zmq_msg_t msg;
zmq_msg_init_size(&msg, sizeof(msgBlit) + WIDTH * HEIGHT);
int d = 0;
switch(on) {
case 0: d = 0; break;
case 1: d = 0; break;
case 2: d = 0; break;
case 3: d = 0; break;
case 4: d = 1; break;
case 5: d = 1; break;
case 6: d = 0; break;
case 7: d = 1; break;
}
for(int i = 0; i < WIDTH * HEIGHT; ++i) {
snow->data[i] = d;
}
on = (on + 1) % 8;
memcpy(zmq_msg_data(&msg), snow, sizeof(msgBlit) + WIDTH * HEIGHT);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, 0);
zmq_msg_send(&msg, requester, 0);
zmq_recv(requester, NULL, 0, 0);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}
// Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#define WIDTH 480
#define HEIGHT 70
#define CMD_PIXEL 0
#define CMD_BLIT 1
struct msgSetPixel {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint8_t on;
} __attribute__ ((packed));
struct msgBlit {
uint8_t cmd;
uint32_t x;
uint32_t y;
uint32_t w;
uint32_t h;
uint8_t data[0];
} __attribute__ ((packed));
int main (void) {
void *context = zmq_ctx_new ();
void *requester;
requester = zmq_socket (context, ZMQ_REQ);
zmq_connect(requester, "tcp://mensadisplay:5556");
// zmq_connect(requester, "tcp://192.168.178.147:5570");
// zmq_connect(requester, "tcp://localhost:5556");
msgBlit *snow = reinterpret_cast<msgBlit *>(malloc(sizeof(msgBlit) + WIDTH * HEIGHT));
snow->cmd = CMD_BLIT;
snow->x = 0;
snow->y = 0;
snow->w = WIDTH;
snow->h = HEIGHT;
float f[HEIGHT / 7] = { 0 };
float dir[HEIGHT / 7] = { 0 };
float sharpness[HEIGHT / 7] = { 0 };
for(int i = 0; i < HEIGHT / 7; ++i) {
dir[i] = 0.2;
sharpness[i] = 2;
}
while(1) {
zmq_msg_t msg;
zmq_msg_init_size(&msg, sizeof(msgBlit) + WIDTH * HEIGHT);
for(int i = 0; i < WIDTH * HEIGHT; ++i) {
int x = i % WIDTH;
int y = i / WIDTH;
int thresh = 32768 + sharpness[y / 7] * sin(f[y / 7] + 1.0 * x / 60) * 32768;
snow->data[i] = (rand() % 65536) > thresh;
}
for(int i = 0; i < HEIGHT / 7; ++i) {
f[i] += dir[i];
}
if(!(rand() % 100)) {
dir[rand() % (HEIGHT / 7)] *= -1;
}
if(!(rand() % 100)) {
sharpness[rand() % (HEIGHT / 7)] = 1 + rand() % 3;
}
memcpy(zmq_msg_data(&msg), snow, sizeof(msgBlit) + WIDTH * HEIGHT);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, 0);
zmq_msg_send(&msg, requester, 0);
zmq_recv(requester, NULL, 0, 0);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment