Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MOVIE_ShowFromFS.c Source File

MOVIE_ShowFromFS.c

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH                         *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2018  SEGGER Microcontroller GmbH                *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.48 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : MOVIE_ShowFromFS.c
00041 Purpose     : Shows how to play a movie directly from a file system.
00042 Requirements: WindowManager - ( )
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 
00049               Requires either a MS Windows environment or emFile.
00050 ----------------------------------------------------------------------
00051 */
00052 
00053 #ifndef SKIP_TEST
00054 
00055 #include "GUI.h"
00056 
00057 #ifdef WIN32
00058   #include <windows.h>
00059 #else
00060   #include "FS.h"
00061 #endif
00062 
00063 /*********************************************************************
00064 *
00065 *       Defines
00066 *
00067 **********************************************************************
00068 */
00069 //
00070 // Recommended memory to run the sample with adequate performance
00071 //
00072 #define RECOMMENDED_MEMORY (1024L * 80)
00073 
00074 /*********************************************************************
00075 *
00076 *       Static code
00077 *
00078 **********************************************************************
00079 */
00080 /*********************************************************************
00081 *
00082 *       _cbNotify
00083 *
00084 * Function description
00085 *   Callback function for movie player. Uses multiple buffering if
00086 *   available to avoid tearing effects.
00087 */
00088 void _cbNotify(GUI_HMEM hMem, int Notification, U32 CurrentFrame) {
00089   switch (Notification) {
00090   case GUI_MOVIE_NOTIFICATION_PREDRAW:
00091     GUI_MULTIBUF_Begin();
00092     break;
00093   case GUI_MOVIE_NOTIFICATION_POSTDRAW:
00094     GUI_MULTIBUF_End();
00095     break;
00096   case GUI_MOVIE_NOTIFICATION_STOP:
00097     break;
00098   }
00099 }
00100 
00101 /*********************************************************************
00102 *
00103 *       _GetData
00104 *
00105 * Function description
00106 *   Reading data directly from file system
00107 */
00108 int _GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) {
00109   U32 NumBytesRead;
00110 #ifdef WIN32
00111   HANDLE hFile;
00112 
00113   hFile = *(HANDLE *)p;
00114   SetFilePointer(hFile, Off, 0, FILE_BEGIN);
00115   ReadFile(hFile, (U8 *)*ppData, NumBytes, &NumBytesRead, NULL);
00116 #else
00117   FS_FILE * pFile;
00118 
00119   pFile = (FS_FILE *)p;
00120   FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
00121   NumBytesRead = FS_Read(pFile, (U8 *)*ppData, NumBytes);
00122 #endif
00123   return NumBytesRead;
00124 }
00125 
00126 /*********************************************************************
00127 *
00128 *       Public code
00129 *
00130 **********************************************************************
00131 */
00132 /*********************************************************************
00133 *
00134 *       _DrawSmilie
00135 */
00136 static void _DrawSmilie(int xPos, int yPos, int r) {
00137   int d;
00138 
00139   GUI_SetColor(GUI_YELLOW);
00140   GUI_FillCircle(xPos, yPos, r);
00141   GUI_SetColor(GUI_BLACK);
00142   GUI_SetPenSize(1);
00143   GUI_DrawCircle(xPos, yPos, r);
00144   d = (r * 2) / 5;
00145   GUI_FillCircle(xPos - d, yPos - d, r / 10);
00146   GUI_FillCircle(xPos + d, yPos - d, r / 10);
00147   GUI_DrawVLine(xPos, yPos - d / 2, yPos + d / 2);
00148   GUI_DrawArc(xPos, yPos + r + d, r, r, 70, 110);
00149 }
00150 
00151 /*********************************************************************
00152 *
00153 *       MainTask
00154 */
00155 void MainTask(void) {
00156   GUI_MOVIE_INFO   Info;
00157   GUI_MOVIE_HANDLE hMovie;
00158   int              xSize, ySize;
00159   GUI_RECT         Rect;
00160   int              FontDistY;
00161 #ifdef WIN32
00162   HANDLE           hFile;
00163   const char       acFileName[] = "C:\\MOVIE_ShowFromFS.emf";
00164   #define PARAM    &hFile
00165 #else
00166   FS_FILE        * pFile;
00167   const char       acFileName[] = "\\MOVIE_ShowFromFS.emf";
00168   #define PARAM    pFile
00169 #endif
00170 
00171   GUI_Init();
00172   //
00173   // Check if recommended memory for the sample is available
00174   //
00175   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00176     GUI_ErrorOut("Not enough memory available."); 
00177     return;
00178   }
00179   //
00180   // Get display size
00181   //
00182   xSize = LCD_GetXSize();
00183   ySize = LCD_GetYSize();
00184   //
00185   // Create file handle
00186   //
00187 #ifdef WIN32
00188   hFile = CreateFile(acFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
00189 #else
00190   FS_Init();
00191   pFile = FS_FOpen(acFileName, "r");
00192 #endif
00193   //
00194   // Get physical size of movie
00195   //
00196   if (GUI_MOVIE_GetInfoEx(_GetData, PARAM, &Info) == 0) {
00197     //
00198     // Check if display size fits
00199     //
00200     if ((Info.xSize <= xSize) && (Info.ySize <= ySize)) {
00201       //
00202       // Create and play movie
00203       //
00204       hMovie = GUI_MOVIE_CreateEx(_GetData, PARAM, _cbNotify);
00205       if (hMovie) {
00206         GUI_MOVIE_Show(hMovie, (xSize - Info.xSize) / 2, (ySize - Info.ySize) / 2, 1);
00207       }
00208     } else {
00209       //
00210       // Error message
00211       //
00212       GUI_SetFont(GUI_FONT_13_ASCII);
00213       GUI_DispStringHCenterAt("Video can not be shown.\n\nDisplay size too small.", xSize / 2, (ySize - GUI_GetFontSizeY()) / 2);
00214     }
00215   } else {
00216     GUI_SetBkColor(GUI_RED);
00217     GUI_Clear();
00218     GUI_SetFont(GUI_FONT_16_ASCII);
00219     FontDistY = GUI_GetFontDistY();
00220     Rect.x0 = 0;
00221     Rect.y0 = ySize / 2;
00222     Rect.x1 = xSize - 1;
00223     Rect.y1 = Rect.y0 + FontDistY * 3 - 1;
00224     GUI_DispStringInRect("Error opening the movie file.\n"
00225                          "Please make sure that the given\n"
00226                          "movie file exists on the specified path:",
00227                          &Rect, GUI_TA_HCENTER | GUI_TA_TOP);
00228     Rect.y0 = Rect.y1 + 1;
00229     Rect.y1 = Rect.y0 + FontDistY;
00230     GUI_DispStringInRect(acFileName, &Rect, GUI_TA_HCENTER | GUI_TA_TOP);
00231     Rect.y0 = Rect.y1 + 1;
00232     Rect.y1 = ySize - 1;
00233     GUI_DispStringInRect("A sample video can be downloaded\non www.segger.com.", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
00234     _DrawSmilie(xSize / 2, ySize / 4, ySize / 8);
00235   }
00236   while (1) {
00237     GUI_Exec();
00238     GUI_X_Delay(1);
00239   }
00240 }
00241 
00242 #endif
00243 
00244 /*************************** End of file ****************************/