diff options
-rw-r--r-- | draw/glui.c | 71 | ||||
-rw-r--r-- | draw/glui.h | 19 | ||||
-rw-r--r-- | 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; 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 -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 <math.h> //radiola -#include <draw/tui.h> +#include <draw/glui.h> #include <hw/hw.h> #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<buf_len; j++) + // sample_buf[j] = (uint8_t)((rand()&0xff)); + + //read some samples + sdr_get_samples( sample_buf, sample_len ); + + //do fft + //simple_fft( sample_buf, sample_len/2 ); + + //prepare to show on the screen + if (normalise( sample_buf, sample_len, buf, buf_len ) == -1) + { + printf("Cannot normalise\n"); + } + glui_waterfall_data( t, buf_len, buf ); + //printf("\n\b"); + usleep(100000); + } + +main_exit: + //close gui, restore terminal mode + glui_close( t ); + sdr_close(); return 0; }
\ No newline at end of file |