Update gaudin and gadc demos for new GWIN

This commit is contained in:
inmarket 2013-07-16 15:28:42 +10:00
parent 38a2a44b3d
commit c82fc68bfa
6 changed files with 101 additions and 55 deletions

View File

@ -36,10 +36,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
@ -47,23 +44,40 @@
/* 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, uint32_t physdev, uint32_t frequency) {
/* Initialise the base class GWIN */
if (!(gs = (GScopeObject *)_gwinInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject))))
return 0;
static void _destroy(GHandle gh) {
gadcHighSpeedStop();
if (((GScopeObject *)gh)->lastscopetrace) {
gfxFree(((GScopeObject *)gh)->lastscopetrace);
((GScopeObject *)gh)->lastscopetrace = 0;
}
if (((GScopeObject *)gh)->audiobuf) {
gfxFree(((GScopeObject *)gh)->audiobuf);
((GScopeObject *)gh)->audiobuf = 0;
}
}
/* Initialise the scope object members and allocate memory for buffers */
gs->gwin.type = GW_SCOPE;
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, uint32_t physdev, uint32_t frequency) {
/* Initialise the base class GWIN */
if (!(gs = (GScopeObject *)_gwindowCreate(&gs->g, pInit, &scopeVMT, 0)))
return 0;
gfxSemInit(&gs->bsem, 0, 1);
gs->nextx = 0;
if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(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(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
@ -72,10 +86,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor
gadcHighSpeedSetBSem(&gs->bsem, &gs->myEvent);
gadcHighSpeedStart();
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;
@ -91,6 +106,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);

View File

@ -56,7 +56,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
@ -78,18 +78,12 @@ extern "C" {
/**
* Create a scope window.
*/
GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coord_t cy, uint32_t physdev, uint32_t frequency);
GHandle gwinScopeCreate(GScopeObject *gs, GWindowInit *pInit, uint32_t physdev, 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
}

View File

@ -37,7 +37,6 @@
* It also demonstrates how to write your own custom GWIN window type.
*/
#include "gfx.h"
#include "chprintf.h"
/* Include our custom gwin oscilloscope */
#include "gwinosc.h"
@ -82,7 +81,7 @@ static GTimer lsTimer;
|| (lastdial > dialvalue && lastdial - dialvalue > MY_DIAL_JITTER)) {
/* Write the value */
chprintf((BaseSequentialStream *)param, "DIAL: %u\n", dialvalue);
gwinPrintf((GHandle)param, "DIAL: %u\n", dialvalue);
/* Save for next time */
lastdial = dialvalue;
@ -107,7 +106,7 @@ static GTimer lsTimer;
|| (lasttemp > tempvalue && lasttemp - tempvalue > MY_TEMP_JITTER)) {
/* Write the value */
chprintf((BaseSequentialStream *)param, "TEMP: %u\n", tempvalue);
gwinPrintf((GHandle)param, "TEMP: %u\n", tempvalue);
/* Save for next time */
lasttemp = tempvalue;
@ -138,7 +137,6 @@ int main(void) {
coord_t swidth, sheight;
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
GHandle ghText;
BaseSequentialStream *gsText;
font_t font;
#endif
@ -151,19 +149,34 @@ int main(void) {
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
/* Set up the console window we use for dial readings */
font = gdispOpenFont("UI2");
ghText = gwinCreateConsole(&gTextWindow, 0, 0, swidth-SCOPE_CX, sheight, font);
gwinSetDefaultFont(font);
{
GWindowInit wi;
wi.show = TRUE;
wi.x = wi.y = 0;
wi.width = swidth-SCOPE_CX;
wi.height = sheight;
ghText = gwinConsoleCreate(&gTextWindow, &wi);
}
gwinSetBgColor(ghText, Black);
gwinSetColor(ghText, Yellow);
gwinClear(ghText);
gsText = gwinGetConsoleStream(ghText);
/* Start our timer for reading the dial */
gtimerInit(&lsTimer);
gtimerStart(&lsTimer, LowSpeedTimer, gsText, TRUE, MY_LS_DELAY);
gtimerStart(&lsTimer, LowSpeedTimer, ghText, TRUE, MY_LS_DELAY);
#endif
/* Set up the scope window in the top right on the screen */
ghScope = gwinCreateScope(&gScopeWindow, swidth-SCOPE_CX, 0, SCOPE_CX, SCOPE_CY, MY_MIC_DEVICE, MY_MIC_FREQUENCY);
{
GWindowInit wi;
wi.show = TRUE;
wi.x = swidth-SCOPE_CX;
wi.y = 0;
wi.width = SCOPE_CX;
wi.height = SCOPE_CY;
ghScope = gwinScopeCreate(&gScopeWindow, &wi, MY_MIC_DEVICE, MY_MIC_FREQUENCY);
}
gwinSetBgColor(ghScope, White);
gwinSetColor(ghScope, Red);
gwinClear(ghScope);
@ -174,6 +187,6 @@ int main(void) {
* The function below internally performs a wait thus giving the timer thread a
* chance to run.
*/
gwinWaitForScopeTrace(ghScope);
gwinScopeWaitForTrace(ghScope);
}
}

View File

@ -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);

View File

@ -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
}

View File

@ -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);
}
}