임베디드 보드/STM32

버튼을 이용하여 LED 밝기 제어 degined by STemWin

ZEROWIN.TECH 2020. 7. 21. 14:39
728x90

STemWin GUIBUILDER 프로그램을 이용하여 GUI 디자인을 합니다.

GUIBUILDER을 이용하여 디자인한 화면을 STM32H7 보드에 적용합니다.

 

프로그래밍

 

GUIBuilder를 이용하여 생성한 FramwinDLG.c 파일입니다.

위젯에 대한 정의를 포함합니다.

 

/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.32                          *
*        Compiled Oct  8 2015, 11:59:02                              *
*        (c) 2015 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END

#include "DIALOG.h"
#include "gpio.h"



/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0        (GUI_ID_USER + 0x00)
#define ID_BUTTON_0        (GUI_ID_USER + 0x01)
#define ID_BUTTON_1        (GUI_ID_USER + 0x02)
#define ID_SLIDER_0        (GUI_ID_USER + 0x03)
#define ID_TEXT_0        (GUI_ID_USER + 0x04)
#define ID_TEXT_1        (GUI_ID_USER + 0x05)
#define ID_CHECKBOX_0        (GUI_ID_USER + 0x06)
#define ID_BUTTON_2        (GUI_ID_USER + 0x07)


// USER START (Optionally insert additional defines)
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 12, 12, 1024, 600, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "LED_1 ON", ID_BUTTON_0, 69, 160, 240, 80, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "LED_2 OFF", ID_BUTTON_1, 321, 160, 240, 80, 0, 0x0, 0 },
  { SLIDER_CreateIndirect, "Slider", ID_SLIDER_0, 196, 52, 574, 50, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "STEPPING MOTOR", ID_TEXT_0, 24, 67, 190, 42, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_1, 819, 75, 80, 20, 0, 0x64, 0 },
  { CHECKBOX_CreateIndirect, "CHECK_LED_2", ID_CHECKBOX_0, 77, 271, 160, 40, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_2, 0, 0, 80, 20, 0, 0x0, 0 },
  // USER START (Optionally insert additional widgets)
  // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       FRAMEWIN_OnValueChanged
*/
static void FRAMEWIN_OnValueChanged(WM_HWIN hDlg, int Id) {
  WM_HWIN hItem;
  int Value;
  hItem = WM_GetDialogItem(hDlg, Id);
  
  switch (Id) {
  case ID_SLIDER_0:

	Value = SLIDER_GetValue(hItem);
	printf("ID_SLIDER_0 # FRAMEWIN_OnValueChanged %d\r\n", Value);

	  	WM_HWIN hItemT;
 		hItemT = WM_GetDialogItem(hDlg, ID_TEXT_1);
		char temp[8] = { 0x00, };
		sprintf(temp, "%d", Value);
		TEXT_SetText(hItemT, temp);
		
    break;

	case ID_CHECKBOX_0:
		Value = CHECKBOX_IsChecked(hItem);
		printf("ID_CHECKBOX_0 # FRAMEWIN_OnValueChanged %d\r\n", Value);

		if(Value == 1) HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);
		else  HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_RESET);
	break;
  }
}

// USER START (Optionally insert additional static code)
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  int NCode;
  int Id;
  
  
  // USER START (Optionally insert additional variables)
  WM_HWIN hDlg;
  WM_HWIN hItem;
  // USER END

	hDlg = pMsg->hWin;
  
  switch (pMsg->MsgId) {
 case WM_INIT_DIALOG:
    //
    // Initialization of 'LED_1 ON'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetFont(hItem, GUI_FONT_20_1);
    //
    // Initialization of 'LED_2 OFF'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    BUTTON_SetFont(hItem, GUI_FONT_20_1);
    //
    // Initialization of 'STEPPING MOTOR'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetFont(hItem, GUI_FONT_20_1);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00FF0000));
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
    TEXT_SetText(hItem, "Text");
    TEXT_SetFont(hItem, GUI_FONT_20_1);
    TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x000000FF));
    //
    // Initialization of 'CHECK_LED_2'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
    CHECKBOX_SetText(hItem, "LED_2 Toggle");
    CHECKBOX_SetFont(hItem, GUI_FONT_20_1);
    CHECKBOX_SetTextColor(hItem, GUI_MAKE_COLOR(0x0000FF00));
    // USER START (Optionally insert additional code for further widget initialization)
    // USER END
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_BUTTON_0: // Notifications sent by 'START'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_BUTTON_0 - WM_NOTIFICATION_CLICKED\r\n");
		HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_SET);//LED1 ON
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_BUTTON_0 - WM_NOTIFICATION_RELEASED\r\n");
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case ID_BUTTON_1: // Notifications sent by 'STOP'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_BUTTON_1 - WM_NOTIFICATION_CLICKED\r\n");
		HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, GPIO_PIN_RESET);//LED1 ON
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_BUTTON_1 - WM_NOTIFICATION_RELEASED\r\n");
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case ID_SLIDER_0: // Notifications sent by 'Slider'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_SLIDER_0 - WM_NOTIFICATION_CLICKED\r\n");
        // USER END
        break;
      case WM_NOTIFICATION_RELEASED:
        // 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)
        printf("ID_SLIDER_0 - WM_NOTIFICATION_VALUE_CHANGED\r\n");
		FRAMEWIN_OnValueChanged(hDlg, Id);
        // USER END
        break;
      // USER START (Optionally insert additional code for further notification handling)
      // USER END
      }
      break;
    case ID_CHECKBOX_0: // Notifications sent by 'CHECK_LED_2'
      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_VALUE_CHANGED:
        // USER START (Optionally insert code for reacting on notification message)
        printf("ID_CHECKBOX_0 - WM_NOTIFICATION_VALUE_CHANGED\r\n");
		FRAMEWIN_OnValueChanged(hDlg, Id);
        // 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)
        // 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)
  // USER END
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateFramewin
*/
WM_HWIN CreateFramewin(void);
WM_HWIN CreateFramewin(void) {
  WM_HWIN hWin;

  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}

void TEST_MainTask()
{
	while(1)
	{
		GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
		GUI_Delay(10);
		GUI_Exec();
	}
}

// USER START (Optionally insert additional public code)
// USER END

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

 

 

 

테스트영상

 

주요내용은 윗글에 포함되어 있습니다.

부득이하게 설명이나 소스코드가 필요하면 구입부탁드립니다.

https://smartstore.naver.com/taklive/products/5025381977

 

STM32H7 버튼을 이용하여 LED 밝기 제어 degined by STemWin : 제로윈마트

[제로윈마트] 제로윈텍 쇼핑몰

smartstore.naver.com

 

'임베디드 보드 > STM32' 카테고리의 다른 글

STM32F4 LED Pinmap  (0) 2020.09.15
Servo Motor PWM 제어  (0) 2020.08.31
STemWin  (0) 2020.07.20
STM32H7 스테핑모터 & JOYSTICK 키 제어  (0) 2020.07.20
STM32H7 JOYSTICK KEY 테스트  (0) 2020.07.18