OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3221|回复: 2

emWin中GraphYT 想加一条上限和下限的直线,模拟好的,但机器不显示

[复制链接]

25

主题

96

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
297
金钱
297
注册时间
2016-6-2
在线时间
49 小时
发表于 2016-11-3 16:59:22 | 显示全部楼层 |阅读模式
1金钱

emWin中GraphYT 想加一条上限和下限的直线,VC.net模拟好的,但刷到机器里就不显示那两条线了。

以下是代码:

[mw_shl_code=applescript,true]/*********************************************************************
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2014  SEGGER Microcontroller GmbH & Co. KG       *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V5.26 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws.   Knowledge of the
source code may not be used to write a similar product.  This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : WIDGET_Graph.c
Purpose     : Demonstrates the use of the GRAPH widget
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
----------------------------------------------------------------------
*/
#include <stdlib.h>
#include <string.h>

#include "DIALOG.h"
#include "GRAPH.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
static GRAPH_DATA_Handle  _ahData; // 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 int _Stop = 1;
static int counter = 0;
static GUI_COLOR _aColor= GUI_GREEN; // Array of colors for the GRAPH_DATA objects

static int test_press;
static int drop_limit;
static int test_duration;
static int press_top;
static int press_bottom;
static int ver_off;
static int press_factor;
static float current_press;
//
// Dialog ressource
//
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Graph widget demo",  0                ,   0,   0, 320, 240, FRAMEWIN_CF_MOVEABLE },
  { GRAPH_CreateIndirect,     0,                   GUI_ID_GRAPH0    ,   3,   5, 307, 180 },
  { EDIT_CreateIndirect, "Start", GUI_ID_EDIT0, 120, 190, 80, 20 },
  { BUTTON_CreateIndirect,    "Start",       GUI_ID_BUTTON0   , 230, 195,  80,  35 },
  
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _AddValues
*
* Function description
*   This routine calculates new random values in dependence of the previous added values
*   and adds them to the GRAPH_DATA objects
*/
static void _AddValues(void) {
  
        current_press = current_press - 0.5;
        if (current_press > press_top) {
                current_press = press_top;
        }
        else if (current_press < press_bottom) {
                current_press = press_bottom;
    }
       
        GRAPH_DATA_YT_SetAlign(_ahData, GRAPH_ALIGN_LEFT);
        GRAPH_DATA_YT_AddValue(_ahData, (current_press - press_bottom) /press_factor);
}

/*********************************************************************
*
*       _UserDraw
*
* Function description
*   This routine is called by the GRAPH object before anything is drawn
*   and after the last drawing operation.
*/
static void _UserDraw(WM_HWIN hWin, int Stage) {
        int temp=0;
  if (Stage == GRAPH_DRAW_LAST) {
    char acText[] = "Pressure - hPa";
    GUI_RECT Rect;
    GUI_RECT RectInvalid;
    int FontSizeY;

    GUI_SetFont(&GUI_Font13_ASCII);
    FontSizeY = GUI_GetFontSizeY();
    WM_GetInsideRect(&Rect);
    WM_GetInvalidRect(hWin, &RectInvalid);
    Rect.x1 = Rect.x0 + FontSizeY;
    GUI_SetColor(GUI_BLUE);
    GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER, strlen(acText), GUI_ROTATE_CCW);
        GUI_SetColor(GUI_RED);
        temp = 172 - (test_press - drop_limit - press_bottom) / press_factor ;
        GUI_DrawLine(46, temp, 298, temp);
        GUI_SetColor(GUI_BLUE);
        temp = 172 - (test_press - press_bottom) / press_factor;
        GUI_DrawLine(46, temp, 298, temp);
  }
}

