Tuesday, May 22nd 2018, 3:29pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

jhgorse

Beginner

Date of registration: Jul 9th 2014

Posts: 17

1

Friday, May 4th 2018, 12:11am

GRAPH_DATA_XY not displaying graphs except the first

The first graph displays, but the second graph does not. This can be observed on embedded hardware and the PC.

As I converted this to a test case, the PC version stopped showing secondary graphs. I have not caught that bug yet. In the larger project this had worked on the PC, but not the embedded side.

Here is the code:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
 *
 *   	Defines
 *
 **********************************************************************
 */
#define OutputDebugString(x) printf(x)
#define ID_WINDOW_0  (GUI_ID_USER + 0x00)
#define ID_GRAPH_0   (GUI_ID_USER + 0x01)
#define ID_BUTTON_0  (GUI_ID_USER + 0x02)
#define ID_BUTTON_1  (GUI_ID_USER + 0x03)

#define Y_SCALE_MAX     113.0   // So that 100 is the highest Y scale bar number displayed
#define Y_SCALE_MIN     0
#define VSCROLL_OFFY    10
#define GY              (340)
#define GRAPH_PIXELS_Y  GY     // Delta-Y of our chart area
#define Y_SCALE_FACTOR ((float)(Y_SCALE_MAX-(Y_SCALE_MIN))/GRAPH_PIXELS_Y)

#define GX              (740)
#define GRAPH_PIXELS_X  GX      // Widget pixels
#define GXp             (GX - 5)  // Usable graph pixels
#define GXLO            15      // X left offset pixels
#define GXRO            15      // X rigt offset pixels

#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_TEXT_0       (GUI_ID_USER + 0x23)
#define ID_GRAPH_0      (GUI_ID_USER + 0x24)
#define ID_BUTTON_3     (GUI_ID_USER + 0x25)
#define ID_BUTTON_4     (GUI_ID_USER + 0x27)

#define PREPOPULATED_DATA_POINTS (MAXSTRIPINDEX/5)
#define MAX_GRAPHS	2

/*********************************************************************
 *
 *   	Static data
 *
 **********************************************************************
 */
static GRAPH_DATA_Handle _ahData[MAX_GRAPHS];	// 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 GUI_POINT _aPoint[MAX_GRAPHS];

static I16 _aValue[MAX_GRAPHS];
static int _Stop = 0;

// Array of colors for the GRAPH_DATA objects
static GUI_COLOR _aColor[] = {
    GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_ORANGE,
    GUI_GREEN, GUI_GREEN, GUI_RED, GUI_RED,
    GUI_LIGHTBLUE, GUI_LIGHTBLUE };

static U8 _aLineStyles[] = {
    GUI_LS_SOLID, GUI_LS_SOLID, GUI_LS_SOLID, GUI_LS_DASH,
    GUI_LS_SOLID, GUI_LS_DASH, GUI_LS_SOLID, GUI_LS_DASH,
    GUI_LS_SOLID, GUI_LS_DASH };

/*********************************************************************
 *
 *   	_aDialogCreate
 */
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { {
  WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 780, 440, 0, 0x0, 0 }, {
	GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 20, 80, GX, GY, 0, 0x0, 0 }, {
	BUTTON_CreateIndirect, "Right", ID_BUTTON_0, 760, 80, 20, GY, 0, 0x0, 0 }, {
	BUTTON_CreateIndirect, "Left", ID_BUTTON_1, 0, 80, 20, GY, 0, 0x0, 0 }, };

/*********************************************************************
 *
 *   	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) {
  static unsigned data_time = 0;
  unsigned i = 0;
  GUI_POINT pt;

  pt.x = data_time;

  for (int i = 0; i < MAX_GRAPHS; i++) {
    pt.y = i * 20 + rand() % 50 / Y_SCALE_FACTOR;
    GRAPH_DATA_XY_AddPoint(_ahData[i], &pt);
  }
  data_time++;
}

/*********************************************************************
 *
 *   	_cbDialog
 */
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  WM_HWIN hDlg;
  static GRAPH_DATA_Handle hGraphData;
  int NCode;
  int Id;
  static int DataAttached;
  unsigned i;

  hDlg = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Window'
    //
    hItem = pMsg->hWin;
    WINDOW_SetBkColor(hItem, GUI_GRAY);
    //
    // Initialize the GRAPH widget
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);

    for (i = 0; i < MAX_GRAPHS; i++) {
      _ahData[i] = GRAPH_DATA_XY_Create(_aColor[i], 2000, 0, 0);
      GRAPH_AttachData(hItem, _ahData[i]);
      GRAPH_DATA_XY_SetLineStyle(_ahData[i], _aLineStyles[i]);
      GRAPH_DATA_XY_SetOffY(_ahData[i], 10 / Y_SCALE_FACTOR);
    }

    GRAPH_SetVSizeY(hItem, 120);
    GRAPH_SetGridVis(hItem, 1);
    WIDGET_SetEffect(hItem, &WIDGET_Effect_3D);
    //
    // Create and add vertical scale
    //
    _hScaleV = GRAPH_SCALE_Create(5, GUI_TA_LEFT | GUI_TA_BOTTOM,
        GRAPH_SCALE_CF_VERTICAL, 10 / Y_SCALE_FACTOR);
    GRAPH_SCALE_SetTextColor(_hScaleV, GUI_YELLOW);
    GRAPH_AttachScale(hItem, _hScaleV);
    GRAPH_SetGridDistY(hItem, 10 / Y_SCALE_FACTOR);
    GRAPH_SCALE_SetFactor(_hScaleV, Y_SCALE_FACTOR);
    GRAPH_SCALE_SetOff(_hScaleV,
        -(Y_SCALE_MIN / Y_SCALE_FACTOR) + VSCROLL_OFFY + 5);

    //
    // Create and add horizontal scale
    //
    _hScaleH = GRAPH_SCALE_Create(320, GUI_TA_RIGHT, GRAPH_SCALE_CF_HORIZONTAL,
        60);
    GRAPH_SCALE_SetTextColor(_hScaleH, GUI_DARKGREEN);
    GRAPH_AttachScale(hItem, _hScaleH);
    GRAPH_SetGridDistX(hItem, 60);
    GRAPH_SCALE_SetTickDist(_hScaleH, 60);

    break;
  case WM_NOTIFY_PARENT:
    Id = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (Id) {
    case ID_BUTTON_0: // Notifications sent by 'Right'
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      }
      break;
      case ID_BUTTON_1: // Notifications sent by 'Left'
        switch (NCode) {
        case WM_NOTIFICATION_CLICKED:
          break;
        case WM_NOTIFICATION_RELEASED:
          break;
        }
        break;
    }
    break;
    default:
      WM_DefaultProc(pMsg);
      break;
  }
}

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

  hGraph = 0;
  WM_SetCreateFlags(WM_CF_MEMDEV);
  GUI_Init();
  hDlg = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
      _cbDialog, WM_HBKWIN, 0, 0);
  GUI_Delay(50);
  for (int i = 0; i < 20; i++) // PREPOPULATED_DATA_POINTS
    _AddValues();

  while (1) {
    GUI_Delay(500);
    if (!_Stop) {
      if (!hGraph) {
        hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0);
      }
      _AddValues();
    }
  }
}

/*************************** End of file ****************************/

jhgorse

Beginner

Date of registration: Jul 9th 2014

Posts: 17

2

Friday, May 4th 2018, 12:26am

It is actually working. My color scheme has the same color for the first two graphs, so I did not see it. Cheers.