Stap 3: Writing een programma buttons.c
buttons.c
De buttons() heet in main voor oneindige lus! Met behulp van GUI_Exec() biedt verblijf in de buttons() functie. Als u wilt maken Voeg meer windows gewoon een globale vlag.
#include <stdio.h>
#include "buttons.h" #include "stm32f429i_discovery.h" #include "WM.h"
/********************************************************************* * * _cbMainWindow * * Callback function of the WELCOME dialog */ static void _cbMainWindow(WM_MESSAGE * pMsg) { WM_HWIN hItem; // Universal handler for all widgets int Id; // Id of source widget int NCode = pMsg -> Data.v; // Code of message WM_HWIN hDlg = pMsg -> hWin;
switch (pMsg->MsgId) { case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON0); // LIGHT ON button BUTTON_SetFont(hItem, GUI_FONT_24_ASCII); // set button text size
hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON1); // LIGHT OFF button BUTTON_SetFont(hItem, GUI_FONT_24_ASCII); // set button text size
FRAMEWIN_SetTitleHeight(hDlg, 30); // set title bar height FRAMEWIN_SetTextColor(hDlg, GUI_DARKRED); // set framewin text color FRAMEWIN_SetFont(hDlg, GUI_FONT_20_ASCII); // set framewin text size FRAMEWIN_SetTextAlign(hDlg, GUI_TA_CENTER); // set framewin text align
WM_SetDesktopColor(GUI_DARKRED); // background color
break;
case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg -> hWinSrc);
schakelaar (Id) {ID_W1_BUTTON0 kast: schakelaar (NCode) {WM_NOTIFICATION_RELEASED kast: //button vrijgegeven reactie {BSP_LED_On(LED3); / / leds op BSP_LED_On(LED4);} switch (Id) { case ID_W1_BUTTON0: switch (NCode) { case WM_NOTIFICATION_RELEASED: //button released reaction { BSP_LED_On(LED3); // leds on BSP_LED_On(LED4); } break; } break; } case ID_W1_BUTTON1: switch (NCode) { case WM_NOTIFICATION_RELEASED: //button released reaction { BSP_LED_Off(LED3); // leds off BSP_LED_Off(LED4); } break; } break; } break;
kast ID_W1_BUTTON1: schakelaar (NCode) {WM_NOTIFICATION_RELEASED kast: //button vrijgegeven reactie {BSP_LED_Off(LED3); / / leds uit BSP_LED_Off(LED4);} default: WM_DefaultProc(pMsg); break; } } } /********************************************************************* * * WelcomeButtons(); * * Main Window of this file */ void Buttons(void) { BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); // create buttons with default skin FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX); // create framewin with default skin GUI_CreateDialogBox(_MainWindow, GUI_COUNTOF(_MainWindow), &_cbMainWindow, WM_HBKWIN, 0, 0); } while (1) { GUI_Exec(); } }
standaard: WM_DefaultProc(pMsg);