241 lines
5.0 KiB
C
241 lines
5.0 KiB
C
#include "mywin_inc.h"
|
|
#include "adc.h"
|
|
#include "timer.h"
|
|
#include "mywin_spectrum.h"
|
|
|
|
|
|
|
|
#define WIN_SPECTRUM_TYPE "WIN_SpectrumStruct"
|
|
|
|
|
|
|
|
|
|
static WIN_SpectrumStruct *g_spec=0;
|
|
|
|
|
|
//1ms计时中断
|
|
static void timer_irq (void)
|
|
{
|
|
if (g_spec->saveNum<SPECTRUM_WAVESAVE_MAX)
|
|
{
|
|
g_spec->wavePtr[g_spec->saveNum++]=Get_Adc (ADC_Channel_5);
|
|
}
|
|
|
|
if (g_spec->saveNum==SPECTRUM_WAVESAVE_MAX)
|
|
{
|
|
if (g_spec->wavePtr==g_spec->waveSave)
|
|
{
|
|
g_spec->wavePtr=g_spec->waveSave2;
|
|
g_spec->waveUsePtr=g_spec->waveSave;
|
|
}
|
|
else
|
|
{
|
|
g_spec->wavePtr=g_spec->waveSave;
|
|
g_spec->waveUsePtr=g_spec->waveSave2;
|
|
}
|
|
g_spec->waveDone=1;
|
|
g_spec->saveNum=0;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
static void timer_init (WIN_SpectrumStruct *s)
|
|
{
|
|
g_spec=s;
|
|
TIMER_InitStruct timer_init={0};
|
|
timer_init.Cycle=800; //1毫秒计时器
|
|
timer_init.Tim=TIM3;
|
|
timer_init.UpdataCall=timer_irq;
|
|
TIMER_InitNormal(&timer_init);
|
|
|
|
}
|
|
|
|
static void timer_deInit (void)
|
|
{
|
|
TIMER_DeInit (TIM3);
|
|
}
|
|
|
|
|
|
|
|
WIN_SpectrumStruct *WIN_CreatSpectrum (WIN_WindowStruct *base,
|
|
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
|
|
int x,int y,int x_size,int y_size)
|
|
{
|
|
//重设消息循环
|
|
if (msgLoop==0)
|
|
{
|
|
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))SPECTRUM_defaultMsgLoop;
|
|
}
|
|
|
|
WIN_SpectrumStruct *ret=mymalloc (sizeof ( WIN_SpectrumStruct));
|
|
//调用父类的构造函数
|
|
if (ret)
|
|
{
|
|
mymemset (ret,0,sizeof ( WIN_SpectrumStruct));
|
|
if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
|
|
{
|
|
//创建失败
|
|
myfree (ret);
|
|
ret=0;
|
|
}
|
|
else
|
|
{
|
|
((WIN_WindowStruct *)ret)->winType=WIN_SPECTRUM_TYPE;
|
|
((WIN_WindowStruct *)ret)->intercept=1;
|
|
((WIN_WindowStruct *)ret)->deleteWindow=(void (*)(struct _WIN_WindowStruct *win))WIN_DeleteSpectrum;
|
|
//构造一个消息框
|
|
//ret->title="频谱";
|
|
ret->rectColor=0x221f18;
|
|
ret->txtColor=0x342e27;
|
|
ret->selectRectColor=0x342f2a;
|
|
ret->selectTxtColor=0xc2ae9b;
|
|
ret->wavePtr=ret->waveSave;
|
|
ret->waveUsePtr=ret->waveSave;
|
|
ret->timerId=WIN_CreatTimer ((WIN_WindowStruct *)ret,50);
|
|
Adc_Init();
|
|
timer_init (ret);
|
|
arm_rfft_fast_init_f32 (&ret->fftStruct,SPECTRUM_WAVESAVE_MAX);
|
|
}
|
|
}
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WIN_DeleteSpectrum (WIN_SpectrumStruct *stopwatch )
|
|
{
|
|
|
|
timer_deInit();
|
|
Adc_DeInit();
|
|
//调用父类的销毁函数
|
|
WIN_DeleteWindow ( (WIN_WindowStruct *)stopwatch);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//消息框的绘制函数
|
|
void SPECTRUM_DefaultPaint (WIN_SpectrumStruct *stopwatch)
|
|
{
|
|
int x=0;
|
|
int y=0;
|
|
int x_size=((WIN_WindowStruct *)stopwatch)->x_size;
|
|
int y_size=((WIN_WindowStruct *)stopwatch)->y_size;
|
|
char txt_buff[20]={0};
|
|
|
|
WIN_PaintBackGround ((WIN_WindowStruct *)stopwatch);
|
|
|
|
//显示标题
|
|
int img_x=x+25;
|
|
int img_y=y;
|
|
int img_xsize=0;
|
|
int img_ysize=0;
|
|
int head_ysize=45;
|
|
WIN_SetLcdColor (((WIN_WindowStruct *)stopwatch)->color);
|
|
if (stopwatch->icon)
|
|
{
|
|
WIN_GetImageSize (stopwatch->icon,&img_xsize,&img_ysize);
|
|
if (img_ysize>head_ysize) img_ysize=head_ysize;
|
|
WIN_DrawImagByAlpha (img_x,img_y+head_ysize/2-img_ysize/2, img_xsize,img_ysize,stopwatch->icon,LCD_GetLcdColor16());
|
|
img_xsize+=10;
|
|
}
|
|
WIN_DrawTxtAt (stopwatch->title,img_x+img_xsize,y+head_ysize/2-WIN_GetFontHight()/2);
|
|
// x+=25;x_size-=25*2;
|
|
// y+=45;y_size-=45*2;
|
|
x+=(x_size-(SPECTRUM_WAVESAVE_MAX-1)*7)/2;
|
|
if (stopwatch->waveDone)
|
|
{
|
|
for (int i=1;i<SPECTRUM_WAVESAVE_MAX-1;i++)
|
|
{
|
|
//WIN_DrawHLine (x+i*7,y_size-(int)stopwatch->waveFft[i]/16,x+i*7+7);
|
|
int y_s=y_size-(int)stopwatch->waveFft[i+1]/16;
|
|
if (y_s<0) y_s=0;
|
|
if (y_s>=y_size) y_s=y_size-1;
|
|
WIN_DrawRect (x+i*7,y_s,7,y_size-y_s);
|
|
//WIN_DrawHLine (x+i*7,(int)stopwatch->waveUsePtr[i]/8,x+i*7+7);
|
|
}
|
|
stopwatch->waveDone=0;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//消息框的消息处理函数
|
|
void SPECTRUM_defaultMsgLoop (WIN_SpectrumStruct *stopwatch,WIN_MsgStruct *msg)
|
|
{
|
|
WIN_KeyStruct *k=0;
|
|
switch (msg->msg)
|
|
{
|
|
case WIN_MSG_PAINT:
|
|
SPECTRUM_DefaultPaint(stopwatch);
|
|
break;
|
|
case WIN_MSG_TIMER:
|
|
if (msg->data.v==stopwatch->timerId)
|
|
{
|
|
|
|
if (stopwatch->waveDone)
|
|
{
|
|
arm_rfft_fast_f32 (&stopwatch->fftStruct,stopwatch->waveUsePtr,stopwatch->waveFft,0);
|
|
//WIN_SetInvalidWhenTop ((WIN_WindowStruct *)stopwatch);
|
|
WIN_WindowStruct *win=(WIN_WindowStruct *)stopwatch;
|
|
WIN_SetInvalidRectWhenTop ((WIN_WindowStruct *)stopwatch,0,win->y_size-120,win->x_size,120);
|
|
}
|
|
}
|
|
break;
|
|
case WIN_MSG_KEY:
|
|
k=msg->data.p;
|
|
if (k->shortPress&KEY_VALUE_UP)//短按
|
|
{
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_DOWN)
|
|
{
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_HOME)
|
|
{
|
|
((WIN_WindowStruct *)stopwatch)->deleteWindow((WIN_WindowStruct *)stopwatch);
|
|
}
|
|
if (k->shortPress)
|
|
{
|
|
WIN_SetInvalid ((WIN_WindowStruct *)stopwatch);
|
|
}
|
|
break;//case WIN_MSG_KEY:
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)stopwatch,msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
WIN_SpectrumStruct *SPECTRUM_RecordWave (WIN_WindowStruct *base)
|
|
{
|
|
WIN_SpectrumStruct *ret=0;
|
|
if (base)
|
|
{
|
|
ret=WIN_CreatSpectrum (base,0,0,0,base->x_size,base->y_size);
|
|
}
|
|
else
|
|
{
|
|
ret=WIN_CreatSpectrum (0,0,0,0,LCD_GetLcdSizeX(),50);
|
|
}
|
|
//WIN_SetBackPic ((WIN_WindowStruct *)ret,&base->pic);
|
|
WIN_ShowWindow((WIN_WindowStruct*)ret);
|
|
return ret;
|
|
}
|
|
|
|
|