summaryrefslogtreecommitdiff
path: root/src/draw
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2016-05-08 16:02:01 +0100
committerFreeArtMan <dos21h@gmail.com>2016-05-08 16:02:01 +0100
commite42911405c4bc2f8c097f47d4598baf8522ef3da (patch)
tree9eb767c5e6a4443e8773b18ea76cf4216f6c8758 /src/draw
parent9b95088bddcf1f83e3a8f73f08f49b38ecb0f500 (diff)
downloadradiola-master.tar.gz
radiola-master.zip
Moved source to src directoryHEADmaster
Diffstat (limited to 'src/draw')
-rw-r--r--src/draw/Kconfig20
-rw-r--r--src/draw/glui.c174
-rw-r--r--src/draw/glui.h63
-rw-r--r--src/draw/make.mk11
-rw-r--r--src/draw/tui.c269
-rw-r--r--src/draw/tui.h45
-rw-r--r--src/draw/ui.c0
-rw-r--r--src/draw/ui.h0
8 files changed, 582 insertions, 0 deletions
diff --git a/src/draw/Kconfig b/src/draw/Kconfig
new file mode 100644
index 0000000..486461f
--- /dev/null
+++ b/src/draw/Kconfig
@@ -0,0 +1,20 @@
+menuconfig DRAW
+ bool "Graphic library support"
+ default y
+
+if DRAW
+ config GL
+ bool "OpenGL support"
+ default y
+
+ config SDL2
+ bool "SDL2 support"
+ default y
+
+ config TUI
+ bool "Terminal interface support"
+ default y
+endif
+
+
+
diff --git a/src/draw/glui.c b/src/draw/glui.c
new file mode 100644
index 0000000..0f1e360
--- /dev/null
+++ b/src/draw/glui.c
@@ -0,0 +1,174 @@
+#include "glui.h"
+
+#if def(OS_LINUX)
+
+#define DEFAULT_TITLE "RADIOLA"
+#define SCREEN_X 1024
+#define SCREEN_Y 480
+
+int glui_init( glui_t **t )
+{
+ int ret=-1;
+
+ glui_t *tui = NULL;
+
+ tui = malloc( sizeof(glui_t) );
+ if (tui == NULL)
+ {
+ return -1;
+ }
+
+ memset(tui, 0, sizeof(glui_t));
+
+ if ( SDL_Init(SDL_INIT_VIDEO) != 0)
+ {
+ printf("Cannot init sdl\n");
+ return -1;
+ }
+
+ tui->h = SCREEN_Y;
+ tui->w = SCREEN_X;
+ tui->win = SDL_CreateWindow("Hello World!", tui->w, tui->h, SCREEN_X, SCREEN_Y, SDL_WINDOW_SHOWN);
+ if (tui->win == NULL)
+ {
+ printf("Couldnt create SDL window\n");
+ return -1;
+ }
+
+ *t = tui;
+ ret = 0;
+
+ return ret;
+}
+
+
+//init waterfall
+int glui_waterfall( glui_t **t, glui_waterfall_t **w )
+{
+ int ret=-1;
+
+ glui_waterfall_t *wtf = NULL;
+
+ wtf = malloc( sizeof(glui_waterfall_t) );
+ if ( wtf == NULL )
+ {
+ printf("Cannot alloc waterfall\n");
+ return -1;
+ }
+
+ memset( wtf, 0, sizeof(glui_waterfall_t) );
+
+ wtf->h = (*t)->h;
+ wtf->w = (*t)->w;
+ wtf->cur_h = 5;
+
+
+ wtf->rend = SDL_CreateRenderer( (*t)->win, -1, SDL_RENDERER_ACCELERATED);
+ if ( wtf->rend == NULL )
+ {
+ printf("Canno create SDL Rendered\n");
+ return -1;
+ }
+
+ (*w) = wtf;
+ (*t)->wf = wtf;
+
+ ret = 0;
+
+ return ret;
+}
+
+
+//first draw, draw all buffer
+int glui_waterfall_draw( glui_waterfall_t *w )
+{
+ int ret=-1;
+
+
+
+ return ret;
+}
+
+
+//redraw only changed lines
+int glui_waterfall_redraw( glui_waterfall_t *w )
+{
+ int ret=-1;
+
+
+ return ret;
+}
+
+
+//update params of waterfall and then need to draw not redraw
+int glui_waterfall_update( glui_t *w )
+{
+ int ret=-1;
+
+
+ return ret;
+}
+
+
+//push one line of data to buffer
+int glui_waterfall_data( glui_t *t, int len, uint8_t *buf )
+{
+ int ret=-1;
+ int i;
+ int y;
+ glui_color_t c = glui_waterfall_color(0);
+ SDL_Point *pt = NULL;
+
+ SDL_SetRenderDrawColor( t->wf->rend, c.r, c.g, c.b, c.a );
+
+ y = t->wf->cur_h;
+ t->wf->cur_h += 1;
+ pt = malloc( sizeof(SDL_Point) );
+ for ( i=0; i<len; i++ )
+ {
+ c = glui_waterfall_color(buf[i]);
+ SDL_SetRenderDrawColor( t->wf->rend, c.r, c.g, c.b, c.a );
+ pt[0].x = i;
+ pt[0].y = y;
+ SDL_RenderDrawPoints( t->wf->rend, pt, 1 );
+ }
+
+
+ SDL_RenderPresent( t->wf->rend );
+ ret = 0;
+
+ return ret;
+}
+
+
+//return color
+glui_color_t glui_waterfall_color( uint8_t d )
+{
+ glui_color_t c;
+
+ c.r = d*10;
+ c.g = d*10;
+ c.b = d*10;
+
+ return c;
+}
+
+
+//close terminal ui
+int glui_close( glui_t *t )
+{
+ int ret=0;
+
+
+ if ( t->win != NULL )
+ {
+ SDL_DestroyWindow( t->win );
+ }
+
+ SDL_Quit();
+
+
+ return ret;
+}
+
+#endif
diff --git a/src/draw/glui.h b/src/draw/glui.h
new file mode 100644
index 0000000..9206bdf
--- /dev/null
+++ b/src/draw/glui.h
@@ -0,0 +1,63 @@
+#ifndef __RADIOLA_GLUI_H
+#define __RADIOLA_GLUI_H
+#include "../config.h"
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#if def(OS_LINUX)
+
+#include <SDL2/SDL.h>
+
+//to draw waterfall
+typedef struct glui_waterfall_t
+{
+ int type;
+ int h,w;
+ uint8_t *buf;
+ size_t buf_len;
+ int cur_h;
+
+ SDL_Renderer *rend;
+} glui_waterfall_t;
+
+typedef struct glui_t
+{
+
+ int h, w;
+
+ SDL_Window *win;
+
+ glui_waterfall_t *wf;
+} glui_t;
+
+typedef struct glui_color_t
+{
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+} glui_color_t;
+
+//prepare terminal ui
+int glui_init( glui_t **t );
+//init waterfall
+int glui_waterfall( glui_t **t, glui_waterfall_t **w );
+//first draw, draw all buffer
+int glui_waterfall_draw( glui_waterfall_t *w );
+//redraw only changed lines
+int glui_waterfall_redraw( glui_waterfall_t *w );
+//update params of waterfall and then need to draw not redraw
+int glui_waterfall_update( glui_t *w );
+//push one line of data to buffer
+int glui_waterfall_data( glui_t *w, int len, uint8_t *buf );
+//return color
+glui_color_t glui_waterfall_color( uint8_t d );
+//close terminal ui
+int glui_close( glui_t *t );
+#endif
+#endif
diff --git a/src/draw/make.mk b/src/draw/make.mk
new file mode 100644
index 0000000..5c0acc4
--- /dev/null
+++ b/src/draw/make.mk
@@ -0,0 +1,11 @@
+DIR_DRAW = draw/
+SOURCES_DRAW += $(SRC_DIR)draw/glui.c $(SRC_DIR)draw/tui.c $(SRC_DIR)draw/ui.c
+OBJECTS_DRAW += $(SOURCES_DRAW:.c=.o)
+LDFLAGS += -lGL `sdl2-config --cflags --libs`
+LDFLAGS_BSD +=
+
+
+OBJECTS_DIR_DRAW += $(subst $(SRC_DIR)$(DIR_DRAW),$(BUILD_DIR)$(SRC_DIR)$(DIR_DRAW),$(OBJECTS_DRAW))
+
+OBJECTS += $(OBJECTS_DRAW)
+OBJECTS_FINAL += $(OBJECTS_DIR_DRAW) \ No newline at end of file
diff --git a/src/draw/tui.c b/src/draw/tui.c
new file mode 100644
index 0000000..c431a61
--- /dev/null
+++ b/src/draw/tui.c
@@ -0,0 +1,269 @@
+#include "tui.h"
+
+#define T_ESC "\x1b"
+
+//prepare terminal ui
+int tui_init( tui_t **t )
+{
+ int ret = -1;
+ tui_t *tui=NULL;
+
+ //should be empty pointer
+ if (*t != NULL)
+ return -1;
+
+ tui = malloc( sizeof(tui_t) );
+ if ( tui == NULL )
+ return -1;
+
+ memset( tui, 0, sizeof( tui_t ) );
+
+ tui->ifd = STDIN_FILENO;
+ tui->ofd = STDOUT_FILENO;
+
+ //if you whant raw mode then you should set it man
+ if ( tcgetattr( tui->ifd, &tui->orig_i ) == -1 )
+ goto exit_error;
+ tui->raw_i = tui->orig_i;
+
+ if ( tcgetattr( tui->ofd, &tui->orig_o ) == -1 )
+ goto exit_error;
+ tui->raw_o = tui->orig_o;
+
+ //set not to echo output
+ /* input modes: no break, no CR to NL, no parity check, no strip char,
+ * no start/stop output control. */
+ tui->raw_i.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ /* output modes - disable post raw */
+ tui->raw_i.c_oflag &= ~(OPOST);
+ /* control modes - set 8 bit chars */
+ tui->raw_i.c_cflag |= (CS8);
+ /* local modes - choing off, canonical off, no extended functions,
+ * no signal chars (^Z,^C) */
+ tui->raw_i.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+ /* control chars - set return condition: min number of bytes and timer.
+ * We want read to return every single byte, without timeout. */
+
+ /* put terminal in raw mode after flushing */
+ if (tcsetattr( tui->ifd, TCSAFLUSH, &tui->raw_i) < 0)
+ {
+ //ERROR("Cannot set new terminal input attribures\n");
+ goto exit_error;
+ }
+
+ *t = tui;
+ ret = 0;
+
+ return ret;
+
+exit_error:
+ free( tui );
+ return -1;
+}
+
+
+//init waterfall
+int tui_waterfall( tui_t **t, tui_waterfall_t **w )
+{
+ int ret=-1;
+ tui_waterfall_t *wtf = NULL;
+
+ //waterfall should be NULL
+ if ( *w != NULL )
+ return -1;
+
+
+ wtf = malloc( sizeof(tui_waterfall_t) );
+ if ( wtf == NULL )
+ {
+ return -1;
+ }
+
+ memset( wtf, 0, sizeof(tui_waterfall_t) );
+
+ *w = wtf;
+ (*t)->wf = wtf;
+ ret = 0;
+
+ return ret;
+
+//exit_error:
+
+// return -1;
+}
+
+
+//first draw, draw all buffer
+int tui_waterfall_draw( tui_waterfall_t *w )
+{
+ int ret = -1;
+ return ret;
+}
+
+
+//redraw only changed lines
+int tui_waterfall_redraw( tui_waterfall_t *w )
+{
+ int ret = -1;
+ return ret;
+}
+
+
+//update params of waterfall and then need to draw not redraw
+int tui_waterfall_update( tui_t *t )
+{
+ int ret = -1;
+ int row=-1,col=-1;
+ char buf[32];
+ int i;
+
+ //we trust that all params are ok
+
+ /* go to right marging and get position */
+ if ( write( t->ofd, "\x1b[999C", 6 ) != 6 )
+ goto exit_error;
+
+ if ( write( t->ofd, "\x1b[6n", 4 ) != 4 )
+ goto exit_error;
+
+ i = 0;
+ //printf("here=%d\n", sizeof(buf));
+ while (i < sizeof(buf)-1)
+ {
+ if ( read( t->ifd, buf+i,1 ) != 1 ) break;
+ if (buf[i] == 'R') break;
+ i++;
+ }
+ buf[i] = '\0';
+ //printf("i=%d,buf=[%s]\n",i,buf);
+
+ if ( buf[0] != '\x1b' || buf[1] != '[' )
+ {
+ goto exit_error;
+ }
+
+ //printf("i=%d,buf=[%s]\n",i,buf);
+
+ if ( sscanf( buf+2, "%d;%d", &row, &col) != 2 )
+ goto exit_error;
+
+ //write( t->ofd, "\x1b[1C", 4 );
+ write( t->ofd, T_ESC "[H" T_ESC "[2J", 7 );
+ write( t->ofd, T_ESC "[0;0H", 6);
+
+ t->wf->w = col;
+
+ ret = 0;
+
+ return ret;
+
+exit_error:
+
+ return -1;
+}
+
+
+//push one line of data to buffer
+int tui_waterfall_data( tui_t *t, int len, uint8_t *buf )
+{
+ int ret = -1;
+ int i;
+
+
+
+ i = 0;
+ while ( (i< t->wf->w) && ( i<len) )
+ {
+ //printf("-%d", buf[i]);
+ uint8_t c = tui_waterfall_color( buf[i] );
+ char buf[32];
+ snprintf( buf, 32, T_ESC "[48;5;%dm " T_ESC "[0m",c);
+ write( t->ofd, buf, strlen(buf) );
+ i++;
+ }
+
+ return ret;
+}
+
+uint8_t tui_waterfall_color( uint8_t d )
+{
+
+ uint8_t color=15;
+
+
+ /*
+ if ( d < 50 )
+ {
+ color = 17;
+ } else if ( d < 100 )
+ {
+ color = 18;
+ } else if ( d < 150 )
+ {
+ color = 19;
+ } else if ( d < 200 )
+ {
+ color = 20;
+ } else
+ {
+ color = 21;
+ }
+ */
+
+
+
+ if ( d == 0 )
+ {
+ color = 17;
+ } else if ( d == 1 )
+ {
+ color = 18;
+ } else if ( d == 2 )
+ {
+ color = 19;
+ } else if ( d == 3 )
+ {
+ color = 20;
+ } else if ( d == 4 )
+ {
+ color = 21;
+ } else if ( d == 5 )
+ {
+ color = 26;
+ } else if ( d == 6 )
+ {
+ color = 27;
+ } else if ( d == 7 )
+ {
+ color = 44;
+ } else
+ {
+ color = 45;
+ }
+
+ /*
+ uint8_t col[] = { 16,17,18,19,20,21,26,27,44,45,86,87,230,229,228,227,226,214,202,196,160,124,88,52 };
+ int len = 24;
+ int step = 256/len;
+
+ color = col[d/step];
+ */
+
+ return color;
+}
+
+
+//close terminal ui
+int tui_close( tui_t *t )
+{
+ int ret = -1;
+
+ //shouldnt be empty pointer
+ if ( t == NULL )
+ return -1;
+
+ //restore terminal mode after closing
+ tcsetattr( t->ifd, TCSAFLUSH, &t->orig_i );
+
+ return ret;
+}
diff --git a/src/draw/tui.h b/src/draw/tui.h
new file mode 100644
index 0000000..a84379f
--- /dev/null
+++ b/src/draw/tui.h
@@ -0,0 +1,45 @@
+#ifndef __RADIOLA_TUI_H
+#define __RADIOLA_TUI_H
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+//to draw waterfall
+typedef struct tui_waterfall_t
+{
+ int type;
+ int h,w;
+ uint8_t *buf;
+ size_t buf_len;
+} tui_waterfall_t;
+
+typedef struct tui_t
+{
+ int ifd, ofd;
+ struct termios orig_i, orig_o;
+ struct termios raw_i, raw_o;
+ tui_waterfall_t *wf;
+} tui_t;
+
+//prepare terminal ui
+int tui_init( tui_t **t );
+//init waterfall
+int tui_waterfall( tui_t **t, tui_waterfall_t **w );
+//first draw, draw all buffer
+int tui_waterfall_draw( tui_waterfall_t *w );
+//redraw only changed lines
+int tui_waterfall_redraw( tui_waterfall_t *w );
+//update params of waterfall and then need to draw not redraw
+int tui_waterfall_update( tui_t *w );
+//push one line of data to buffer
+int tui_waterfall_data( tui_t *w, int len, uint8_t *buf );
+//return color
+uint8_t tui_waterfall_color( uint8_t d );
+//close terminal ui
+int tui_close( tui_t *t );
+
+#endif \ No newline at end of file
diff --git a/src/draw/ui.c b/src/draw/ui.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/draw/ui.c
diff --git a/src/draw/ui.h b/src/draw/ui.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/draw/ui.h