2013-11-02 19:47:37 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ncurses.h>
|
2013-11-02 18:44:02 +01:00
|
|
|
|
2013-11-02 19:58:39 +01:00
|
|
|
#include "msg.h"
|
2013-11-02 18:44:02 +01:00
|
|
|
#include "display.h"
|
|
|
|
|
2013-11-02 19:47:37 +01:00
|
|
|
|
|
|
|
void setup_display() {
|
|
|
|
initscr(); // ncurses initialization
|
|
|
|
curs_set(0); // invisible cursor
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup_display() {
|
|
|
|
endwin(); // clean ncurses shutdown
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
image[row][col] >>> image[row*width+col];
|
|
|
|
|
|
|
|
uint32_t width; // normally 80
|
|
|
|
uint32_t height; // normally 25, may vary
|
|
|
|
char *image; // dimension is width x height
|
|
|
|
*/
|
2013-11-02 19:58:39 +01:00
|
|
|
void print_current_image(struct message* msg, int start, int end) {
|
2013-11-02 19:51:41 +01:00
|
|
|
// end is ignored and 80 is used, should be considered later
|
2013-11-02 19:47:37 +01:00
|
|
|
|
2013-11-02 19:51:41 +01:00
|
|
|
move(0,0); // start in the upper left corner
|
2013-11-02 19:58:39 +01:00
|
|
|
char *pic = msg->image; // get a ptr to the actual image
|
2013-11-02 19:47:37 +01:00
|
|
|
|
2013-11-02 19:51:41 +01:00
|
|
|
for (int row=0; row < 25; row++) { // iterate rows
|
2013-11-02 19:47:37 +01:00
|
|
|
char *line = (char*) malloc(81);
|
2013-11-02 19:51:41 +01:00
|
|
|
strcpy(line, strtok(pic, '\n')); // get a line
|
|
|
|
line[80] = '\0'; // terminate
|
|
|
|
printw("%s", line+start);
|
2013-11-02 19:47:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh(); // refresh the screen
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-02 19:21:09 +01:00
|
|
|
void callback(const struct message *msg) {
|
|
|
|
printf("in callback, tst=%d\n", msg->timestamp);
|
2013-11-02 18:44:02 +01:00
|
|
|
}
|
2013-11-02 19:47:37 +01:00
|
|
|
|