How to display the variable value on the screen?
displaying the variable on the screen
This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.
-
-
Andrzej wrote:
How to display the variable value on the screen?
If you need to display some variable with constant refreshing period (for example 200 ms) you can use Timer for it.
Here is a small example that explains the principle:
C Source Code
- WM_HWIN hLabel;
- static void cbWindow(WM_MESSAGE * pMsg) {
- char* str = getValue(); // some getter, that gets stringified value to display
- switch (pMsg->MsgId) {
- case WM_TIMER:
- WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
- TEXT_SetText(hLabel, str); // shows the value
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- WM_HWIN createWindow() {
- WM_HWIN hWindow = WINDOW_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, 0, 0, cbWindow);
- hLabel = TEXT_CreateEx(10, 10, 100, 30, hWindow, WM_CF_SHOW, 0, 0, NULL);
- WM_CreateTimer(hWindow, 0, 0, 0); // create timer for periodical value show
- return hWindow;
- }
Best regards,
Volodymyr.The post was edited 1 time, last by volodymyr ().
-
Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.
-
/*
* myrolster.c
*
* Created on: 04.02.2019
* Author: P
*/
#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_sdram.h"
#include "stm32746g_discovery_ts.h"
#include "GUI.h"
#include "DIALOG.h"
#include "WM.h"
#include "BUTTON.h"
#include "EDIT.h"
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_BUTTON_2 (GUI_ID_USER + 0x03)
#define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
#define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
#define ID_TEXT_0 (GUI_ID_USER + 0xA0)
#define ID_TEXT_1 (GUI_ID_USER + 0xA1)
#define ID_TEXT_2 (GUI_ID_USER + 0xA2)
#define ID_TEXT_3 (GUI_ID_USER + 0xA3)
#define WORK 600
extern int posters;
extern int poster;
extern int showing;
void Stop(void);
void Up(void);
void Down(void);
void Working(void);
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
"down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
"signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
"poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, };
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
WM_HWIN hEdit;
int NCode;
int Id;
static int isButton_0 = 1;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
BUTTON_SetText(hItem, "SETTING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetText(hItem, "UP");
BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
BUTTON_SetText(hItem, "DOWN");
BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
hEdit = SPINBOX_GetEditHandle(hItem);
EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
hEdit = SPINBOX_GetEditHandle(hItem);
EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
SPINBOX_SetStep(hItem, 10);
SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "POSTERS");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "SHOW TIME");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "POSTER");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_D80);
TEXT_SetTextColor(hItem, GUI_RED);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case ID_BUTTON_0:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
if (isButton_0) {
isButton_0 = 0;
BUTTON_SetText(hItem, "SCROLLING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetTextColor(hItem, 0, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
WM_DisableWindow(hItem);
} else {
isButton_0 = 1;
BUTTON_SetText(hItem, "SETTING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
WM_EnableWindow(hItem);
}
break;
case WM_NOTIFICATION_RELEASED:
if (!isButton_0) {
Working();
}
break;
}
break;
case ID_BUTTON_1:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
if (isButton_0) {
Up();
}
break;
case WM_NOTIFICATION_RELEASED:
Stop();
break;
}
break;
case ID_BUTTON_2:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
if (isButton_0) {
Down();
}
break;
case WM_NOTIFICATION_RELEASED:
Stop();
break;
}
break;
case ID_SPINBOX_0:
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
posters = SPINBOX_GetValue(pMsg->hWinSrc);
break;
}
break;
case ID_SPINBOX_1:
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
showing = SPINBOX_GetValue(pMsg->hWinSrc);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
_cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
void MainTask(void);
void MainTask(void) {
GUI_Clear();
CreateWindow();
}The post was edited 1 time, last by Andrzej: /* * myrolster.c * * Created on: 04.02.2019 * Author: P */ #include "stm32746g_discovery.h" #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_sdram.h" #include "stm32746g_discovery_ts.h" #include "GUI.h" #include "DIALOG.h" #include "WM.h" #include "BUTTON.h" #include "EDIT.h" #define ID_WINDOW_0 (GUI_ID_USER + 0x00) #define ID_BUTTON_0 (GUI_ID_USER + 0x01) #define ID_BUTTON_1 (GUI_ID_USER + 0x02) #define ID_BUTTON_2 (GUI_ID_USER + 0x03) #define ID_SPINBOX_0 (GUI_ID_USER + 0x08) #define ID_SPINBOX_1 (GUI_ID_USER + 0x09) #define ID_TEXT_0 (GUI_ID_USER + 0xA0) #define ID_TEXT_1 (GUI_ID_USER + 0xA1) #define ID_TEXT_2 (GUI_ID_USER + 0xA2) #define ID_TEXT_3 (GUI_ID_USER + 0xA3) #define WORK 600 extern int posters; extern int poster; extern int showing; void Stop(void); void Up(void); void Down(void); void Working(void); static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10, 440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up", ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100, 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time", ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter", ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, }; static void _cbDialog(WM_MESSAGE * pMsg) { WM_HWIN hItem; WM_HWIN hEdit; int NCode; int Id; static int isButton_0 = 1; switch (pMsg->MsgId) { case WM_INIT_DIALOG: hItem = pMsg->hWin; WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000)); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII); BUTTON_SetText(hItem, "SETTING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII); BUTTON_SetText(hItem, "UP"); BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII); BUTTON_SetText(hItem, "DOWN"); BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); hEdit = SPINBOX_GetEditHandle(hItem); EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0); EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER); SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER); SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII); SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); hEdit = SPINBOX_GetEditHandle(hItem); EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0); EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER); SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER); SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII); SPINBOX_SetStep(hItem, 10); SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "POSTERS"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "SHOW TIME"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "POSTER"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_D80); TEXT_SetTextColor(hItem, GUI_RED); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case ID_BUTTON_0: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); if (isButton_0) { isButton_0 = 0; BUTTON_SetText(hItem, "SCROLLING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetTextColor(hItem, 0, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); WM_DisableWindow(hItem); } else { isButton_0 = 1; BUTTON_SetText(hItem, "SETTING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetTextColor(hItem, 0, GUI_BLACK); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); WM_EnableWindow(hItem); } break; case WM_NOTIFICATION_RELEASED: if (!isButton_0) { Working(); } break; } break; case ID_BUTTON_1: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); if (isButton_0) { Up(); } break; case WM_NOTIFICATION_RELEASED: Stop(); break; } break; case ID_BUTTON_2: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); if (isButton_0) { Down(); } break; case WM_NOTIFICATION_RELEASED: Stop(); break; } break; case ID_SPINBOX_0: switch (NCode) { case WM_NOTIFICATION_VALUE_CHANGED: posters = SPINBOX_GetValue(pMsg->hWinSrc); break; } break; case ID_SPINBOX_1: switch (NCode) { case WM_NOTIFICATION_VALUE_CHANGED: showing = SPINBOX_GetValue(pMsg->hWinSrc); break; } break; } break; default: WM_DefaultProc(pMsg); break; } } WM_HWIN CreateWindow(void); WM_HWIN CreateWindow(void) { WM_HWIN hWin; hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0); return hWin; } void MainTask(void); void MainTask(void) { GUI_Clear(); CreateWindow(); } ().
-
Andrzej wrote:
Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.
Also I have removed all your dependencies which do not allow compile this code, added at first GUI_Init() (it is always required) and added infinite loop with GUI_Delay().
The core point is adding to the callback the reacting to message WM_TIMER and also start Timer with function WM_CreateTimer(hWin, 0, 0, 0);
Hope it is clear and helpful:
C Source Code
- /*
- * myrolster.c
- *
- * Created on: 04.02.2019
- * Author: P
- */
- #include "GUI.h"
- #include "DIALOG.h"
- #include "WM.h"
- #include "BUTTON.h"
- #include "EDIT.h"
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
- #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
- #define ID_BUTTON_2 (GUI_ID_USER + 0x03)
- #define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
- #define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
- #define ID_TEXT_0 (GUI_ID_USER + 0xA0)
- #define ID_TEXT_1 (GUI_ID_USER + 0xA1)
- #define ID_TEXT_2 (GUI_ID_USER + 0xA2)
- #define ID_TEXT_3 (GUI_ID_USER + 0xA3)
- #define WORK 600
- int posters;
- int getPoster() {
- static int poster;
- return poster++;
- };
- int showing;
- void Stop(void) {};
- void Up(void) {};
- void Down(void) {};
- void Working(void) {};
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
- 0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
- 440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
- ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
- "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
- SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
- 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
- ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
- "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
- TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
- 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
- ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
- "poster", ID_TEXT_3, 170, 75, 100, 100, 0, 0x0, 0 }, };
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- WM_HWIN hEdit;
- int NCode;
- int Id;
- static int isButton_0 = 1;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- hItem = pMsg->hWin;
- WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
- BUTTON_SetText(hItem, "SETTING");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
- BUTTON_SetText(hItem, "UP");
- BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
- BUTTON_SetText(hItem, "DOWN");
- BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
- hEdit = SPINBOX_GetEditHandle(hItem);
- EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
- EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
- SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
- SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
- SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
- hEdit = SPINBOX_GetEditHandle(hItem);
- EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
- EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
- SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
- SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
- SPINBOX_SetStep(hItem, 10);
- SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
- TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
- TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
- TEXT_SetTextColor(hItem, GUI_WHITE);
- TEXT_SetText(hItem, "POSTERS");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
- TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
- TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
- TEXT_SetTextColor(hItem, GUI_WHITE);
- TEXT_SetText(hItem, "SHOW TIME");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
- TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
- TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
- TEXT_SetTextColor(hItem, GUI_WHITE);
- TEXT_SetText(hItem, "POSTER");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
- TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
- TEXT_SetFont(hItem, GUI_FONT_D32);
- TEXT_SetTextColor(hItem, GUI_RED);
- break;
- case WM_TIMER:
- WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
- char str[20];
- sprintf(str, "%d", getPoster());
- TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_3), str); // shows the value
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch (Id) {
- case ID_BUTTON_0:
- switch (NCode) {
- case WM_NOTIFICATION_CLICKED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- if (isButton_0) {
- isButton_0 = 0;
- BUTTON_SetText(hItem, "SCROLLING");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- BUTTON_SetTextColor(hItem, 0, GUI_RED);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- WM_DisableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- WM_DisableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
- WM_DisableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
- WM_DisableWindow(hItem);
- }
- else {
- isButton_0 = 1;
- BUTTON_SetText(hItem, "SETTING");
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- WM_EnableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- WM_EnableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
- WM_EnableWindow(hItem);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
- WM_EnableWindow(hItem);
- }
- break;
- case WM_NOTIFICATION_RELEASED:
- if (!isButton_0) {
- Working();
- }
- break;
- }
- break;
- case ID_BUTTON_1:
- switch (NCode) {
- case WM_NOTIFICATION_CLICKED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- if (isButton_0) {
- Up();
- }
- break;
- case WM_NOTIFICATION_RELEASED:
- Stop();
- break;
- }
- break;
- case ID_BUTTON_2:
- switch (NCode) {
- case WM_NOTIFICATION_CLICKED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- if (isButton_0) {
- Down();
- }
- break;
- case WM_NOTIFICATION_RELEASED:
- Stop();
- break;
- }
- break;
- case ID_SPINBOX_0:
- switch (NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- posters = SPINBOX_GetValue(pMsg->hWinSrc);
- break;
- }
- break;
- case ID_SPINBOX_1:
- switch (NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- showing = SPINBOX_GetValue(pMsg->hWinSrc);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- WM_HWIN CreateWindow(void);
- WM_HWIN CreateWindow(void) {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
- _cbDialog, WM_HBKWIN, 0, 0);
- WM_CreateTimer(hWin, 0, 0, 0);
- return hWin;
- }
- void MainTask(void);
- void MainTask(void) {
- GUI_Init();
- WM_SetBkWindowColor(GUI_GRAY);
- CreateWindow();
- while (1) {
- GUI_Delay(100);
- };
- }
By the way, it is bad practice to work with external variables, much better is to make for all of them some getters (like my function poster(), which should be defined in the c-file, that contains and exports such variables) and publish them via header-file. This principle called encapsulation. You cannot change this variable, only read. And you can control this reading because you have a function instead direct access.
But if you need to change these variables, you write "setters" like:
and then you also have full control in changing of such variables.Best regards,
Volodymyr.The post was edited 5 times, last by volodymyr ().
-
volodymyr wrote:
Andrzej wrote:
How to display the variable value on the screen?
If you need to display some variable with constant refreshing period (for example 200 ms) you can use Timer for it.
Here is a small example that explains the principle:
C Source Code
- WM_HWIN hLabel;
- static void cbWindow(WM_MESSAGE * pMsg) {
- char* str = getValue(); // some getter, that gets stringified value to display
- switch (pMsg->MsgId) {
- case WM_TIMER:
- WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
- TEXT_SetText(hLabel, str); // shows the value
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- WM_HWIN createWindow() {
- WM_HWIN hWindow = WINDOW_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, 0, 0, cbWindow);
- hLabel = TEXT_CreateEx(10, 10, 100, 30, hWindow, WM_CF_SHOW, 0, 0, NULL);
- WM_CreateTimer(hWindow, 0, 0, 0); // create timer for periodical value show
- return hWindow;
- }
Andrzej wrote:
Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.
Andrzej wrote:
/*
* myrolster.c
*
* Created on: 04.02.2019
* Author: P
*/
#include "stm32746g_discovery.h"
#include "stm32746g_discovery_lcd.h"
#include "stm32746g_discovery_sdram.h"
#include "stm32746g_discovery_ts.h"
#include "GUI.h"
#include "DIALOG.h"
#include "WM.h"
#include "BUTTON.h"
#include "EDIT.h"
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_BUTTON_2 (GUI_ID_USER + 0x03)
#define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
#define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
#define ID_TEXT_0 (GUI_ID_USER + 0xA0)
#define ID_TEXT_1 (GUI_ID_USER + 0xA1)
#define ID_TEXT_2 (GUI_ID_USER + 0xA2)
#define ID_TEXT_3 (GUI_ID_USER + 0xA3)
#define WORK 600
extern int posters;
extern int poster;
extern int showing;
void Stop(void);
void Up(void);
void Down(void);
void Working(void);
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
"down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
"signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
"poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, };
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
WM_HWIN hEdit;
int NCode;
int Id;
static int isButton_0 = 1;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
BUTTON_SetText(hItem, "SETTING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
BUTTON_SetText(hItem, "UP");
BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
BUTTON_SetText(hItem, "DOWN");
BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
hEdit = SPINBOX_GetEditHandle(hItem);
EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
hEdit = SPINBOX_GetEditHandle(hItem);
EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
SPINBOX_SetStep(hItem, 10);
SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "POSTERS");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "SHOW TIME");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
TEXT_SetTextColor(hItem, GUI_WHITE);
TEXT_SetText(hItem, "POSTER");
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
TEXT_SetFont(hItem, GUI_FONT_D80);
TEXT_SetTextColor(hItem, GUI_RED);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case ID_BUTTON_0:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
if (isButton_0) {
isButton_0 = 0;
BUTTON_SetText(hItem, "SCROLLING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetTextColor(hItem, 0, GUI_RED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
WM_DisableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
WM_DisableWindow(hItem);
} else {
isButton_0 = 1;
BUTTON_SetText(hItem, "SETTING");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
WM_EnableWindow(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
WM_EnableWindow(hItem);
}
break;
case WM_NOTIFICATION_RELEASED:
if (!isButton_0) {
Working();
}
break;
}
break;
case ID_BUTTON_1:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
if (isButton_0) {
Up();
}
break;
case WM_NOTIFICATION_RELEASED:
Stop();
break;
}
break;
case ID_BUTTON_2:
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
if (isButton_0) {
Down();
}
break;
case WM_NOTIFICATION_RELEASED:
Stop();
break;
}
break;
case ID_SPINBOX_0:
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
posters = SPINBOX_GetValue(pMsg->hWinSrc);
break;
}
break;
case ID_SPINBOX_1:
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
showing = SPINBOX_GetValue(pMsg->hWinSrc);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
_cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
void MainTask(void);
void MainTask(void) {
GUI_Clear();
CreateWindow();
}
-
Andrzej wrote:
Thank you for the changes and comments on the programming style. Now I will check how it goes.
Best regards,
Volodymyr.
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0