Knob issue

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Hello all,

    I am new to emWin so i have my first issues with an application that i am trying to develop.
    In my main window I want to use a knob widget to select one of the next windows that i want to open.
    In the main window i use one 480x272 image as background and the know image 154x154, they are defined in different c files as

    Source Code

    1. #include #include "GUI.h"#ifndef GUI_CONST_STORAGE #define GUI_CONST_STORAGE const#endifstatic GUI_CONST_STORAGE unsigned long _acBackGround[] = {....};GUI_CONST_STORAGE GUI_BITMAP bmBackGround = { 480, 272, 1920, 32, (unsigned char *)_acBackGround, NULL, GUI_DRAW_BMP8888};static GUI_CONST_STORAGE unsigned long _acKnob[] = {...};GUI_CONST_STORAGE GUI_BITMAP bmKnob = { 154, 154, 616, 32, (unsigned char *)_acKnob, NULL, GUI_DRAW_BMP8888};



    In the attached image you can see that the know has some rendering issues that i am not able (don't know how) to fix them and this is the reason i am asking here for help and ideas.

    Source Code

    1. #include "MainScreen.h"#include "DIALOG.h"#include "myResources.h"#include
    2. #define IcoSize 32#define BtnSize 40#define AMP_COLOR_BLUE 0x0237e1#define AMP_COLOR_GRAY 0xFF4D4B4C#define KNOB_X 163#define KNOB_Y 85#define FONT_EXPLANATION &GUI_Fontlcdphone13char myStr[10];static const GUI_BITMAP * _bntIco[] = {&bmScreenOff, &bmXBee, &bmPlay};typedef struct BITMAP_ITEM BITMAP_ITEM;struct BITMAP_ITEM{ const GUI_BITMAP * pBitmap; const char * pText; U16 xPos; U8 yPos; U16 imgId;};static const BITMAP_ITEM _aBitmapItem[] = { {&bmHand, "MANUAL", 115, 207, ID_Hand}, {&bmBulb, "BULB", 102, 172, ID_Bulb}, {&bmTimeLapse, "TIME LAPSE", 99, 135, ID_TimeLapse}, {&bmHDR, "HDR", 108, 99, ID_Hdr}, {&bmIR, "IR", 127, 67, ID_Ir}, {&bmTriggrered, "TRIGGERED", 154, 42, ID_Triggrered}, {&bmDarkRoom, "DARK ROOM", 187, 26, ID_DarkRoom}, {&bmLightning, "LIGHTINING", 224, 21, ID_Lightning}, {&bmBullet, "BULLET", 261, 26, ID_Bullet}, {&bmDrops, "DROPTLETS", 294, 42, ID_Drops}, {&bmPanManual, "MANUAL P&T", 321, 67, ID_ManualPT}, {&bmPanAuto, "AUTO P&T", 340, 99, ID_AutoPT}, {&bmStarTracker, "STAR TRACKER", 349, 135, ID_StarTracker}, {&bmUSB, "USB", 346, 172,ID_USB}, {&bmSettings, "SETTINGS", 333, 207, ID_Settings},};typedef struct Coord Coord;struct Coord { U16 xPos; U8 yPos;};static const Coord _LedPos[] = {{156, 201},{147, 176},{145, 149},{152, 123},{165, 100},{185, 82},{209, 71},{235, 67},{261, 71},{285, 82},{305, 100},{318, 123},{325, 149},{323, 176},{314, 201},};static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { WINDOW_CreateIndirect, "", ID_WINDOW_0, 0, 0, 480, 272, WM_CF_SHOW | WM_CF_MEMDEV, 0, 0 }, { KNOB_CreateIndirect, "", GUI_ID_KNOB0, 163, 85, 154, 154, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Hand, 115, 207, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Bulb, 102, 172, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_TimeLapse, 99, 135, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Hdr, 108, 99, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Ir, 127, 67, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Triggrered, 154, 42, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_DarkRoom, 187, 26, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Lightning, 224, 21, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Bullet, 261, 26, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Drops, 294, 42, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_ManualPT, 321, 67, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_AutoPT, 340, 99, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_StarTracker,349, 135, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_USB, 346, 172, IcoSize, IcoSize, WM_CF_SHOW }, { IMAGE_CreateIndirect, "", ID_Settings, 333, 207, IcoSize, IcoSize, WM_CF_SHOW }, { BUTTON_CreateIndirect, "", ID_BUTTON_0, 10, 230, BtnSize, BtnSize, WM_CF_SHOW }, { BUTTON_CreateIndirect, "", ID_BUTTON_1, 80, 230, BtnSize, BtnSize, WM_CF_SHOW }, { BUTTON_CreateIndirect, "", ID_BUTTON_2, 400, 230, BtnSize, BtnSize, WM_CF_SHOW }, { TEXT_CreateIndirect, "", ID_TEXT_0, 200, 240, 120, 20, WM_CF_SHOW }, };static void _DrawScale(KNOB_Handle hKnob, TEXT_Handle hText){ U8 Value; Value = 14 - (KNOB_GetValue(hKnob) / 170); TEXT_SetText(hText, _aBitmapItem[Value].pText); GUI_DrawBitmap(&bmLED, _LedPos[Value].xPos, _LedPos[Value].yPos);}static void _DrawKnob(GUI_MEMDEV_Handle hMem) { int xSizeMem, ySizeMem;
    3. xSizeMem = GUI_MEMDEV_GetXSize(hMem); ySizeMem = GUI_MEMDEV_GetYSize(hMem); GUI_AA_PreserveTrans(1); GUI_MEMDEV_Select(hMem); GUI_SetBkColor(GUI_TRANSPARENT); GUI_Clear(); GUI_SetPenSize(3); GUI_SetColor(AMP_COLOR_BLUE); GUI_AA_DrawLine(xSizeMem / 2 + 10, ySizeMem / 2, xSizeMem / 2 + xSizeMem / 3, ySizeMem / 2); GUI_SetPenSize(1); GUI_MEMDEV_Select(0); GUI_AA_PreserveTrans(0);}static void _cbDialog(WM_MESSAGE * pMsg) { static GUI_MEMDEV_Handle hMemKnob; WM_HWIN hParent; WM_HWIN hWin; GUI_RECT Rect; BUTTON_Handle hButton; KNOB_Handle hKnob; IMAGE_Handle hImage; TEXT_Handle hText; int Id, NCode; U8 i, ImgCount; ImgCount = GUI_COUNTOF(_aBitmapItem); hWin = pMsg->hWin; switch (pMsg->MsgId) { case WM_INIT_DIALOG: // Create and fill memory devices hMemKnob = GUI_MEMDEV_CreateFixed32(0, 0, 140, 20); //_DrawKnob(hMemKnob); // Init KNOB hKnob = WM_GetDialogItem(hWin, GUI_ID_KNOB0); KNOB_SetDevice(hKnob, hMemKnob); KNOB_SetBkColor(hKnob, GUI_TRANSPARENT); KNOB_SetRange(hKnob, 0, 14); KNOB_SetOffset(hKnob, 14); KNOB_SetTickSize(hKnob, 170); KNOB_SetPeriod(hKnob, 50); KNOB_SetPos(hKnob, 14); // Initialization Buttons for (i = 0; i < 3; i++) { hButton = WM_GetDialogItem(hWin, ID_BUTTON_0 + i); BUTTON_SetBitmapEx(hButton, BUTTON_BI_UNPRESSED, _bntIco[i], 4, 4); } // Initialization Icons for (i = 0; i < ImgCount; i++) { hImage = WM_GetDialogItem(hWin, _aBitmapItem[i].imgId); IMAGE_SetBitmap(hImage, _aBitmapItem[i].pBitmap); } // Initialization text hText = WM_GetDialogItem(hWin, ID_TEXT_0); GUI_SetTextMode(GUI_TM_TRANS); TEXT_SetFont(hText, FONT_EXPLANATION); TEXT_SetDefaultTextColor(AMP_COLOR_BLUE); break; case WM_PAINT: //draw background GUI_DrawBitmap(&bmBackGround, 0, 0); GUI_DrawBitmap(&bmKnob, 163, 85); //draw LED _DrawScale(WM_GetDialogItem(hWin, GUI_ID_KNOB0), WM_GetDialogItem(hWin, ID_TEXT_0)); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch(Id) { case GUI_ID_KNOB0: switch(NCode) { case WM_NOTIFICATION_VALUE_CHANGED: hKnob = WM_GetDialogItem(hWin, Id); WM_GetWindowRectEx(hKnob, &Rect); Rect.x0 = 150; Rect.y0 = 50; Rect.x1 = 360; Rect.y1 = 272; hParent = WM_GetParent(hKnob); WM_InvalidateRect(hParent, &Rect); break; } break; case ID_BUTTON_0: switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: break; } break; case ID_BUTTON_1: switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: break; } break; case ID_BUTTON_2: switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: break; } break; } case WM_NOTIFICATION_RELEASED: switch (Id) { case ID_BUTTON_0: hButton = WM_GetDialogItem(hWin, Id); break; case ID_BUTTON_1: hButton = WM_GetDialogItem(hWin, Id); break; case ID_BUTTON_2: hButton = WM_GetDialogItem(hWin, Id); break; } break; default: WM_DefaultProc(pMsg); break; }}static void myMainMenu(void){ GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);}void MainTask(void){ myMainMenu();}


    The second issue is that i cant find any example on how to:
    - create an new window based on the selection from the main screen
    - on the new window if i press a button i want to close it and go back to main window.

    I did found examples with virtual screens and frames and use them. I have managed to create the new window, close it using GUI_EndDialog, but once i get back to the main window the widgets are not responding.

    Thank you.
    Images
    • Knob.JPG

      177.38 kB, 1,214×762, viewed 751 times
  • Hi,

    Not sure what causes these effects on the screen. Did you made sure that the back ground of the memory device set for the knob has been cleared with transparency. Like

    C Source Code

    1. GUI_MEMDEV_Select(hMemKnob);
    2. GUI_SetBkColor(GUI_TRANSPARENT);
    3. GUI_Clear();


    Attached is an example which looks good on my end. Please give it a try.

    This sample also shows how to determin which item is selected and how to create a window and how to delete it.

    Regards,
    Sven
    Files
    • KnobExample.zip

      (289.2 kB, downloaded 533 times, last: )
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi,
    Thank you for the quick reply. I have tested the solution from attachment but dosent work as expected.

    The knob has flicker on it when moving, when opening and closing the windows it gets stuck after 3 tries

    For the know to work i have used the following

    Source Code

    1. { KNOB_CreateIndirect,"", GUI_ID_KNOB0,163,85,944,94, WM_CF_SHOW }

    Source Code

    1. switch (pMsg->MsgId) { case WM_INIT_DIALOG: // Create and fill memory devices //hMemKnob = GUI_MEMDEV_CreateFixed32(0, 0, 140, 20); //_DrawKnob(hMemKnob); // Init KNOB hKnob = WM_GetDialogItem(hWin, GUI_ID_KNOB0); KNOB_SetDevice(hKnob, hMemKnob); KNOB_SetBkColor(hKnob, GUI_TRANSPARENT); KNOB_SetRange(hKnob, 0, 14); KNOB_SetOffset(hKnob, 14); KNOB_SetTickSize(hKnob, 170); KNOB_SetPeriod(hKnob, 50); KNOB_SetPos(hKnob, 14); // Initialization Buttons for (i = 0; i < 3; i++) { hButton = WM_GetDialogItem(hWin, ID_BUTTON_0 + i); BUTTON_SetBitmapEx(hButton, BUTTON_BI_UNPRESSED, _bntIco[i], 4, 4); } // Initialization Icons for (i = 0; i < ImgCount; i++) { hImage = WM_GetDialogItem(hWin, _aBitmapItem[i].imgId); IMAGE_SetBitmap(hImage, _aBitmapItem[i].pBitmap); } // Initialization text hText = WM_GetDialogItem(hWin, ID_TEXT_0); GUI_SetTextMode(GUI_TM_TRANS); TEXT_SetFont(hText, FONT_EXPLANATION); TEXT_SetDefaultTextColor(AMP_COLOR_BLUE); break; case WM_PAINT: //draw background GUI_DrawBitmap(&bmBackGround, 0, 0); GUI_DrawBitmap(&bmKnob, 163, 85); //draw LED _DrawScale(WM_GetDialogItem(hWin, GUI_ID_KNOB0), WM_GetDialogItem(hWin, ID_TEXT_0));
    2. static void _DrawScale(KNOB_Handle hKnob, TEXT_Handle hText){ U8 Value; Value = 14 - (KNOB_GetValue(hKnob) / 170); TEXT_SetText(hText, _aBitmapItem[Value].pText); GUI_DrawBitmap(&bmLED, _LedPos[Value].xPos, _LedPos[Value].yPos);}


    So i have a smaller size knob and a small image to show the position.

    The only issue remaining is the limited number of cycles to open new window.
    This is a big problem because in my application i intend to open 17 secondary windows from the main window, each having several controls on it.

    I forgot to add in the previous post that i am using an STM32F746G DISCOVERY board with the setting
    LCDConf.c

    Source Code

    1. #define NUM_BUFFERS 2
    2. #define GUI_NUM_LAYERS 1
    3. #define VRAM_ADDR 0xC0000000
    4. #define DMA2D_BUFFER_ADDR 0x20000000
    5. #define COLOR_MODE_0 COLOR_MODE_RGB888
    6. #define COLOR_MODE_1 COLOR_MODE_RGB888



    and GUIConf.c

    Source Code

    1. #define GUI_NUMBYTES 0x38000
    2. void GUI_X_Config(void) { // // 32 bit aligned memory area // static U32 aMemory[GUI_NUMBYTES / 4]; // // Assign memory to emWin // GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES); // // Set default font // GUI_SetDefaultFont(GUI_FONT_6X8);}