awful but somehow working implementation of flipdot control in the simulator - fire and forget...
This commit is contained in:
parent
3a5052900d
commit
4583c0fbbb
|
@ -27,6 +27,13 @@
|
||||||
#include "../display_loop.h"
|
#include "../display_loop.h"
|
||||||
#include "trackball.h"
|
#include "trackball.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
struct addrinfo *servinfo, *p;
|
||||||
|
|
||||||
/** Number of bytes per row. */
|
/** Number of bytes per row. */
|
||||||
#define LINEBYTES (((NUM_COLS - 1) / 8) + 1)
|
#define LINEBYTES (((NUM_COLS - 1) / 8) + 1)
|
||||||
|
|
||||||
|
@ -116,6 +123,35 @@ void display(void) {
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
|
static uint8_t buffer[160] = {0};
|
||||||
|
/* {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||||
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
||||||
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa};*/
|
||||||
|
static unsigned int divider = 0;
|
||||||
|
if (++divider == 10) {
|
||||||
|
for (unsigned int y = 0; y < NUM_ROWS; ++y) {
|
||||||
|
for (unsigned int lb = 0; lb < LINEBYTES; ++lb) {
|
||||||
|
unsigned int offset = y * 10 + LINEBYTES - lb - 1;
|
||||||
|
buffer[offset] = pixmap[0][y][lb];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendto(sockfd, buffer, 160, 0, p->ai_addr, p->ai_addrlen);
|
||||||
|
divider = 0;
|
||||||
|
}
|
||||||
|
|
||||||
usleep(20000);
|
usleep(20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +287,46 @@ static void special(int k, int x, int y) {
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int init_socket() {
|
||||||
|
struct addrinfo hints = {.ai_family = AF_UNSPEC, .ai_socktype = SOCK_DGRAM};
|
||||||
|
int rv;
|
||||||
|
int numbytes;
|
||||||
|
|
||||||
|
if ((rv = getaddrinfo("flipdot", "2323", &hints, &servinfo)) != 0) {
|
||||||
|
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop through all the results and make a socket
|
||||||
|
for(p = servinfo; p != NULL; p = p->ai_next) {
|
||||||
|
if ((sockfd = socket(p->ai_family, p->ai_socktype,
|
||||||
|
p->ai_protocol)) == -1) {
|
||||||
|
perror("talker: socket");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p == NULL) {
|
||||||
|
fprintf(stderr, "talker: failed to bind socket\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if ((numbytes = sendto(sockfd, argv[2], strlen(argv[2]), 0,
|
||||||
|
p->ai_addr, p->ai_addrlen)) == -1) {
|
||||||
|
perror("talker: sendto");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_socket() {
|
||||||
|
freeaddrinfo(servinfo);
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for starting the display loop thread.
|
* Entry point for starting the display loop thread.
|
||||||
|
@ -269,6 +345,7 @@ void *display_loop_run(void * unused) {
|
||||||
* @return Exit codem, always zero.
|
* @return Exit codem, always zero.
|
||||||
*/
|
*/
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
init_socket();
|
||||||
WindHeight = 700;
|
WindHeight = 700;
|
||||||
WindWidth = 700;
|
WindWidth = 700;
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
|
@ -318,6 +395,8 @@ int main(int argc, char **argv) {
|
||||||
pthread_create(&simthread, NULL, display_loop_run, NULL);
|
pthread_create(&simthread, NULL, display_loop_run, NULL);
|
||||||
|
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
|
free_socket();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue