Update gaudin and gadc demos for new GWIN
This commit is contained in:
parent
38a2a44b3d
commit
c82fc68bfa
6 changed files with 101 additions and 55 deletions
|
@ -36,10 +36,7 @@
|
||||||
#include "gwinosc.h"
|
#include "gwinosc.h"
|
||||||
|
|
||||||
/* Include internal GWIN routines so we can build our own superset class */
|
/* Include internal GWIN routines so we can build our own superset class */
|
||||||
#include "gwin/internal.h"
|
#include "gwin/class_gwin.h"
|
||||||
|
|
||||||
/* Our GWIN identifier */
|
|
||||||
#define GW_SCOPE (GW_FIRST_USER_WINDOW+0)
|
|
||||||
|
|
||||||
/* The size of our dynamically allocated audio buffer */
|
/* The size of our dynamically allocated audio buffer */
|
||||||
#define AUDIOBUFSZ 64*2
|
#define AUDIOBUFSZ 64*2
|
||||||
|
@ -47,23 +44,40 @@
|
||||||
/* How many flat-line sample before we trigger */
|
/* How many flat-line sample before we trigger */
|
||||||
#define FLATLINE_SAMPLES 8
|
#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) {
|
static void _destroy(GHandle gh) {
|
||||||
/* Initialise the base class GWIN */
|
gadcHighSpeedStop();
|
||||||
if (!(gs = (GScopeObject *)_gwinInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject))))
|
if (((GScopeObject *)gh)->lastscopetrace) {
|
||||||
return 0;
|
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 */
|
static const gwinVMT scopeVMT = {
|
||||||
gs->gwin.type = GW_SCOPE;
|
"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);
|
gfxSemInit(&gs->bsem, 0, 1);
|
||||||
gs->nextx = 0;
|
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;
|
return 0;
|
||||||
if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(AUDIOBUFSZ * sizeof(adcsample_t))))
|
if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(AUDIOBUFSZ * sizeof(adcsample_t))))
|
||||||
return 0;
|
return 0;
|
||||||
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
|
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
|
||||||
gs->lasty = gs->gwin.height/2;
|
gs->lasty = gs->g.height/2;
|
||||||
#elif TRIGGER_METHOD == TRIGGER_MINVALUE
|
#elif TRIGGER_METHOD == TRIGGER_MINVALUE
|
||||||
gs->lasty = gs->gwin.height/2;
|
gs->lasty = gs->g.height/2;
|
||||||
gs->scopemin = 0;
|
gs->scopemin = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -72,10 +86,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor
|
||||||
gadcHighSpeedSetBSem(&gs->bsem, &gs->myEvent);
|
gadcHighSpeedSetBSem(&gs->bsem, &gs->myEvent);
|
||||||
gadcHighSpeedStart();
|
gadcHighSpeedStart();
|
||||||
|
|
||||||
|
gwinSetVisible((GHandle)gs, pInit->show);
|
||||||
return (GHandle)gs;
|
return (GHandle)gs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinWaitForScopeTrace(GHandle gh) {
|
void gwinScopeWaitForTrace(GHandle gh) {
|
||||||
#define gs ((GScopeObject *)(gh))
|
#define gs ((GScopeObject *)(gh))
|
||||||
int i;
|
int i;
|
||||||
coord_t x, y;
|
coord_t x, y;
|
||||||
|
@ -91,6 +106,9 @@ void gwinWaitForScopeTrace(GHandle gh) {
|
||||||
coord_t scopemin;
|
coord_t scopemin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (gh->vmt != &scopeVMT)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Wait for a set of audio conversions */
|
/* Wait for a set of audio conversions */
|
||||||
gfxSemWait(&gs->bsem, TIME_INFINITE);
|
gfxSemWait(&gs->bsem, TIME_INFINITE);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
/* A scope window object. Treat it as a black box */
|
/* A scope window object. Treat it as a black box */
|
||||||
typedef struct GScopeObject_t {
|
typedef struct GScopeObject_t {
|
||||||
GWindowObject gwin; // Base Class
|
GWindowObject g; // Base Class
|
||||||
|
|
||||||
coord_t *lastscopetrace; // To store last scope trace
|
coord_t *lastscopetrace; // To store last scope trace
|
||||||
gfxSem bsem; // We get signalled on this
|
gfxSem bsem; // We get signalled on this
|
||||||
|
@ -78,18 +78,12 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* Create a scope window.
|
* 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.
|
* Wait for a scope trace to be ready and then draw it.
|
||||||
*/
|
*/
|
||||||
void gwinWaitForScopeTrace(GHandle gh);
|
void gwinScopeWaitForTrace(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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
* It also demonstrates how to write your own custom GWIN window type.
|
* It also demonstrates how to write your own custom GWIN window type.
|
||||||
*/
|
*/
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "chprintf.h"
|
|
||||||
|
|
||||||
/* Include our custom gwin oscilloscope */
|
/* Include our custom gwin oscilloscope */
|
||||||
#include "gwinosc.h"
|
#include "gwinosc.h"
|
||||||
|
@ -82,7 +81,7 @@ static GTimer lsTimer;
|
||||||
|| (lastdial > dialvalue && lastdial - dialvalue > MY_DIAL_JITTER)) {
|
|| (lastdial > dialvalue && lastdial - dialvalue > MY_DIAL_JITTER)) {
|
||||||
|
|
||||||
/* Write the value */
|
/* Write the value */
|
||||||
chprintf((BaseSequentialStream *)param, "DIAL: %u\n", dialvalue);
|
gwinPrintf((GHandle)param, "DIAL: %u\n", dialvalue);
|
||||||
|
|
||||||
/* Save for next time */
|
/* Save for next time */
|
||||||
lastdial = dialvalue;
|
lastdial = dialvalue;
|
||||||
|
@ -107,7 +106,7 @@ static GTimer lsTimer;
|
||||||
|| (lasttemp > tempvalue && lasttemp - tempvalue > MY_TEMP_JITTER)) {
|
|| (lasttemp > tempvalue && lasttemp - tempvalue > MY_TEMP_JITTER)) {
|
||||||
|
|
||||||
/* Write the value */
|
/* Write the value */
|
||||||
chprintf((BaseSequentialStream *)param, "TEMP: %u\n", tempvalue);
|
gwinPrintf((GHandle)param, "TEMP: %u\n", tempvalue);
|
||||||
|
|
||||||
/* Save for next time */
|
/* Save for next time */
|
||||||
lasttemp = tempvalue;
|
lasttemp = tempvalue;
|
||||||
|
@ -138,7 +137,6 @@ int main(void) {
|
||||||
coord_t swidth, sheight;
|
coord_t swidth, sheight;
|
||||||
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
|
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
|
||||||
GHandle ghText;
|
GHandle ghText;
|
||||||
BaseSequentialStream *gsText;
|
|
||||||
font_t font;
|
font_t font;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -151,19 +149,34 @@ int main(void) {
|
||||||
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
|
#if defined(MY_DIAL_DEVICE) || defined(MY_TEMP_DEVICE)
|
||||||
/* Set up the console window we use for dial readings */
|
/* Set up the console window we use for dial readings */
|
||||||
font = gdispOpenFont("UI2");
|
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);
|
gwinSetBgColor(ghText, Black);
|
||||||
gwinSetColor(ghText, Yellow);
|
gwinSetColor(ghText, Yellow);
|
||||||
gwinClear(ghText);
|
gwinClear(ghText);
|
||||||
gsText = gwinGetConsoleStream(ghText);
|
|
||||||
|
|
||||||
/* Start our timer for reading the dial */
|
/* Start our timer for reading the dial */
|
||||||
gtimerInit(&lsTimer);
|
gtimerInit(&lsTimer);
|
||||||
gtimerStart(&lsTimer, LowSpeedTimer, gsText, TRUE, MY_LS_DELAY);
|
gtimerStart(&lsTimer, LowSpeedTimer, ghText, TRUE, MY_LS_DELAY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set up the scope window in the top right on the screen */
|
/* 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);
|
gwinSetBgColor(ghScope, White);
|
||||||
gwinSetColor(ghScope, Red);
|
gwinSetColor(ghScope, Red);
|
||||||
gwinClear(ghScope);
|
gwinClear(ghScope);
|
||||||
|
@ -174,6 +187,6 @@ int main(void) {
|
||||||
* The function below internally performs a wait thus giving the timer thread a
|
* The function below internally performs a wait thus giving the timer thread a
|
||||||
* chance to run.
|
* chance to run.
|
||||||
*/
|
*/
|
||||||
gwinWaitForScopeTrace(ghScope);
|
gwinScopeWaitForTrace(ghScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,7 @@
|
||||||
#include "gwinosc.h"
|
#include "gwinosc.h"
|
||||||
|
|
||||||
/* Include internal GWIN routines so we can build our own superset class */
|
/* Include internal GWIN routines so we can build our own superset class */
|
||||||
#include "gwin/internal.h"
|
#include "gwin/class_gwin.h"
|
||||||
|
|
||||||
/* Our GWIN identifier */
|
|
||||||
#define GW_SCOPE (GW_FIRST_USER_WINDOW+0)
|
|
||||||
|
|
||||||
/* The size of our dynamically allocated audio buffer */
|
/* The size of our dynamically allocated audio buffer */
|
||||||
#define AUDIOBUFSZ 64*2
|
#define AUDIOBUFSZ 64*2
|
||||||
|
@ -54,23 +51,42 @@
|
||||||
/* How many flat-line sample before we trigger */
|
/* How many flat-line sample before we trigger */
|
||||||
#define FLATLINE_SAMPLES 8
|
#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 */
|
/* 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;
|
return 0;
|
||||||
|
|
||||||
/* Initialise the scope object members and allocate memory for buffers */
|
/* Initialise the scope object members and allocate memory for buffers */
|
||||||
gs->gwin.type = GW_SCOPE;
|
|
||||||
gfxSemInit(&gs->bsem, 0, 1);
|
gfxSemInit(&gs->bsem, 0, 1);
|
||||||
gs->nextx = 0;
|
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;
|
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;
|
return 0;
|
||||||
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
|
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
|
||||||
gs->lasty = gs->gwin.height/2;
|
gs->lasty = gs->g.height/2;
|
||||||
#elif TRIGGER_METHOD == TRIGGER_MINVALUE
|
#elif TRIGGER_METHOD == TRIGGER_MINVALUE
|
||||||
gs->lasty = gs->gwin.height/2;
|
gs->lasty = gs->g.height/2;
|
||||||
gs->scopemin = 0;
|
gs->scopemin = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -79,10 +95,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor
|
||||||
gaudinSetBSem(&gs->bsem, &gs->myEvent);
|
gaudinSetBSem(&gs->bsem, &gs->myEvent);
|
||||||
gaudinStart();
|
gaudinStart();
|
||||||
|
|
||||||
|
gwinSetVisible((GHandle)gs, pInit->show);
|
||||||
return (GHandle)gs;
|
return (GHandle)gs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gwinWaitForScopeTrace(GHandle gh) {
|
void gwinScopeWaitForTrace(GHandle gh) {
|
||||||
#define gs ((GScopeObject *)(gh))
|
#define gs ((GScopeObject *)(gh))
|
||||||
int i;
|
int i;
|
||||||
coord_t x, y;
|
coord_t x, y;
|
||||||
|
@ -98,6 +115,9 @@ void gwinWaitForScopeTrace(GHandle gh) {
|
||||||
coord_t scopemin;
|
coord_t scopemin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (gh->vmt != &scopeVMT)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Wait for a set of audio conversions */
|
/* Wait for a set of audio conversions */
|
||||||
gfxSemWait(&gs->bsem, TIME_INFINITE);
|
gfxSemWait(&gs->bsem, TIME_INFINITE);
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
|
|
||||||
/* A scope window object. Treat it as a black box */
|
/* A scope window object. Treat it as a black box */
|
||||||
typedef struct GScopeObject_t {
|
typedef struct GScopeObject_t {
|
||||||
GWindowObject gwin; // Base Class
|
GWindowObject g; // Base Class
|
||||||
|
|
||||||
coord_t *lastscopetrace; // To store last scope trace
|
coord_t *lastscopetrace; // To store last scope trace
|
||||||
gfxSem bsem; // We get signalled on this
|
gfxSem bsem; // We get signalled on this
|
||||||
|
@ -84,18 +84,12 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* Create a scope window.
|
* 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.
|
* Wait for a scope trace to be ready and then draw it.
|
||||||
*/
|
*/
|
||||||
void gwinWaitForScopeTrace(GHandle gh);
|
void gwinScopeWaitForTrace(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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,20 @@ int main(void) {
|
||||||
sheight = gdispGetHeight();
|
sheight = gdispGetHeight();
|
||||||
|
|
||||||
/* Set up the scope window to fill the screen */
|
/* 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);
|
gwinSetBgColor(ghScope, White);
|
||||||
gwinSetColor(ghScope, Red);
|
gwinSetColor(ghScope, Red);
|
||||||
gwinClear(ghScope);
|
gwinClear(ghScope);
|
||||||
|
|
||||||
/* Just keep displaying the scope traces */
|
/* Just keep displaying the scope traces */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
gwinWaitForScopeTrace(ghScope);
|
gwinScopeWaitForTrace(ghScope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue