Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork218
Arduino_H7_Video: Adding SEGGER emWin example#788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions.github/workflows/compile-examples.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletionslibraries/Arduino_H7_Video/docs/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
303 changes: 303 additions & 0 deletionslibraries/Arduino_H7_Video/examples/emWinDemo/emWinDemo.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,303 @@ | ||
| /* | ||
| emWinDemo | ||
| created 04 Dec 2023 | ||
| by Leonardo Cavagnis | ||
| */ | ||
| #include "DIALOG.h" /* emWin library includes Arduino_H7_Video and Arduino_GigaDisplayTouch library */ | ||
| /* | ||
| * Main window handler: It creates 4 window childs. | ||
| * Source: https://wiki.segger.com/WM_child_windows_(Sample) | ||
| */ | ||
| static void _cbWin(WM_MESSAGE * pMsg) { | ||
| switch (pMsg->MsgId) { | ||
| case WM_CREATE: | ||
| /* [0, 0] - Image */ | ||
| WM_CreateWindowAsChild(20, 20, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinImg, 0); | ||
| /* [1, 0] - Slider */ | ||
| WM_CreateWindowAsChild(20, 210+20*2, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinSlider, 0); | ||
| /* [0, 1] - Checkbox, button and labels */ | ||
| WM_CreateWindowAsChild(370+20*2, 20, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinChkBtn, 0); | ||
| /* [1, 1] - Progress bar */ | ||
| WM_CreateWindowAsChild(370+20*2, 210+20*2, 370, 210, pMsg->hWin, WM_CF_SHOW, _cbChildWinPgrBar, 0); | ||
| break; | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(0x03989e); /* Background color set to: R(0x03),G(0x98),B(0x9E) */ | ||
| GUI_Clear(); | ||
| break; | ||
| default: | ||
| WM_DefaultProc(pMsg); | ||
| break; | ||
| } | ||
| } | ||
| /* | ||
| * Image window handler | ||
| * To convert image use "Bitmap Converter for emWin" | ||
| * https://www.segger.com/products/user-interface/emwin/tools/tools-overview/ | ||
| */ | ||
| extern GUI_CONST_STORAGE GUI_BITMAP bmarduinologo; /* Image bitmap structure (see img_arduinologo_emwin.c in attach) */ | ||
| static void _cbChildWinImg(WM_MESSAGE * pMsg) { | ||
| switch (pMsg->MsgId) { | ||
| case WM_CREATE: | ||
| break; | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(GUI_WHITE); | ||
| GUI_Clear(); | ||
| /* Draw image */ | ||
| GUI_DrawBitmap(&bmarduinologo, 85, 35); | ||
| break; | ||
| default: | ||
| WM_DefaultProc(pMsg); | ||
| break; | ||
| } | ||
| } | ||
| /* | ||
| * Slider window handler | ||
| * Source: https://wiki.segger.com/SLIDER_-_Usage_(Sample) | ||
| */ | ||
| static void _cbChildWinSlider(WM_MESSAGE * pMsg) { | ||
| static WM_HWIN hSlider; | ||
| int NCode, Id; | ||
| int Value; | ||
| char acBuffer[32]; | ||
| switch(pMsg->MsgId) { | ||
| case WM_CREATE: | ||
| /* Create horizonzal slider */ | ||
| hSlider = SLIDER_CreateEx(110, 90, 150, 30, pMsg->hWin, WM_CF_SHOW, SLIDER_CF_HORIZONTAL, GUI_ID_SLIDER0); | ||
| /* Set range of slider */ | ||
| SLIDER_SetRange(hSlider, 0, 100); | ||
| /* Set number of tick marks */ | ||
| SLIDER_SetNumTicks(hSlider, 10); | ||
| /* Set value of slider */ | ||
| SLIDER_SetValue(hSlider, 20); | ||
| /* Set width of thumb */ | ||
| SLIDER_SetWidth(hSlider, 20); | ||
| break; | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(GUI_WHITE); | ||
| GUI_Clear(); | ||
| GUI_SetFont(&GUI_Font13B_1); | ||
| GUI_SetColor(GUI_BLACK); | ||
| /* Display slider value */ | ||
| Value = SLIDER_GetValue(hSlider); | ||
| sprintf(acBuffer, "Value: %d", Value); | ||
| GUI_DispStringAt(acBuffer, 110, 120); | ||
| break; | ||
| case WM_NOTIFY_PARENT: | ||
| Id = WM_GetId(pMsg->hWinSrc); | ||
| NCode = pMsg->Data.v; | ||
| switch(Id) { | ||
| case GUI_ID_SLIDER0: | ||
| switch(NCode) { | ||
| case WM_NOTIFICATION_VALUE_CHANGED: | ||
| /* Redraw the window when a value has changed so the displayed value will be updated */ | ||
| WM_InvalidateWindow(pMsg->hWin); | ||
| break; | ||
| } | ||
| break; | ||
| } | ||
| break; | ||
| default: | ||
| WM_DefaultProc(pMsg); | ||
| } | ||
| } | ||
| /* | ||
| * Checkbox&Button window handler | ||
| * Source: | ||
| * https://wiki.segger.com/CHECKBOX_-_Usage_(Sample) | ||
| * https://wiki.segger.com/BUTTON_-_Usage_(Sample) | ||
| */ | ||
| #define ID_BUTTON 1 | ||
| static void _cbChildWinChkBtn(WM_MESSAGE * pMsg) { | ||
| static WM_HWIN hBox; | ||
| BUTTON_Handle hButton; | ||
| int NCode, Id; | ||
| char acBuffer[32]; | ||
| int State; | ||
| static int Clicked, Released; | ||
| switch(pMsg->MsgId) { | ||
| case WM_CREATE: | ||
| /* Create CHECKBOX widget */ | ||
| hBox = CHECKBOX_CreateEx(10, 30, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_CHECK0); | ||
| /* Edit widget properties */ | ||
| CHECKBOX_SetText(hBox, "Check"); | ||
| CHECKBOX_SetTextColor(hBox, GUI_BLACK); | ||
| CHECKBOX_SetFont(hBox, &GUI_Font16_1); | ||
| /* Set number of possible states to 3 (if needed). The minimum number of states is 2 and the maximum is 3 */ | ||
| CHECKBOX_SetNumStates(hBox, 3); | ||
| /* Manually set the state */ | ||
| CHECKBOX_SetState(hBox, 1); | ||
| /* Create a button */ | ||
| hButton = BUTTON_CreateEx(10, 100, 80, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_BUTTON); | ||
| BUTTON_SetText(hButton, "Click me"); | ||
| break; | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(GUI_WHITE); | ||
| GUI_Clear(); | ||
| GUI_SetFont(&GUI_Font16_1); | ||
| GUI_SetColor(GUI_BLACK); | ||
| /* Display current CHECKBOX state */ | ||
| State = CHECKBOX_GetState(hBox); | ||
| sprintf(acBuffer, "State of checkbox: %d", State); | ||
| GUI_DispStringAt(acBuffer, 10, 60); | ||
| /* Check button state and print info on labels */ | ||
| if(Clicked) { | ||
| sprintf(acBuffer, "Button was clicked at: %d.", Clicked); | ||
| GUI_DispStringAt(acBuffer, 10, 130); | ||
| } | ||
| if(Released) { | ||
| sprintf(acBuffer, "Button was released at: %d.", Released); | ||
| GUI_DispStringAt(acBuffer, 10, 150); | ||
| } | ||
| break; | ||
| case WM_NOTIFY_PARENT: | ||
| /* Get Id of sender window and notification code */ | ||
| Id = WM_GetId(pMsg->hWinSrc); | ||
| NCode = pMsg->Data.v; | ||
| switch (Id) { | ||
| case GUI_ID_CHECK0: | ||
| switch(NCode) { | ||
| case WM_NOTIFICATION_VALUE_CHANGED: | ||
| /* When the value of the checkbox changed, redraw parent window to update the display of the state */ | ||
| WM_InvalidateWindow(pMsg->hWin); | ||
| break; | ||
| } | ||
| break; | ||
| case ID_BUTTON: | ||
| switch(NCode) { | ||
| case WM_NOTIFICATION_CLICKED: | ||
| Clicked = GUI_GetTime(); | ||
| WM_InvalidateWindow(pMsg->hWin); | ||
| break; | ||
| case WM_NOTIFICATION_RELEASED: | ||
| Released = GUI_GetTime(); | ||
| WM_InvalidateWindow(pMsg->hWin); | ||
| break; | ||
| } | ||
| break; | ||
| break; | ||
| } | ||
| break; | ||
| default: | ||
| WM_DefaultProc(pMsg); | ||
| } | ||
| } | ||
| /* | ||
| * Progress bar window handler | ||
| * Source: https://wiki.segger.com/PROGBAR_-_Custom_(Sample) | ||
| */ | ||
| PROGBAR_Handle hProg; | ||
| static void _cbChildWinPgrBar(WM_MESSAGE * pMsg) { | ||
| GUI_RECT Rect; | ||
| float ValueF; | ||
| int Value; | ||
| char acBuffer[16]; | ||
| switch (pMsg->MsgId) { | ||
| case WM_CREATE: | ||
| hProg = PROGBAR_CreateEx(85, 90, 200, 30, pMsg->hWin, WM_CF_SHOW, PROGBAR_CF_HORIZONTAL, GUI_ID_PROGBAR0); | ||
| WM_SetCallback(hProg, _cbProgbar); | ||
| break; | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(GUI_WHITE); | ||
| GUI_Clear(); | ||
| break; | ||
| default: | ||
| WM_DefaultProc(pMsg); | ||
| break; | ||
| } | ||
| } | ||
| /* | ||
| * Progress bar widget handler | ||
| * Source: https://wiki.segger.com/PROGBAR_-_Custom_(Sample) | ||
| */ | ||
| static void _cbProgbar(WM_MESSAGE * pMsg) { | ||
| GUI_RECT Rect; | ||
| float ValueF; | ||
| int Value; | ||
| char acBuffer[16]; | ||
| switch (pMsg->MsgId) { | ||
| case WM_PAINT: | ||
| GUI_SetBkColor(GUI_WHITE); | ||
| GUI_Clear(); | ||
| /* Draw progress bar */ | ||
| WM_GetClientRect(&Rect); | ||
| GUI_SetColor(GUI_BLACK); | ||
| GUI_AA_DrawRoundedRectEx(&Rect, 3); | ||
| Value = PROGBAR_GetValue(pMsg->hWin); | ||
| ValueF = Value / 100.0F; | ||
| sprintf(acBuffer, "Progress: %d%%", Value); | ||
| Rect.x0 += 2; | ||
| Rect.y0 += 2; | ||
| Rect.x1 -= 2; | ||
| Rect.y1 -= 2; | ||
| Rect.x1 = Rect.x1 * (ValueF); | ||
| GUI_SetColor(GUI_GRAY_9A); | ||
| GUI_AA_FillRoundedRectEx(&Rect, 1); | ||
| WM_GetClientRect(&Rect); | ||
| Rect.x0 += 2; | ||
| Rect.y0 += 2; | ||
| Rect.x1 -= 2; | ||
| Rect.y1 -= 2; | ||
| GUI_SetColor(GUI_BLACK); | ||
| GUI_SetTextMode(GUI_TM_TRANS); | ||
| GUI_SetFont(&GUI_Font16B_1); | ||
| GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER); | ||
| break; | ||
| default: | ||
| PROGBAR_Callback(pMsg); | ||
| break; | ||
| } | ||
| } | ||
| int progbarCnt = 0; | ||
| unsigned long previousMillis = 0; | ||
| void setup() { | ||
| /* Init SEGGER emWin library. It also init display and touch controller */ | ||
| GUI_Init(); | ||
| LCD_ROTATE_SetSel(1); /* Set landscape mode */ | ||
| WM_MULTIBUF_Enable(1); /* Enable multi buffering mode for Windows manager */ | ||
| /* Create the main window. It will include all the sub-windows */ | ||
| WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0); | ||
| } | ||
| void loop() { | ||
| /* Update progress bar value */ | ||
| if (millis() - previousMillis >= 100) { | ||
| previousMillis = millis(); | ||
| progbarCnt++; | ||
| if (progbarCnt > 100) { | ||
| progbarCnt = 0; | ||
| } | ||
| PROGBAR_SetValue(hProg, progbarCnt); | ||
| WM_InvalidateWindow(hProg); /* Make sure the entire PROGBAR gets redrawn */ | ||
| } | ||
| /* Keep emWin alive, handle touch and other stuff */ | ||
| GUI_Exec(); | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.