From c82fc68bfad5787c0745b957abf61fb18304ecd8 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 16 Jul 2013 15:28:42 +1000 Subject: Update gaudin and gadc demos for new GWIN --- demos/modules/gaudin/gwinosc.c | 44 ++++++++++++++++++++++++++++++------------ demos/modules/gaudin/gwinosc.h | 12 +++--------- demos/modules/gaudin/main.c | 11 +++++++++-- 3 files changed, 44 insertions(+), 23 deletions(-) (limited to 'demos/modules/gaudin') diff --git a/demos/modules/gaudin/gwinosc.c b/demos/modules/gaudin/gwinosc.c index d90742ee..9882bcde 100644 --- a/demos/modules/gaudin/gwinosc.c +++ b/demos/modules/gaudin/gwinosc.c @@ -43,10 +43,7 @@ #include "gwinosc.h" /* Include internal GWIN routines so we can build our own superset class */ -#include "gwin/internal.h" - -/* Our GWIN identifier */ -#define GW_SCOPE (GW_FIRST_USER_WINDOW+0) +#include "gwin/class_gwin.h" /* The size of our dynamically allocated audio buffer */ #define AUDIOBUFSZ 64*2 @@ -54,23 +51,42 @@ /* How many flat-line sample before we trigger */ #define FLATLINE_SAMPLES 8 -GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coord_t cy, uint16_t channel, uint32_t frequency) { +static void _destroy(GHandle gh) { + gaudinStop(); + if (((GScopeObject *)gh)->lastscopetrace) { + gfxFree(((GScopeObject *)gh)->lastscopetrace); + ((GScopeObject *)gh)->lastscopetrace = 0; + } + if (((GScopeObject *)gh)->audiobuf) { + gfxFree(((GScopeObject *)gh)->audiobuf); + ((GScopeObject *)gh)->audiobuf = 0; + } +} + +static const gwinVMT scopeVMT = { + "Scope", // The classname + sizeof(GScopeObject), // The object size + _destroy, // The destroy routine + 0, // The redraw routine + 0, // The after-clear routine +}; + +GHandle gwinScopeCreate(GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency) { /* Initialise the base class GWIN */ - if (!(gs = (GScopeObject *)_gwinInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject)))) + if (!(gs = (GScopeObject *)_gwindowCreate(&gs->g, pInit, &scopeVMT, 0))) return 0; /* Initialise the scope object members and allocate memory for buffers */ - gs->gwin.type = GW_SCOPE; gfxSemInit(&gs->bsem, 0, 1); gs->nextx = 0; - if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(NULL, gs->gwin.width * sizeof(coord_t)))) + if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(gs->g.width * sizeof(coord_t)))) return 0; - if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(NULL, AUDIOBUFSZ * sizeof(adcsample_t)))) + if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(AUDIOBUFSZ * sizeof(adcsample_t)))) return 0; #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP - gs->lasty = gs->gwin.height/2; + gs->lasty = gs->g.height/2; #elif TRIGGER_METHOD == TRIGGER_MINVALUE - gs->lasty = gs->gwin.height/2; + gs->lasty = gs->g.height/2; gs->scopemin = 0; #endif @@ -79,10 +95,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor gaudinSetBSem(&gs->bsem, &gs->myEvent); gaudinStart(); + gwinSetVisible((GHandle)gs, pInit->show); return (GHandle)gs; } -void gwinWaitForScopeTrace(GHandle gh) { +void gwinScopeWaitForTrace(GHandle gh) { #define gs ((GScopeObject *)(gh)) int i; coord_t x, y; @@ -98,6 +115,9 @@ void gwinWaitForScopeTrace(GHandle gh) { coord_t scopemin; #endif + if (gh->vmt != &scopeVMT) + return; + /* Wait for a set of audio conversions */ gfxSemWait(&gs->bsem, TIME_INFINITE); diff --git a/demos/modules/gaudin/gwinosc.h b/demos/modules/gaudin/gwinosc.h index ff13a060..6a559c34 100644 --- a/demos/modules/gaudin/gwinosc.h +++ b/demos/modules/gaudin/gwinosc.h @@ -62,7 +62,7 @@ /* A scope window object. Treat it as a black box */ typedef struct GScopeObject_t { - GWindowObject gwin; // Base Class + GWindowObject g; // Base Class coord_t *lastscopetrace; // To store last scope trace gfxSem bsem; // We get signalled on this @@ -84,18 +84,12 @@ extern "C" { /** * Create a scope window. */ - GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coord_t cy, uint16_t channel, uint32_t frequency); + GHandle gwinScopeCreate(GScopeObject *gs, GWindowInit *pInit, uint16_t channel, uint32_t frequency); /** * Wait for a scope trace to be ready and then draw it. */ - void gwinWaitForScopeTrace(GHandle gh); - - /** - * We should also have a special destroy routine here as we have dynamically - * allocated some memory. There is no point implementing this however as, for - * this demo, we never destroy the window. - */ + void gwinScopeWaitForTrace(GHandle gh); #ifdef __cplusplus } diff --git a/demos/modules/gaudin/main.c b/demos/modules/gaudin/main.c index 2f3759ff..32418450 100644 --- a/demos/modules/gaudin/main.c +++ b/demos/modules/gaudin/main.c @@ -59,13 +59,20 @@ int main(void) { sheight = gdispGetHeight(); /* Set up the scope window to fill the screen */ - ghScope = gwinCreateScope(&gScopeWindow, 0, 0, swidth, sheight, MY_AUDIO_CHANNEL, MY_AUDIO_FREQUENCY); + { + GWindowInit wi; + + wi.show = TRUE; + wi.x = wi.y = 0; + wi.width = swidth; wi.height = sheight; + ghScope = gwinScopeCreate(&gScopeWindow, &wi, MY_AUDIO_CHANNEL, MY_AUDIO_FREQUENCY); + } gwinSetBgColor(ghScope, White); gwinSetColor(ghScope, Red); gwinClear(ghScope); /* Just keep displaying the scope traces */ while (TRUE) { - gwinWaitForScopeTrace(ghScope); + gwinScopeWaitForTrace(ghScope); } } -- cgit v1.2.3