From 992bed5fbbbe47917e862ef6a4aee3921bdf4abb Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Fri, 2 Oct 2015 21:25:53 +0100 Subject: graphical waterfall drawing --- draw/glui.c | 71 +++++++++++++++++++++++++++++++++++++++++-------- draw/glui.h | 19 ++++++++++--- test/ui_gl_waterfall.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 147 insertions(+), 15 deletions(-) diff --git a/draw/glui.c b/draw/glui.c index 3e85646..fd27693 100644 --- a/draw/glui.c +++ b/draw/glui.c @@ -24,16 +24,17 @@ int glui_init( glui_t **t ) return -1; } - tui->win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_X, SCREEN_Y, SDL_WINDOW_SHOWN); + 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; } - tui->rend = SDL_CreateRenderer( tui->win, -1, SDL_RENDERER_ACCELERATED); - - + *t = tui; + ret = 0; return ret; } @@ -44,6 +45,33 @@ 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; } @@ -55,6 +83,7 @@ int glui_waterfall_draw( glui_waterfall_t *w ) int ret=-1; + return ret; } @@ -80,20 +109,44 @@ 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 ) +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; iwf->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 -uint8_t glui_waterfall_color( uint8_t d ) +glui_color_t glui_waterfall_color( uint8_t d ) { - uint8_t c; + glui_color_t c; + c.r = d; + c.g = d; + c.b = d; return c; } @@ -104,10 +157,6 @@ int glui_close( glui_t *t ) { int ret=0; - if ( t->rend ) - { - SDL_DestroyRenderer( t->rend ); - } if ( t->win != NULL ) { diff --git a/draw/glui.h b/draw/glui.h index f9f9bdf..0b9f6f3 100644 --- a/draw/glui.h +++ b/draw/glui.h @@ -17,16 +17,29 @@ typedef struct glui_waterfall_t int h,w; uint8_t *buf; size_t buf_len; + int cur_h; + + SDL_Renderer *rend; } glui_waterfall_t; typedef struct glui_t { - SDL_Window *win; - SDL_Renderer *rend; + 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 @@ -40,7 +53,7 @@ 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 -uint8_t glui_waterfall_color( uint8_t d ); +glui_color_t glui_waterfall_color( uint8_t d ); //close terminal ui int glui_close( glui_t *t ); diff --git a/test/ui_gl_waterfall.c b/test/ui_gl_waterfall.c index 1af4096..cbc2ec4 100644 --- a/test/ui_gl_waterfall.c +++ b/test/ui_gl_waterfall.c @@ -3,7 +3,7 @@ #include //radiola -#include +#include #include #define SAMPLE_RATE 2048000 @@ -253,6 +253,76 @@ int main() { + int i,j; + uint8_t *buf, *sample_buf; + int buf_len, sample_len; + uint32_t dev_num; + + glui_t *t = NULL; + glui_waterfall_t *w = NULL; + + if ( sdr_init() == -1 ) + { + goto main_exit; + } + + sine_table( FFT_LEVEL ); + + + //printf("%x\n",t); + //open GUI + if ( glui_init( &t ) == -1 ) + { + printf("Cannot set glui\n"); + return 1; + } + + //printf("%x\n",t); + if ( glui_waterfall( &t, &w ) == -1 ) + { + printf("Cannot set waterfall\n"); + return 1; + } + + dev_num = rtlsdr_get_device_count(); + if ( dev_num < 1 ) + { + printf( "Cannot find any device" ); + goto main_exit; + } + + buf_len = sizeof(char)*w->w; + buf = malloc( buf_len ); + + sample_len = BUF_LENGHT; + sample_buf = malloc( sample_len ); + + srand(0); //fake seed + for ( i=0; i<400;i++ ) + { + //for (j=0; j