When to call LISTWHEEL_SetVelocity()

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

    • When to call LISTWHEEL_SetVelocity()

      Hello,

      I'm working on trying to get a time/date picker working with STeMWIN, I have a basic screen working however movement of the various wheels is something I've not quite grasped yet. Currently each list wheel has it's own callback:

      Source Code

      1. static void
      2. CbListWheel (WM_MESSAGE *pMsg)
      3. {
      4. switch (pMsg->MsgId)
      5. {
      6. //**********************************************************************
      7. // WM_PID_STATE_CHANGED
      8. case WM_PID_STATE_CHANGED:
      9. {
      10. // React on pressing data areas
      11. LISTWHEEL_SetVelocity(pMsg->hWin, LISTWHEEL_VELOCITY);
      12. break;
      13. }
      14. //**********************************************************************
      15. // Default handling.
      16. default:
      17. {
      18. LISTWHEEL_Callback(pMsg);
      19. break;
      20. }
      21. }
      22. }
      23. /******************************************************************************/
      Display All


      When I touch on the wheel it moves, however it only moves in 1 direction. I'm wondering how (if?) I control the direction of movement with listwheels? The example code looks like this:


      Source Code

      1. case WM_PID_STATE_CHANGED:
      2. //
      3. // React on pressing data areas
      4. //
      5. pState = (const WM_PID_STATE_CHANGED_INFO *)pMsg->Data.p;
      6. if ((pState->StatePrev == 0) && (pState->State == 1)) {
      7. x = pState->x;
      8. y = pState->y;
      9. if ((x >= 10) && (x <= 230)) {
      10. for (j = 0; j < 2; j++) {
      11. if ((y >= (75 + j * 40)) && (y < 75 + (j + 1) * 40)) {
      12. if (Selection != j) {
      13. Selection = j;
      14. for (i = 0; i < 3; i++) {
      15. LISTWHEEL_MoveToPos(_aWheel[i].hWin, _aSelection[Selection][i]);
      16. }
      17. WM_InvalidateWindow(pMsg->hWin);
      18. }
      19. }
      20. }
      21. }
      22. }
      23. break;
      Display All
      Which sadly I am struggling to understand - I suspect this is trying to find the list wheel selection at given screen coordinates. However this would surely just move the wheel there, rather than enable a smooth scroll to a new selection.

      All in all I'm a little confused about this widget and would like some pointing in the right direction.

      Thanks,
      Peter.
    • Hi,

      To move the LISTWHEEL to the other direction simply make the value negative.

      LISTWHEEL_SetVelocity(pMsg->hWin, -LISTWHEEL_VELOCITY);

      If I get you right you want to move the LISTWHEEL to the item under the position you have clicked, right?

      Maybe like this:

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Defines
      12. *
      13. **********************************************************************
      14. */
      15. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      16. #define ID_LISTWHEEL_0 (GUI_ID_USER + 0x01)
      17. /*********************************************************************
      18. *
      19. * Static data
      20. *
      21. **********************************************************************
      22. */
      23. /*********************************************************************
      24. *
      25. * _aDialogCreate
      26. */
      27. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      28. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
      29. { LISTWHEEL_CreateIndirect, "Listwheel", ID_LISTWHEEL_0, 25, 25, 160, 200, 0, 0x0, 0 },
      30. };
      31. /*********************************************************************
      32. *
      33. * Static code
      34. *
      35. **********************************************************************
      36. */
      37. /*********************************************************************
      38. *
      39. * _cbDialog
      40. */
      41. static void _cbDialog(WM_MESSAGE * pMsg) {
      42. WM_HWIN hItem;
      43. int NCode;
      44. int Id;
      45. char acBuffer[32];
      46. int i;
      47. int Sel;
      48. GUI_PID_STATE State;
      49. int Item;
      50. int yPos;
      51. int SnapPos;
      52. switch (pMsg->MsgId) {
      53. case WM_INIT_DIALOG:
      54. //
      55. // Initialization of 'Listwheel'
      56. //
      57. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
      58. for (i = 0; i < 30; i++) {
      59. sprintf(acBuffer, "Item %i", i);
      60. LISTWHEEL_AddString(hItem, acBuffer);
      61. }
      62. SnapPos = (WM_GetWindowSizeY(hItem) - LISTWHEEL_GetLineHeight(hItem)) / 2;
      63. LISTWHEEL_SetSnapPosition(hItem, SnapPos);
      64. LISTWHEEL_SetDeceleration(hItem, 5);
      65. break;
      66. case WM_NOTIFY_PARENT:
      67. Id = WM_GetId(pMsg->hWinSrc);
      68. NCode = pMsg->Data.v;
      69. switch(Id) {
      70. case ID_LISTWHEEL_0: // Notifications sent by 'Listwheel'
      71. switch(NCode) {
      72. case WM_NOTIFICATION_CLICKED:
      73. break;
      74. case WM_NOTIFICATION_RELEASED:
      75. if (!LISTWHEEL_IsMoving(pMsg->hWinSrc)) {
      76. GUI_PID_GetCurrentState(&State);
      77. yPos = State.y - (WM_GetWindowOrgY(pMsg->hWinSrc) - WM_GetWindowOrgY(pMsg->hWin));
      78. Item = LISTWHEEL_GetItemFromPos(pMsg->hWinSrc, yPos);
      79. LISTWHEEL_SetSel(pMsg->hWinSrc, Item);
      80. LISTWHEEL_MoveToPos(pMsg->hWinSrc, Item);
      81. }
      82. break;
      83. case WM_NOTIFICATION_SEL_CHANGED:
      84. break;
      85. }
      86. break;
      87. }
      88. break;
      89. default:
      90. WM_DefaultProc(pMsg);
      91. break;
      92. }
      93. }
      94. /*********************************************************************
      95. *
      96. * Public code
      97. *
      98. **********************************************************************
      99. */
      100. /*********************************************************************
      101. *
      102. * MainTask
      103. */
      104. void MainTask(void) {
      105. GUI_Init();
      106. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      107. while (1) {
      108. GUI_Delay(100);
      109. }
      110. }
      Display All




      Regards,
      Sven
      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.