ICONVIEW and External memory nOS

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

    • Hi,

      emWin doesn't require an OS, so the code you referred to should work under these circumstances.

      Best regards,

      Florian
      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.
    • Florian,

      What I meant to say was the referred link has usage of code that are used for windows. Since I am not using any OS, I am not able to use some features so I modified it to fit my needs but it still doesn't seem to work. I have attached the code I am working on, could you please take a look at it and let me know what I am doing wrong?

      Best regards,
      BMD

      C Source Code

      1. /*********************************************************************
      2. * SEGGER Microcontroller GmbH *
      3. * Solutions for real time microcontroller applications *
      4. **********************************************************************
      5. * *
      6. * (c) 1996 - 2018 SEGGER Microcontroller GmbH *
      7. * *
      8. * Internet: www.segger.com Support: support@segger.com *
      9. * *
      10. **********************************************************************
      11. ** emWin V5.48 - Graphical user interface for embedded applications **
      12. emWin is protected by international copyright laws. Knowledge of the
      13. source code may not be used to write a similar product. This file may
      14. only be used in accordance with a license and should not be re-
      15. distributed in any way. We appreciate your understanding and fairness.
      16. ----------------------------------------------------------------------
      17. File : GUI_DrawExternalImage_BMP.c
      18. Purpose : Sample that shows how to draw external BMP images
      19. with emWin.
      20. This sample supports both usage in the Windows Simulation as well
      21. as usage on a target device using emFile.
      22. ---------------------------END-OF-HEADER------------------------------
      23. */
      24. #include "project.h"
      25. #include <stddef.h>
      26. #include <string.h>
      27. #include "WM.h"
      28. #include "BUTTON.h"
      29. #include "DIALOG.h"
      30. #include "Global Defines.h"
      31. #define GLOBALS_INTERNAL
      32. #include "Global Variables.h"
      33. #include "ICONVIEW.h"
      34. #include "GUI.h"
      35. #include "FS.h"
      36. /*********************************************************************
      37. *
      38. * Defines
      39. *
      40. **********************************************************************
      41. */
      42. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      43. #define ID_ICONVIEW_0 (GUI_ID_USER + 0x01)
      44. #define ID_ICONVIEW_0_IMAGE_0 0x00
      45. /*********************************************************************
      46. *
      47. * Static data
      48. *
      49. **********************************************************************
      50. */
      51. /*********************************************************************
      52. *
      53. * _aDialogCreate
      54. */
      55. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      56. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      57. { ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_0, 10, 190, 50, 50, 0, 0x00320032, 0 },
      58. };
      59. /*********************************************************************
      60. *
      61. * Public code
      62. *
      63. **********************************************************************
      64. */
      65. /*********************************************************************
      66. *
      67. * _GetImageById
      68. */
      69. static const void * _GetImageById(U32 Id){
      70. const char * apImagePath[] = {
      71. // "\\AlarmAudio.bmp",
      72. // "\\AlarmNoSilenceIconDown.bmp",
      73. // "\\AlarmNoSilenceIconUp.bmp",
      74. // "\\ButtonBacklightUp.bmp"
      75. "\\Alarm&Audio.dta",
      76. "\\AlarmNoSilenceIconDown.dta",
      77. "\\AlarmNoSilenceIconUp.dta",
      78. "\\ButtonBacklightUp.dta"
      79. };
      80. if (Id < GUI_COUNTOF(apImagePath)) {
      81. return FS_FOpen(apImagePath[Id], "rb");
      82. } else {
      83. return 0;
      84. }
      85. }
      86. /*********************************************************************
      87. *
      88. * APP_GetData
      89. */
      90. int _GetDataBMP(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off)
      91. {
      92. static U8 acBuffer[512];
      93. FS_FILE * pFile;
      94. int NumBytesRead;
      95. pFile = (FS_FILE *)p;
      96. //
      97. // Check buffer size
      98. //
      99. if (NumBytes > sizeof(acBuffer))
      100. {
      101. NumBytes = sizeof(acBuffer);
      102. }
      103. //
      104. // Set file pointer to the required position
      105. //
      106. FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
      107. //
      108. // Read data into buffer
      109. //
      110. NumBytesRead = FS_FRead(acBuffer, 1, NumBytes, pFile);
      111. //
      112. // Set data pointer to the beginning of the buffer
      113. //
      114. *ppData = (const U8 *)acBuffer;
      115. //
      116. // Return number of available bytes
      117. //
      118. return NumBytesRead;
      119. }
      120. /*********************************************************************
      121. *
      122. * _OwnerDraw
      123. */
      124. static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      125. const void * pData;
      126. switch (pDrawItemInfo->Cmd) {
      127. case WIDGET_ITEM_DRAW_BITMAP:
      128. pData = _GetImageById(pDrawItemInfo->ItemIndex);
      129. GUI_DrawStreamedBitmapExAuto(_GetDataBMP, (void *)&pData, pDrawItemInfo->x0, pDrawItemInfo->y0);
      130. return 0;
      131. default:
      132. return ICONVIEW_OwnerDraw(pDrawItemInfo);
      133. }
      134. }
      135. /*********************************************************************
      136. *
      137. * _cbDialog
      138. */
      139. static void _cbDialog(WM_MESSAGE * pMsg) {
      140. const void * pData;
      141. WM_HWIN hItem;
      142. U32 FileSize;
      143. int NCode;
      144. int Id;
      145. static GUI_BITMAP DummyBitmap;
      146. switch (pMsg->MsgId) {
      147. case WM_INIT_DIALOG:
      148. //
      149. // Initialization of 'Iconview'
      150. //
      151. hItem = WM_GetDialogItem(pMsg->hWin, ID_ICONVIEW_0);
      152. ICONVIEW_SetOwnerDraw(hItem, _OwnerDraw);
      153. // pData = _GetImageById("AlarmAudio.bmp", &FileSize);
      154. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "");
      155. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "Item");
      156. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "Item");
      157. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "Item");
      158. // ICONVIEW_AddStreamedBitmapItem(hItem, pData, "");
      159. // ICONVIEW_SetBkColor(hItem, ICONVIEW_CI_BK, GUI_MAKE_COLOR(0x00E1ECEE));
      160. break;
      161. case WM_NOTIFY_PARENT:
      162. Id = WM_GetId(pMsg->hWinSrc);
      163. NCode = pMsg->Data.v;
      164. switch(Id) {
      165. case ID_ICONVIEW_0: // Notifications sent by 'Iconview'
      166. switch(NCode) {
      167. case WM_NOTIFICATION_CLICKED:
      168. break;
      169. case WM_NOTIFICATION_RELEASED:
      170. break;
      171. case WM_NOTIFICATION_MOVED_OUT:
      172. break;
      173. case WM_NOTIFICATION_SCROLL_CHANGED:
      174. break;
      175. case WM_NOTIFICATION_SEL_CHANGED:
      176. break;
      177. }
      178. break;
      179. }
      180. break;
      181. default:
      182. WM_DefaultProc(pMsg);
      183. break;
      184. }
      185. }
      186. /*********************************************************************
      187. *
      188. * Public code
      189. *
      190. **********************************************************************
      191. */
      192. /*********************************************************************
      193. *
      194. * MainTask
      195. */
      196. void BitmapOnIconview(void) {
      197. FS_Init();
      198. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      199. while (1) {
      200. GUI_Delay(100);
      201. }
      202. }
      Display All
    • Hi,

      I was able to make the modifications but I am not able to set the index to display different icons. Could you please see the code and tell me how to do that so I am able to display all the Icons as required?


      C Source Code

      1. ----------
      2. */
      3. #include "project.h"
      4. #include <string.h>
      5. #include "WIDGET.h"
      6. #include "WM.h"
      7. #include "BUTTON.h"
      8. #include "DIALOG.h"
      9. #include "ICONVIEW.h"
      10. #include "FS.h"
      11. /*********************************************************************
      12. *
      13. * Defines
      14. *
      15. **********************************************************************
      16. */
      17. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      18. #define ID_ICONVIEW_0 (GUI_ID_USER + 0x01)
      19. #define ID_ICONVIEW_1 (GUI_ID_USER + 0x02)
      20. #define ID_TEXT_0 (GUI_ID_USER + 0x03)
      21. #define ID_ICONVIEW_0_IMAGE_0 0x01
      22. #define ID_ICONVIEW_1_IMAGE_0 0x02
      23. #define RECOMMENDED_MEMORY (1024L * 5)
      24. int touch = 0;
      25. /*********************************************************************
      26. *
      27. * Static data
      28. *
      29. **********************************************************************
      30. */
      31. /*********************************************************************
      32. *
      33. * _aDialogCreate
      34. */
      35. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
      36. {
      37. { WINDOW_CreateIndirect, "Window", 0, 0, 0, 320, 240},
      38. { ICONVIEW_CreateIndirect, "UpArrow", ID_ICONVIEW_0, 35, 10, 30, 44},
      39. { TEXT_CreateIndirect, "AlarmNoSilenceTimer", ID_TEXT_0, 10, 40, 30, 20, 0, 0x64, 0 },
      40. { ICONVIEW_CreateIndirect, "DownArrow", ID_ICONVIEW_1, 35, 50, 30, 44},
      41. };
      42. /*********************************************************************
      43. *
      44. * Public code
      45. *
      46. **********************************************************************
      47. */
      48. unsigned int UpArrowLeft = 21;
      49. unsigned int UpArrowRight;
      50. unsigned int DownArrowLeft;
      51. unsigned int DownArrowRight = 100;
      52. /*********************************************************************
      53. *
      54. * _GetImageById
      55. */
      56. static const void * _GetImageById(U32 Id)
      57. {
      58. FS_FILE * pFile;
      59. char acVolumeName[10];
      60. const char * apImagePath[] =
      61. {
      62. "UpArrow.bmp",
      63. "GearUp.bmp",
      64. "O2Cell.bmp",
      65. };
      66. if (Id < GUI_COUNTOF(apImagePath))
      67. {
      68. FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName));
      69. if (FS_Mount(acVolumeName) > 0)
      70. {
      71. pFile = FS_FOpen(apImagePath[Id], "rb");
      72. }
      73. return pFile;
      74. }
      75. else
      76. {
      77. return 0;
      78. }
      79. }
      80. /*********************************************************************
      81. *
      82. * APP_GetData
      83. */
      84. int _GetDataBMP(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off)
      85. {
      86. static U8 acBuffer[512];
      87. FS_FILE * pFile;
      88. int NumBytesRead;
      89. pFile = (FS_FILE *)p;
      90. //
      91. // Check buffer size
      92. //
      93. if (NumBytes > sizeof(acBuffer))
      94. {
      95. NumBytes = sizeof(acBuffer);
      96. }
      97. //
      98. // Set file pointer to the required position
      99. //
      100. FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
      101. //
      102. // Read data into buffer
      103. //
      104. NumBytesRead = FS_FRead(acBuffer, 1, NumBytes, pFile);
      105. //
      106. // Set data pointer to the beginning of the buffer
      107. //
      108. *ppData = (const U8 *)acBuffer;
      109. //
      110. // Return number of available bytes
      111. //
      112. return NumBytesRead;
      113. }
      114. /*********************************************************************
      115. *
      116. * _OwnerDraw
      117. */
      118. static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo)
      119. {
      120. FS_FILE *pFile;
      121. switch (pDrawItemInfo->Cmd)
      122. {
      123. case WIDGET_ITEM_DRAW_BITMAP:
      124. pFile = _GetImageById(pDrawItemInfo->ItemIndex);
      125. GUI_BMP_DrawEx(_GetDataBMP, pFile, pDrawItemInfo->x0,pDrawItemInfo->y0);
      126. FS_FClose(pFile);
      127. return 0;
      128. default:
      129. return ICONVIEW_OwnerDraw(pDrawItemInfo);
      130. }
      131. }
      132. /*********************************************************************
      133. *
      134. * _cbDialog
      135. */
      136. static void _cbDialog(WM_MESSAGE * pMsg)
      137. {
      138. WM_HWIN hItem;
      139. int NCode;
      140. int Id;
      141. // BUTTON_Handle hButton;
      142. // ICONVIEW_Handle hIcon;
      143. TEXT_Handle hText1;
      144. GUI_BITMAP DummyBitmap;
      145. switch (pMsg->MsgId)
      146. {
      147. case WM_PAINT:
      148. GUI_SetBkColor(0x00E1ECEE);
      149. GUI_SetColor(0x00DBA47B);
      150. GUI_SetPenSize(1);
      151. GUI_DrawLine(0,188, 320,188);
      152. GUI_DrawRect(175,190, 316,238);
      153. GUI_DrawLine(247, 190, 247, 237);
      154. GUI_SetColor(0x00774409);
      155. GUI_SetPenSize(3);
      156. GUI_DrawLine(5, 167, 105, 167);
      157. GUI_DrawLine(210, 167, 320, 167);
      158. GUI_SetFont(GUI_FONT_24B_1);
      159. GUI_SetColor(0x00774409);
      160. GUI_DispStringAt("21",10,139);
      161. GUI_DispStringAt("100",282,139);
      162. GUI_DispDecAt(DownArrowRight, 282, 40, 3);
      163. break;
      164. case WM_INIT_DIALOG:
      165. WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00E1ECEE));
      166. //
      167. // Initialization of 'Iconview'
      168. //
      169. // pDrawItemInfo->ItemIndex = 0;
      170. hItem = WM_GetDialogItem(pMsg->hWin, ID_ICONVIEW_0);
      171. ICONVIEW_SetOwnerDraw(hItem, _OwnerDraw);
      172. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "");
      173. //ICONVIEW_AddBitmapItem(hItem, _GetImageById(0), "");
      174. // ICONVIEW_SetBkColor(hItem, ICONVIEW_CI_BK, GUI_MAKE_COLOR(0x00E1ECEE));
      175. //
      176. // Initialization of 'AlarmNoSilenceTimer'
      177. //
      178. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      179. TEXT_SetFont(hItem, GUI_FONT_24B_1);
      180. TEXT_SetText(hItem, "21");
      181. hItem = WM_GetDialogItem(pMsg->hWin, ID_ICONVIEW_1);
      182. ICONVIEW_SetOwnerDraw(hItem, _OwnerDraw);
      183. ICONVIEW_AddBitmapItem(hItem, &DummyBitmap, "");
      184. //ICONVIEW_AddBitmapItem(hItem, _GetImageById(1), "");
      185. break;
      186. case WM_NOTIFY_PARENT:
      187. Id = WM_GetId(pMsg->hWinSrc);
      188. NCode = pMsg->Data.v;
      189. switch (NCode)
      190. {
      191. case WM_NOTIFICATION_RELEASED: // React only if released
      192. hText1 = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      193. if(Id == ID_ICONVIEW_0)
      194. {
      195. GUI_ClearRect(10,10,38,65);
      196. UpArrowLeft = (UpArrowLeft+1);
      197. TEXT_SetDec (hText1,UpArrowLeft,2,0,0,1);
      198. }
      199. if(Id == GUI_ID_BUTTON0)
      200. {
      201. }
      202. break;
      203. }
      204. break;
      205. default:
      206. WM_DefaultProc(pMsg);
      207. }
      208. }
      209. /*********************************************************************
      210. *
      211. * Public code
      212. *
      213. **********************************************************************
      214. */
      215. /*********************************************************************
      216. *
      217. * MainTask
      218. */
      219. void BitmapOnIconview(void)
      220. {
      221. //
      222. // Check if recommended memory for the sample is available
      223. //
      224. if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY)
      225. {
      226. GUI_ErrorOut("Not enough memory available.");
      227. return;
      228. }
      229. //
      230. // Use memory devices for all windows
      231. //
      232. #if GUI_SUPPORT_MEMDEV
      233. WM_SetCreateFlags(WM_CF_MEMDEV);
      234. WM_EnableMemdev(WM_HBKWIN);
      235. #endif
      236. WM_SetDesktopColor(GUI_BLACK);
      237. while (1)
      238. {
      239. GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, 0, 0, 0);
      240. GUI_Delay(10);
      241. }
      242. }
      243. /*************************** End of file ****************************/
      Display All
      Appreciate all the help!

      Thanks and regards,
      BMD
    • Florian/Sven,

      Could you please help me understand how to display different images assigned to different icons from external memory?? So far, I can only see same image on all the icons. I couldn't find anything on the forum regarding this as well. Any hint will be greatly appreciated.


      Thanks and regards,
      BMD
    • Hi,

      I can't tell what is wrong with your code, my guess is the file handles point all to the same image, thus all icons are the same.

      Best regards,

      Florian
      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.