Edit Widget and Up / Down buttons with auto repeat

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

  • Edit Widget and Up / Down buttons with auto repeat

    I want to use Edit Widget with two buttons for changing values Up and Down.
    In attachment is example and it works but it change value only for one when I press Up or Down button.
    I need auto increment or decrement function if I press and hold Up or Down button.
    I try to implement auto repeat function with use of WM_CreateTimer() and it works but not as I want.
    When I press Up or Down Button first time, first pause before Button repeat should be 500msec and all next pauses before Button repeat should be 100msec.
    Timer function is not included in attached example.

    I need suggestion how to implement button auto repeat function.

    Thanks

    C Source Code

    1. /*********************************************************************
    2. * *
    3. * SEGGER Microcontroller GmbH & Co. KG *
    4. * Solutions for real time microcontroller applications *
    5. * *
    6. **********************************************************************
    7. * *
    8. * C-file generated by: *
    9. * *
    10. * GUI_Builder for emWin version 5.14 *
    11. * Compiled Jan 12 2012, 10:28:50 *
    12. * (c) 2011 Segger Microcontroller GmbH & Co. KG *
    13. * *
    14. **********************************************************************
    15. * *
    16. * Internet: www.segger.com Support: support@segger.com *
    17. * *
    18. **********************************************************************
    19. */
    20. // USER START (Optionally insert additional includes)
    21. // USER END
    22. #include "DIALOG.h"
    23. /*********************************************************************
    24. *
    25. * Defines
    26. *
    27. **********************************************************************
    28. */
    29. #define ID_WINDOW_0 (GUI_ID_USER + 0x06)
    30. #define ID_EDIT_0 (GUI_ID_USER + 0x07)
    31. #define ID_BUTTON_0 (GUI_ID_USER + 0x08)
    32. #define ID_BUTTON_1 (GUI_ID_USER + 0x09)
    33. // USER START (Optionally insert additional defines)
    34. // USER END
    35. /*********************************************************************
    36. *
    37. * Static data
    38. *
    39. **********************************************************************
    40. */
    41. // USER START (Optionally insert additional static data)
    42. // USER END
    43. /*********************************************************************
    44. *
    45. * _aDialogCreate
    46. */
    47. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    48. { WINDOW_CreateIndirect, "EditTest", ID_WINDOW_0, 0, 0, 320, 240, 0, 0, 0 },
    49. { EDIT_CreateIndirect, "Edit", ID_EDIT_0, 90, 40, 130, 40, 0, 5, 0 },
    50. { BUTTON_CreateIndirect, "-", ID_BUTTON_0, 50, 120, 80, 20, 0, 0, 0 },
    51. { BUTTON_CreateIndirect, "+", ID_BUTTON_1, 180, 120, 80, 20, 0, 0, 0 },
    52. // USER START (Optionally insert additional widgets)
    53. // USER END
    54. };
    55. /*********************************************************************
    56. *
    57. * Static code
    58. *
    59. **********************************************************************
    60. */
    61. // USER START (Optionally insert additional static code)
    62. // USER END
    63. /*********************************************************************
    64. *
    65. * _cbDialog
    66. */
    67. static void _cbDialog(WM_MESSAGE * pMsg) {
    68. WM_HWIN hItem;
    69. int Id, NCode;
    70. // USER START (Optionally insert additional variables)
    71. // USER END
    72. switch (pMsg->MsgId) {
    73. case WM_INIT_DIALOG:
    74. //
    75. // Initialization of 'Edit'
    76. //
    77. hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
    78. EDIT_SetText(hItem, "1000");
    79. EDIT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER);
    80. EDIT_SetFont(hItem, GUI_FONT_D24X32);
    81. EDIT_SetFloatMode(hItem, 0 , 0 , 99.99, 2, 2);
    82. EDIT_SetCursorAtChar(hItem , 3);
    83. //
    84. // Initialization of '-'
    85. //
    86. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    87. BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
    88. BUTTON_SetFocussable(hItem,0);
    89. //
    90. // Initialization of '+'
    91. //
    92. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    93. BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
    94. BUTTON_SetFocussable(hItem,0);
    95. // USER START (Optionally insert additional code for further widget initialization)
    96. // USER END
    97. break;
    98. case WM_NOTIFY_PARENT:
    99. Id = WM_GetId(pMsg->hWinSrc);
    100. NCode = pMsg->Data.v;
    101. switch(Id) {
    102. case ID_EDIT_0: // Notifications sent by 'Edit'
    103. switch(NCode) {
    104. case WM_NOTIFICATION_CLICKED:
    105. // USER START (Optionally insert code for reacting on notification message)
    106. // USER END
    107. break;
    108. case WM_NOTIFICATION_RELEASED:
    109. // USER START (Optionally insert code for reacting on notification message)
    110. // USER END
    111. break;
    112. case WM_NOTIFICATION_VALUE_CHANGED:
    113. // USER START (Optionally insert code for reacting on notification message)
    114. // USER END
    115. break;
    116. // USER START (Optionally insert additional code for further notification handling)
    117. // USER END
    118. }
    119. break;
    120. case ID_BUTTON_0: // Notifications sent by '-'
    121. switch(NCode) {
    122. case WM_NOTIFICATION_CLICKED:
    123. // USER START (Optionally insert code for reacting on notification message)
    124. GUI_SendKeyMsg(GUI_KEY_DOWN, 1); // Send a key message to the focussed window
    125. // USER END
    126. break;
    127. case WM_NOTIFICATION_RELEASED:
    128. // USER START (Optionally insert code for reacting on notification message)
    129. // USER END
    130. break;
    131. // USER START (Optionally insert additional code for further notification handling)
    132. // USER END
    133. }
    134. break;
    135. case ID_BUTTON_1: // Notifications sent by '+'
    136. switch(NCode) {
    137. case WM_NOTIFICATION_CLICKED:
    138. // USER START (Optionally insert code for reacting on notification message)
    139. GUI_SendKeyMsg(GUI_KEY_UP, 1); // Send a key message to the focussed window
    140. // USER END
    141. break;
    142. case WM_NOTIFICATION_RELEASED:
    143. // USER START (Optionally insert code for reacting on notification message)
    144. // USER END
    145. break;
    146. // USER START (Optionally insert additional code for further notification handling)
    147. // USER END
    148. }
    149. break;
    150. // USER START (Optionally insert additional code for further Ids)
    151. // USER END
    152. }
    153. break;
    154. // USER START (Optionally insert additional message handling)
    155. // USER END
    156. default:
    157. WM_DefaultProc(pMsg);
    158. break;
    159. }
    160. }
    161. /*********************************************************************
    162. *
    163. * Public code
    164. *
    165. **********************************************************************
    166. */
    167. /*********************************************************************
    168. *
    169. * CreateEditTest
    170. */
    171. WM_HWIN CreateEditTest(void);
    172. WM_HWIN CreateEditTest(void) {
    173. WM_HWIN hWin;
    174. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, WM_HBKWIN, 0, 0);
    175. return hWin;
    176. }
    177. // USER START (Optionally insert additional public code)
    178. void MainTask(void)
    179. {
    180. GUI_Init();
    181. CreateEditTest();
    182. while(1)
    183. GUI_Exec();
    184. }
    185. // USER END
    186. /*************************** End of file ****************************/
    Display All