/*********************************************************************
*
* Initial Graph setting
*/
void Graph_Init(WM_HWIN hItem, int press, int limit, int duration) {
        press_top = press;
        press_bottom = (press - limit-50)/100*100;
        press_factor = (press_top - press_bottom) / 15 / 10 +1;
        ver_off = press_bottom / press_factor;
        current_press = press;
        _ahData = GRAPH_DATA_YT_Create(_aColor, 250, 0, 0);
        GRAPH_AttachData(hItem, _ahData);

        //
        // Set graph attributes
        //

        GRAPH_SetGridDistY(hItem, 25); //这些函数设置Y从一条网格线到下一网格线的距离。
        GRAPH_SetGridDistX(hItem, 25);
        GRAPH_SetGridVis(hItem, 1); //启用网格绘制。1-可见 0-不可见
        GRAPH_SetGridFixedX(hItem, 1); //这些函数设置X从一条网格线到下一网格线的距离。
        GRAPH_SetUserDraw(hItem, _UserDraw);

        GRAPH_SetBorder(hItem, 45, 5, 5, 5);
        //
        // Create and add vertical scale
        //
        _hScaleV = GRAPH_SCALE_Create(40, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 50);
        GRAPH_SCALE_SetTextColor(_hScaleV, GUI_BLUE);
        GRAPH_AttachScale(hItem, _hScaleV);
        GRAPH_SCALE_SetFactor(_hScaleV, press_factor);
        GRAPH_DATA_YT_SetOffY(_hScaleV, -ver_off);
        //
        // Create and add horizontal scale
        //
        _hScaleH = GRAPH_SCALE_Create(155, GUI_TA_HCENTER, GRAPH_SCALE_CF_HORIZONTAL, 125);
        GRAPH_SCALE_SetTextColor(_hScaleH, GUI_YELLOW);
        GRAPH_AttachScale(hItem, _hScaleH);
        GRAPH_SCALE_SetNumDecs(_hScaleH, 1);
        GRAPH_SCALE_SetFactor(_hScaleH, duration/ 250.0f);
}
/*********************************************************************
*
*       _cbCallback
*
* Function description
*   Callback function of the dialog
*/
static void _cbCallback(WM_MESSAGE * pMsg) {
  unsigned i;
  int      NCode;
  int      Id;
  int      Value;
  WM_HWIN  hDlg;
  WM_HWIN  hItem;

  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
        FRAMEWIN_SetTitleVis(hDlg, 0);
        test_press = 2600;
        drop_limit = 100;
        test_duration = 5;
       
        Graph_Init(hItem, test_press, drop_limit, test_duration);

       
    // Init button widget
    //
    hItem = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0);
    WM_SetStayOnTop(hItem, 1);
       
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);      // Id of widget
    NCode = pMsg->Data.v;                 // Notification code
    switch (NCode) {
    case WM_NOTIFICATION_CLICKED:
      switch (Id) {
      case GUI_ID_BUTTON0:
                  current_press = test_press;
                  counter = 0;
                  GRAPH_DATA_YT_Clear(_ahData);
                  _Stop ^= 1;

        break;
      }
      break;

    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  WM_HWIN hDlg;
  WM_HWIN hGraph,hItem;

  hGraph = 0;
  GUI_Init();
  GUI_CURSOR_Show();
  WM_SetDesktopColor(GUI_BLACK);
  #if GUI_SUPPORT_MEMDEV
    WM_SetCreateFlags(WM_CF_MEMDEV);
  #endif
  hDlg = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbCallback, 0, 0, 0);
  while (1) {
        GUI_Delay(10);
    if (!_Stop) {
             hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
            _AddValues();
                        counter++;
                        hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0);
                        EDIT_SetDecMode(hItem, current_press, 0, 3000, 0, 0);
                        //if (current_press == test_press - drop_limit) _Stop = 1;
                        if (counter == 250) _Stop = !_Stop;
    }
    GUI_Exec();//更新小工具
       
  }
}

/*************************** End of file ****************************/
[/mw_shl_code]

GUISimulationDebug.zip

202.68 KB, 下载次数: 392

最佳答案

查看完整内容[请看2#楼]

解决方案有了,就是创建另一个Array of handles for the GRAPH_DATA objects static GRAPH_DATA_Handle _ahData; // Array of handles for the GRAPH_DATA objects static GRAPH_DATA_Handle _ahData_R; // Array of handles for the GRAPH_DATA objects 可以先画出红线在画测量值
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

25

主题

96

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
297
金钱
297
注册时间
2016-6-2
在线时间
49 小时
 楼主| 发表于 2016-11-3 16:59:23 | 显示全部楼层
解决方案有了,就是创建另一个Array of handles for the GRAPH_DATA objects

static GRAPH_DATA_Handle  _ahData; // Array of handles for the GRAPH_DATA objects
static GRAPH_DATA_Handle  _ahData_R; // Array of handles for the GRAPH_DATA objects

可以先画出红线在画测量值
回复

使用道具 举报

25

主题

96

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
297
金钱
297
注册时间
2016-6-2
在线时间
49 小时
 楼主| 发表于 2016-11-4 17:30:00 | 显示全部楼层
自己顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-23 15:42

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表