Use of Encoder with emWwin

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

    • Use of Encoder with emWwin

      Hello.

      My project using emWin needs to accept inputs from an Encoder and hard key buttons. I have designed a primitive interface using GUI Builder's exported code and its displaying as expected. I need some help with the implementation of the interactions. Here are the basic ones:

      1. Scroll through options on a menu using an encoder.
      2. Select the preferred option by pressing the encoder.
      3. Input values by rotating the encoder and then set the values by pressing the encoder.

      My question is how to focus attention on the specific options for selection and then select it. If possible please suggest a basic example which I can use for the implementation.

      Any help will be very much appreciated.

      Thank you.
    • Hello,

      presumably it is a matter of choosing an appropriate widget and passing WM_KEY message to it.

      1. Scroll through options on a menu using an encoder.
      2. Select the preferred option by pressing the encoder.

      For ex, LISTBOX widget:

      C Source Code: main.c

      1. #include "DIALOG.h"
      2. GUI_ConstString ppItems[5] = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
      3. LISTBOX_Handle hListbox;
      4. // Call this in encoder's handler when rotating CW
      5. void _StoreUpKey(void) {
      6. GUI_StoreKeyMsg(GUI_KEY_UP, 1);
      7. }
      8. // Call this in encoder's handler when rotating CCW
      9. void _StoreDownKey(void) {
      10. GUI_StoreKeyMsg(GUI_KEY_DOWN, 1);
      11. }
      12. // Call this in encoder's handler when pressing
      13. void _StoreEnterKey(void) {
      14. GUI_StoreKeyMsg(GUI_KEY_ENTER, 1);
      15. }
      16. // Call this in encoder's handler when releasing
      17. void _ReleaseEnterKey(void) {
      18. GUI_StoreKeyMsg(GUI_KEY_ENTER, 0);
      19. }
      20. void _cbListbox(WM_MESSAGE * pMsg) {
      21. WM_KEY_INFO * pInfo;
      22. switch (pMsg->MsgId) {
      23. case WM_KEY:
      24. pInfo = (WM_KEY_INFO *)pMsg->Data.p;
      25. if (pInfo->Key == GUI_KEY_ENTER) {
      26. if (pInfo->PressedCnt > 0) {
      27. // Insert reaction on pressing the encoder
      28. }
      29. else {
      30. // Optionally insert reaction on releasing the encoder
      31. }
      32. }
      33. else
      34. LISTBOX_Callback(pMsg); // Default reaction on other keys
      35. break;
      36. default:
      37. LISTBOX_Callback(pMsg);
      38. break;
      39. }
      40. }
      41. void MainTask(void) {
      42. GUI_Init();
      43. WM_MULTIBUF_Enable(1);
      44. WM_SetDesktopColor(GUI_BLACK);
      45. hListbox = LISTBOX_CreateEx(50, 50, 80, 80, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTBOX0, ppItems);
      46. WM_SetCallback(hListbox, _cbListbox);
      47. WM_SetFocus(hListbox);
      48. while (1) {
      49. GUI_Exec();
      50. }
      51. }
      Display All

      3. Input values by rotating the encoder and then set the values by pressing the encoder

      For ex, SPINBOX widget:

      C Source Code: main.c

      1. #include "DIALOG.h"
      2. SPINBOX_Handle hSpinbox;
      3. // Call this in encoder's handler when rotating CW
      4. void _StoreUpKey(void) {
      5. GUI_StoreKeyMsg(GUI_KEY_UP, 1);
      6. }
      7. // Call this in encoder's handler when rotating CCW
      8. void _StoreDownKey(void) {
      9. GUI_StoreKeyMsg(GUI_KEY_DOWN, 1);
      10. }
      11. // Call this in encoder's handler when pressing
      12. void _StoreEnterKey(void) {
      13. GUI_StoreKeyMsg(GUI_KEY_ENTER, 1);
      14. }
      15. // Call this in encoder's handler when releasing
      16. void _ReleaseEnterKey(void) {
      17. GUI_StoreKeyMsg(GUI_KEY_ENTER, 0);
      18. }
      19. void _cbSpinbox(WM_MESSAGE * pMsg) {
      20. WM_KEY_INFO * pInfo;
      21. switch (pMsg->MsgId) {
      22. case WM_KEY:
      23. pInfo = (WM_KEY_INFO *)pMsg->Data.p;
      24. if (pInfo->Key == GUI_KEY_ENTER) {
      25. if (pInfo->PressedCnt > 0) {
      26. // Insert reaction on pressing the encoder
      27. }
      28. else {
      29. // Optionally insert reaction on releasing the encoder
      30. }
      31. }
      32. else
      33. SPINBOX_Callback(pMsg); // Default reaction on other keys
      34. break;
      35. default:
      36. SPINBOX_Callback(pMsg);
      37. break;
      38. }
      39. }
      40. void MainTask(void) {
      41. GUI_Init();
      42. WM_MULTIBUF_Enable(1);
      43. WM_SetDesktopColor(GUI_BLACK);
      44. hSpinbox = SPINBOX_CreateEx(50, 50, 80, 30, WM_HBKWIN, WM_CF_SHOW, GUI_ID_SPINBOX0, 0, 100);
      45. WM_SetCallback(hSpinbox, _cbSpinbox);
      46. WM_SetFocus(hSpinbox);
      47. while (1) {
      48. GUI_Exec();
      49. }
      50. }
      Display All
      Regards,

      Anthony

      The post was edited 6 times, last by cilmagemlu ().