diff options
author | inmarket <andrewh@inmarket.com.au> | 2013-07-16 15:28:42 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2013-07-16 15:28:42 +1000 |
commit | c82fc68bfad5787c0745b957abf61fb18304ecd8 (patch) | |
tree | 2e57ca8a10910cc72b56db41d34405b3a2e72890 /demos/modules/gaudin/gwinosc.c | |
parent | 38a2a44b3d27ca29019cd0d75e60233ee9188c71 (diff) | |
download | uGFX-c82fc68bfad5787c0745b957abf61fb18304ecd8.tar.gz uGFX-c82fc68bfad5787c0745b957abf61fb18304ecd8.tar.bz2 uGFX-c82fc68bfad5787c0745b957abf61fb18304ecd8.zip |
Update gaudin and gadc demos for new GWIN
Diffstat (limited to 'demos/modules/gaudin/gwinosc.c')
-rw-r--r-- | demos/modules/gaudin/gwinosc.c | 44 |
1 files changed, 32 insertions, 12 deletions
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); |