金牌会员
- 积分
- 1383
- 金钱
- 1383
- 注册时间
- 2015-2-3
- 在线时间
- 197 小时
|
发表于 2016-7-3 23:39:20
|
显示全部楼层
本帖最后由 yyx112358 于 2016-7-3 23:42 编辑
发这里好了
[mw_shl_code=c,true]/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.26 *
* Compiled Aug 18 2014, 17:12:05 *
* (c) 2014 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
// USER START (Optionally insert additional includes)
#include "malloc.h"
#include <stdio.h>
#include "UI.h"
// USER END
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_GRAPH_0 (GUI_ID_USER + 0x01)
#define ID_MULTIPAGE_0 (GUI_ID_USER + 0x02)
#define ID_BUTTON_0 (GUI_ID_USER + 0x03)
#define ID_BUTTON_1 (GUI_ID_USER + 0x04)
#define ID_BUTTON_2 (GUI_ID_USER + 0x05)
#define ID_BUTTON_3 (GUI_ID_USER + 0x06)
// USER START (Optionally insert additional defines)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
WM_HWIN CreateDSO_Graph( void );
WM_HWIN CreateDSO_Filter( void );
WM_HWIN CreateDSO_Sample( void );
WM_HWIN CreateDSO_Data( void );
#define GRAPH_SCOLLERBAR_WIDTH (12)
#define DSO_TIMER_PERIOD (200)
static GRAPH_DATA_Handle _ahData[DSO_GRAPH_MAX_CURVE]; // Array of handles for the GRAPH_DATA objects
static GRAPH_SCALE_Handle _hScaleV; // Handle of vertical scale
static GRAPH_SCALE_Handle _hScaleH; // Handle of horizontal scale
static I16 *_pval[DSO_GRAPH_MAX_CURVE]; //原始数据
static unsigned int _cnt = 0,_start=0; //原始数据队列指针,起始位置指针
struct Scale_Info_Struct Scale_Info = { 60, 60, 0x100, 0x100, 0, 228, 0, 0, 0 };
struct Graph_Info_Struct Graph_Info = { 240, 240, 240, 240,
0,0,
0,1,1,1,
1,
1,1,
100,1,1,1,1};
static GUI_COLOR _aColor[] = { GUI_RED, GUI_GREEN, GUI_LIGHTBLUE, GUI_GRAY,
GUI_LIGHTRED,GUI_LIGHTGREEN,GUI_LIGHTBLUE,GUI_WHITE }; //曲线颜色
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "DSO", ID_WINDOW_0, 0, 0, 240, 320, 0, 0x0, 0 },
{ GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 0, 0, 240, 240, 0, 0x0, 0 },
{ MULTIPAGE_CreateIndirect, "Multipage", ID_MULTIPAGE_0, 0, 240, 200, 80, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button_Close", ID_BUTTON_0, 200, 300, 37, 20, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 200, 280, 37, 20, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_2, 200, 260, 37, 20, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_3, 200, 240, 37, 20, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
struct Scale_Info_Struct DSO_GetScaleInfo( void )//Scale_Info仅对DSO显示任务内部可读写,对外部仅制度,故采用返回值而非使用指针
{
return Scale_Info;
}
struct Graph_Info_Struct DSO_GetGraphInfo( void )
{
return Graph_Info;
}
static void _UserDraw( WM_HWIN hWin, int Stage )//绘制前、后会调用该函数
{
GUI_PID_STATE pid;
signed int scrollx = GRAPH_GetScrollValue( hWin, GUI_COORD_X ), scrolly = GRAPH_GetScrollValue( hWin, GUI_COORD_Y );
unsigned int scalexoff;
//无滚动条(scrollx得到的返回值为-1),说明图像缩小,反之放大
if ( -1 == scrollx ) scalexoff = Graph_Info.xsize - Scale_Info.cnt;
else scalexoff = Graph_Info.xsize - Scale_Info.cnt + scrollx - GRAPH_SCOLLERBAR_WIDTH;
GUI_PID_GetState( &pid );
switch ( Stage )
{
case GRAPH_DRAW_FIRST:/* Draw for example a user defined grid...*/
{
GRAPH_SCALE_SetOff( _hScaleH, scalexoff );
}
break;
case GRAPH_DRAW_LAST:/* Draw for example a user defined scale or additional text...*/
{
if ( Graph_Info.mark )
{
if ( ( 1 == pid.Pressed ) && ( pid.x <= Graph_Info.xsize - GRAPH_SCOLLERBAR_WIDTH )
&& ( pid.y <= Graph_Info.ysize - GRAPH_SCOLLERBAR_WIDTH ) )
{
int old_ta_align;
float markposx, markposy;
char str[8];
GUI_DrawHLine( pid.y, 0, Graph_Info.xsize );
GUI_DrawVLine( pid.x, 0, Graph_Info.ysize );
markposx = pid.x - (signed int)scalexoff;//注:unsigned int优先级比int高,会进行自动提升
sprintf( str, "%.1f", markposx );
GUI_DispStringAt( str, pid.x, 0 );
if ( -1 == scrolly ) markposy = Graph_Info.ysize - pid.y;
else markposy = Graph_Info.ysize - pid.y + scrolly - GRAPH_SCOLLERBAR_WIDTH;//Y轴需要作处理
sprintf( str, "%.1f", markposy );
old_ta_align = GUI_SetTextAlign( GUI_TA_RIGHT );
GUI_DispStringAt( str, Graph_Info.xsize - 10, pid.y );
GUI_SetTextAlign( old_ta_align );
}
}
}
break;
}
}
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
// USER START (Optionally insert additional variables)
WM_HWIN hWin;
unsigned int i = 0;
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Button_Close'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetText(hItem, "Close");
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetText(hItem, "Clear");
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
BUTTON_SetText(hItem, "?");
BUTTON_SetFont(hItem, GUI_FONT_13B_ASCII);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
BUTTON_SetText(hItem, "||");
BUTTON_SetFont(hItem, GUI_FONT_13B_ASCII);
// USER START (Optionally insert additional code for further widget initialization)
hItem = WM_GetDialogItem( pMsg->hWin, ID_BUTTON_3 );
BUTTON_SetTextColor( hItem, BUTTON_CI_UNPRESSED,
( Graph_Info.pause ) ? ( GUI_RED ) : ( GUI_BLACK ) );
//=====================图形Graph====================
hItem = WM_GetDialogItem( pMsg->hWin, ID_GRAPH_0 );
//初始化尺寸
Graph_Info.xsize = WM_GetWindowSizeX( hItem ); Graph_Info.ysize = WM_GetWindowSizeY( hItem );
Graph_Info.xvsize = Graph_Info.xsize+100; Graph_Info.yvsize = Graph_Info.ysize + 100;
Scale_Info.xdist = Graph_Info.xsize / 4; Scale_Info.ydist = Graph_Info.ysize / 4;
Scale_Info.xpos = 0; Scale_Info.ypos = Graph_Info.ysize - 12;
// 添加图形
for ( i = 0; i < DSO_GRAPH_MAX_CURVE; i++ )
{
U32 j = 0;
_ahData = GRAPH_DATA_YT_Create( _aColor, Graph_Info.xsize*DSO_GRAPH_MAX_XMAG, 0, 0 );
//GRAPH_DATA_YT_SetAlign( _ahData, GRAPH_ALIGN_LEFT );
//GRAPH_DATA_YT_MirrorX( _ahData, 1 );
GRAPH_AttachData( hItem, _ahData );
#ifdef WIN32
_pval = (I16*)malloc( Graph_Info.xsize*sizeof( I16 ) );
#else
_pval = (I16*)mymalloc(SRAMIN, Graph_Info.xsize*sizeof( I16 ) );
#endif // WIN32
for ( j = 0; j < Graph_Info.xsize; j++ ) _pval[j] = 0;
}
// 设定图形属性
GRAPH_SetGridDistX( hItem, Scale_Info.xdist ); GRAPH_SetGridDistY( hItem, Scale_Info.ydist );
GRAPH_SetGridVis( hItem, 1 );
GRAPH_SetGridFixedX( hItem, 1 );
GRAPH_SetVSizeX( hItem, Graph_Info.xvsize ); GRAPH_SetVSizeY( hItem, Graph_Info.yvsize );
GRAPH_SetUserDraw( hItem, _UserDraw );
// 水平刻度
_hScaleH = GRAPH_SCALE_Create( Scale_Info.ypos, GUI_TA_BOTTOM, GRAPH_SCALE_CF_HORIZONTAL, Scale_Info.xdist );
GRAPH_SCALE_SetTextColor( _hScaleH, GUI_BLUE );
GRAPH_SCALE_SetNumDecs( _hScaleH, Scale_Info.xdecs );
GRAPH_AttachScale( hItem, _hScaleH );
// 垂直刻度
_hScaleV = GRAPH_SCALE_Create( Scale_Info.xpos, GUI_TA_LEFT, GRAPH_SCALE_CF_VERTICAL, Scale_Info.ydist );
GRAPH_SCALE_SetTextColor( _hScaleV, GUI_YELLOW );
GRAPH_SCALE_SetNumDecs( _hScaleV, Scale_Info.ydecs );
GRAPH_AttachScale( hItem, _hScaleV );
//======================多页MULTIPAGE==================
hItem = WM_GetDialogItem( pMsg->hWin, ID_MULTIPAGE_0 );
hWin = CreateDSO_Graph();
MULTIPAGE_AddPage( hItem, hWin, "Graph" );
hWin = CreateDSO_Filter();
MULTIPAGE_AddPage( hItem, hWin, "Filter" );
hWin = CreateDSO_Sample();
MULTIPAGE_AddPage( hItem, hWin, "Sample" );
hWin = CreateDSO_Data();
MULTIPAGE_AddPage( hItem, hWin, "Data" );
MULTIPAGE_SelectPage( hItem, 0 );
//======================定时器========================
WM_CreateTimer( pMsg->hWin, 0, DSO_TIMER_PERIOD, 0 );
// USER END
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_MULTIPAGE_0: // Notifications sent by 'Multipage'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_VALUE_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_0: // Notifications sent by 'Button_Close'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
WM_DeleteWindow( pMsg->hWin );
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_1: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
for ( i = 0; i < DSO_GRAPH_MAX_CURVE; i++ )
GRAPH_DATA_YT_Clear( _ahData);
Scale_Info.cnt=0;
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_2: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
GUI_MessageBox( "Help:\nUnfinished!", NULL, 0 );
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_3: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
Graph_Info.pause = ~Graph_Info.pause;
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
case WM_DSO_GRAPH_UPDATE:
hItem = WM_GetDialogItem( pMsg->hWin, ID_GRAPH_0 );
if ( 0 == Graph_Info.pause )
{
struct DSO_Data_Struct dat = *( struct DSO_Data_Struct* )( pMsg->Data.p );
U16 j = 0;
//Scale_Info.xmag >= 0x100则插值Scale_Info.xmag /0x100次,否则每隔0x100 / Scale_Info.xmag次显示一次
if ( Scale_Info.xmag >= 0x100 ) j = Scale_Info.xmag >> 8;
else j = ( 0 == ( _cnt % ( 0x100 / Scale_Info.xmag ) ) );
for ( i = 0; i < DSO_GRAPH_MAX_CURVE; i++ )
{
U16 k= j;
I16 last_dat,delta;
_pval[_cnt] = dat.l;//原始数据
last_dat = _pval[( _cnt - 1 ) % Graph_Info.xsize];
delta = ( _pval[_cnt] - last_dat )*( Scale_Info.ymag)/(Scale_Info.xmag);
while ( k-- )
GRAPH_DATA_YT_AddValue( _ahData, last_dat+=delta );
}
_cnt++;//实际采样次数
_cnt %= Graph_Info.xsize;//循环队列指针
Scale_Info.cnt+=j;//统计画点次数以改变刻度
}
else
{
//_UserDraw( hItem, GRAPH_DRAW_LAST );
WM_InvalidateWindow( WM_GetDialogItem( pMsg->hWin, ID_GRAPH_0 ));//无效化GRAPH使之重绘
}
break;
case WM_TIMER:
{
static struct Scale_Info_Struct old_Scale_Info;
static struct Graph_Info_Struct old_Graph_Info;
hItem = WM_GetDialogItem( pMsg->hWin, ID_GRAPH_0 );
if ( Graph_Info.grid^old_Graph_Info.grid ) GRAPH_SetGridVis( hItem,Graph_Info.grid );
if ( Graph_Info.scale^old_Graph_Info.scale )
{
if ( Graph_Info.scale )
{
GRAPH_SCALE_SetPos( _hScaleH, Scale_Info.ypos );
GRAPH_SCALE_SetPos( _hScaleV, Scale_Info.xpos );
}
else
{
GRAPH_SCALE_SetPos( _hScaleH, -255 );
GRAPH_SCALE_SetPos( _hScaleV, -255 );
}
}
if ( ( Scale_Info.xmag^old_Scale_Info.xmag ) || ( Scale_Info.ymag^old_Scale_Info.ymag ) )//重绘、虚拟屏幕、改刻度
{
Graph_Info.xvsize = Graph_Info.xsize*(Scale_Info.xmag/0x100);GRAPH_SetVSizeX( hItem, Graph_Info.xvsize );
Graph_Info.yvsize = Graph_Info.ysize*( Scale_Info.ymag / 0x100 ); GRAPH_SetVSizeY( hItem, Graph_Info.yvsize );
GRAPH_SCALE_SetFactor( _hScaleH, 256.0/Scale_Info.xmag );
GRAPH_SCALE_SetFactor( _hScaleV, 256.0/Scale_Info.ymag );
for ( i = 0; i < DSO_GRAPH_MAX_CURVE; i++ )
{
// U16 j = 0, k = 0;
// I16 last_dat, delta;
GRAPH_DATA_YT_Clear( _ahData );
// if ( Scale_Info.cnt < Graph_Info.xsize )
// {
// for ( k = 1; k < Scale_Info.cnt; k++ )
// {
// last_dat = _pval[k-1];
// delta = ( _pval[k] - last_dat )*( Scale_Info.ymag ) / ( Scale_Info.xmag );
// //Scale_Info.xmag >= 0x100则插值Scale_Info.xmag /0x100次,否则每隔0x100 / Scale_Info.xmag次显示一次
// if ( Scale_Info.xmag >= 0x100 ) j = Scale_Info.xmag >> 8;
// else j = ( 0 == ( _cnt % ( 0x100 / Scale_Info.xmag ) ) );
// while ( j-- )
// GRAPH_DATA_YT_AddValue( _ahData, last_dat += delta );
// }
// }
}
}
for ( i = 0; i < DSO_SAMPLE_NUM; i++ )
{
if ( Graph_Info.disp ^ old_Graph_Info.disp )
GRAPH_DATA_YT_SetOffY( _ahData, ( 0 == Graph_Info.disp ) * 0x0F000000 );//disp为零则将图像移出视野
Graph_Info.disp[i+DSO_SAMPLE_NUM]=(Graph_Info.disp&&Graph_Info.filter);
if ( Graph_Info.disp[i+DSO_SAMPLE_NUM] ^ old_Graph_Info.disp[i+DSO_SAMPLE_NUM] )//滤波后图像
GRAPH_DATA_YT_SetOffY( _ahData[i+DSO_SAMPLE_NUM], ( 0 == Graph_Info.disp[i+DSO_SAMPLE_NUM] ) * 0x0F000000 );
}
old_Scale_Info = Scale_Info;
old_Graph_Info = Graph_Info;
WM_RestartTimer( pMsg->Data.v, DSO_TIMER_PERIOD );
}
break;
case WM_DELETE:
DESKTOP_Reset_APPRunning();
for ( i = 0; i < DSO_GRAPH_MAX_CURVE; i++ )
#ifdef WIN32// WIN32
free( _pval );
#else
myfree(SRAMIN, _pval );
#endif
break;
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateDSO
*/
WM_HWIN CreateDSO(void);
WM_HWIN CreateDSO(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
[/mw_shl_code]
|
-
效果图
|