Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

IFlip sample code, part 6

Definition and implementation of the c_iflipapp_DrawScreen() function

/*===========================================================================
FUNCTION c_iflipapp_DrawScreen

DESCRIPTION
This is main function which draws the output on screen according to  the active 
application state.

PROTOTYPE:
static void c_iflipapp_DrawScreen(c_iflipapp* pMe, AppState state)

PARAMETERS:
pMe: Pointer to the c_iflipapp structure.
state: Application state
DEPENDENCIES
none

RETURN VALUE
none

SIDE EFFECTS
none
===========================================================================*/

static void c_iflipapp_DrawScreen(c_iflipapp* pMe, AppState state)
{
   int nErr = 0, i=0, fId = 0, xPos=0, yPos=0, zPos=0;    
   int bIsParmSupported = FALSE;
   int nParm;
   char buff [200] = {0};   // temperory storage buffer
   AEEFlipInfoEx pFlipInfoEx; 		  
   int16 numKeys;   
   AVKType * pKeyList = NULL; 	// Stores accessible key list

   // First store the current state of application
   pMe->currentAppState = state;

   switch (state)
   {
      case NOTICE_SCR:
      // Display notice when application starts
      c_iflipapp_DrawNotice(pMe);
      ISHELL_SetTimer (pMe->a.m_pIShell,NOTICE_TIMER_DELAY,c_iflipapp_timerCB, pMe);
      break;
      case PRIMARY_OUTPUT_SCR:
		 {
            nParm = FLIP_PARM_DISPLAYLIST;
            bIsParmSupported = FALSE;
            // Reset buffer
            MEMSET(pMe->pbuffer,0, TEXT_BUFFER_SIZE);
            if (pMe->pIStatic)
			{
               ISTATIC_SetText(pMe->pIStatic, L"Flip Info", NULL, AEE_FONT_BOLD, NULL);
			}
            // First check support for FLIP_PARM_DISPLAYLIST.
            if ( SUCCESS != (nErr =	IFLIP_IsSupport(pMe->pIFlip,NULL,(int32 *)nParm,
																																				(int32 *)&bIsParmSupported)))
			{
               DBGPRINTF("IFLIP_IsSupport failed error=%d",nErr);
			}
            if (bIsParmSupported)
			{
               //Find out the number of displays available and then allocate memory.
               IFLIP_GetDisplayList(pMe->pIFlip, NULL, (int32 *)&(pMe->nNumberOfDisplay));
               DBGPRINTF("Num Display =%d", pMe->nNumberOfDisplay);
               if(NULL == pMe->pDispList)
			   {
                  pMe->pDispList = 
                      (AEECLSID *)(MALLOC (sizeof(AEECLSID) * (pMe->nNumberOfDisplay)));
			   }
               // Fetch the displaylist			  
               nErr = IFLIP_GetDisplayList(pMe->pIFlip,
                                          (int32 *)pMe->pDispList,
                                          (int32 *)&(pMe->nNumberOfDisplay));
               if (nErr != SUCCESS)
			   {
                  DBGPRINTF("IFLIP_GetDisplayList failed with return value %d",nErr); 
			   }
               
			   DBGPRINTF("Display Class IDs: ");
		   
               // Extract the display class id
               for (i=0; i < pMe->nNumberOfDisplay; i++)
			   {
                  SPRINTF(buff, "Display id %d ",*(pMe->pDispList+i)); 
                  DBGPRINTF("Disp %d ",*(pMe->pDispList+i));
                  STRCAT(pMe->pbuffer,buff);
                  STRCAT(pMe->pbuffer, "\n");
                  pMe->pDispClassId[i] = *(pMe->pDispList+i);
			   }

               // Create instance of each display
               if(!pMe->pIDis[0] && (pMe->pDispClassId[0]))
			   {
			      if (ISHELL_CreateInstance(pMe->a.m_pIShell, 
                                   pMe->pDispClassId[0], 
                                  (void **)&(pMe->pIDis[0])) != SUCCESS)
				  {
				     DBGPRINTF("Display instance 1 failed");
				  }	  
			   }
               if(!pMe->pIDis[1] && (pMe->pDispClassId[1]))
			   {
			      if (ISHELL_CreateInstance(pMe->a.m_pIShell, 
                                   pMe->pDispClassId[1], 
                                  (void **)&(pMe->pIDis[1])) != SUCCESS)
				  {
				     DBGPRINTF("Display instance 2 failed");
				  }	  
			   }
               if(!pMe->pIDis[2] && (pMe->pDispClassId[2]))
			   {
			      if (ISHELL_CreateInstance(pMe->a.m_pIShell, 
                                   pMe->pDispClassId[2], 
                                  (void **)&(pMe->pIDis[2])) != SUCCESS)
				  {
				     DBGPRINTF("Display instance 3 failed");
				  }
			   }
               if(!pMe->pIDis[3] && (pMe->pDispClassId[3]))
			   {
				  if (ISHELL_CreateInstance(pMe->a.m_pIShell, 
                                pMe->pDispClassId[3], 
                               (void **)&(pMe->pIDis[3])) != SUCCESS)
				  {
				     DBGPRINTF("Display instance 4 failed");
				  }
			   }
			}
            else
			{
               DBGPRINTF("FLIP_PARM_DISPLAYLIST not supported");
			}
  
            // Retrieves the flip IDs of the flips present on the device 
            for (i=0; i < pMe->nNumberOfFlip;++i)
			{
               SPRINTF(buff,"Flip ID for flip %d: %d", 
                       i+1,DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i)));
               DBGPRINTF("%d",DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i)));
               STRCAT(pMe->pbuffer,buff);
               STRCAT(pMe->pbuffer, "\n");
			}
		  
            //Retrieves the information about the specified flip in the 
            // AEEFlipInfox structure
            // The caller allocates the structure and indicates the structure size 
            // in wStructSize.
	      	    pFlipInfoEx.dwStructSize = sizeof(AEEFlipInfoEx); 

            // DEVNOTIFY_MAKE() to set the flip ID in the flipInfo member of pFlipInfoEx 
            pFlipInfoEx.flipInfo = DEVNOTIFY_MAKE(0,0,0,0);   

		  
            for (i=0; i < pMe->nNumberOfFlip; ++i)
			{
               if(SUCCESS == IFLIP_GetFlipInfoEx(pMe->pIFlip,&pFlipInfoEx))
			   {
                  pFlipInfoEx.flipInfo = *((pMe->pFlipInfoList)+i);
                  DBGPRINTF("IFLIP_GetFlipInfoEx, 
                            flip ID: %d, cap %d, pos %d", 
                            DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i)), 
                            (&pFlipInfoEx)->flipCapability, 
                            (&pFlipInfoEx)->flipPositionType);
                  SPRINTF(buff,
                          "Flip ID %d's\n   Capability %d\n   Position Type %d", 
                          DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i)), 
                          (&pFlipInfoEx)->flipCapability, 
                          (&pFlipInfoEx)->flipPositionType);
                  STRCAT(pMe->pbuffer,buff);
                  STRCAT(pMe->pbuffer, "\n");
			   }
			}

            /* This returns the maximum position that the specified flip can take,
            that is, the position of the flip when it is fully open. 
            Use the DEVNOTIFY_GET_X, DEVNOTIFY_GET_Y and DEVNOTIFY_GET_Z macros
            to retrieve values from pFlipInfo*/

            for (i=0; i < pMe->nNumberOfFlip;++i)
			{
	           if(SUCCESS != (nErr = IFLIP_GetMaxFlipPosition(pMe->pIFlip,
                          ((pMe->pFlipInfoList)+i))))
			   {
	              DBGPRINTF("IFLIP_GetMaxFlipPosition failed error=%d",nErr);
	              return;
			   }
               fId  = DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i)); // Flip Id
               xPos = DEVNOTIFY_GET_X(*((pMe->pFlipInfoList)+i));  // Maximum X position
               yPos = DEVNOTIFY_GET_Y(*((pMe->pFlipInfoList)+i));  // Maximum Y position
               zPos = DEVNOTIFY_GET_Z(*((pMe->pFlipInfoList)+i));  // Maximum Z position
	  
               DBGPRINTF("Max positions of flip ID: %d, xPos %d,yPos %d, zPos %d ",
                         fId,xPos,yPos,zPos);
               SPRINTF(buff,
                       "Flip ID %d's\n    Max Position X %d\n    
                        Max Position Y %d\n    Max Position Z %d ",
                        fId,xPos,yPos,zPos);
               STRCAT(pMe->pbuffer,buff);
               STRCAT(pMe->pbuffer, "\n");
			}

		  
		    /* This returns the minimum position that the specified flip can take,
		    that is, the position of the flip when it is fully closed.
		    Use the DEVNOTIFY_MAKE macro to set the ID portion in pFlipInfo. 
		    Use the DEVNOTIFY_GET_X, DEVNOTIFY_GET_Y and DEVNOTIFY_GET_Z macros 
		    to retrieve values from pFlipInfo, if this function returns SUCCESS.
		    */
		  		  

		    for (i=0; i < pMe->nNumberOfFlip;++i)
			{

			   if(SUCCESS != (nErr = IFLIP_GetMinFlipPosition
                    (pMe->pIFlip,((pMe->pFlipInfoList)+i))))
			   {
				  DBGPRINTF("IFLIP_GetMaxFlipPosition failed error=%d",nErr);
				  return  ;
			   }

               fId  = DEVNOTIFY_GET_ID(*((pMe->pFlipInfoList)+i));  // Flip id
			   xPos = DEVNOTIFY_GET_X(*((pMe->pFlipInfoList)+i));   // Minimum X position
			   yPos = DEVNOTIFY_GET_Y(*((pMe->pFlipInfoList)+i));   // Minimum Y position
			   zPos = DEVNOTIFY_GET_Z(*((pMe->pFlipInfoList)+i));   // Minimum Z position

			   DBGPRINTF("Min positions of flip ID: %d, x %d,y %d, z %d ", fId, xPos, yPos, zPos);
			   SPRINTF(buff,
              "Flip ID %d's\n    Min Position X %d\n    
               Min Position Y %d\n    Min Position Z %d ",
               fId, xPos, yPos, zPos);
			   STRCAT(pMe->pbuffer,buff);
			   STRCAT(pMe->pbuffer, "\n");
			}

		    //Acknowledge from Background application

		    STRCAT(pMe->pbuffer, "BG Acknowledge received\n");
		    STRCAT(pMe->pbuffer, pMe->pAckFromBGapp);

		    // Feed buffer to istatic
		    ISTATIC_SetTextEx(pMe->pIStatic, (byte*)pMe->pbuffer, NULL, FALSE);
		 }
		break;
    case SECONDARY_SCR:
		{
         if(pMe->pIDis[1])
		 {		
		    IDISPLAY_ClearScreen(pMe->pIDis[1]);
			IDISPLAY_DrawText(pMe->pIDis[1], 
                     AEE_FONT_NORMAL, 
                     L"Open Flip", -1, 0, 0, NULL , 
                     IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);
			IDISPLAY_Update(pMe->pIDis[1]);	
		 }
		}
		break;
	case PRI_KEYLIST_OUTPUT_SCR:
	case SEC_KEYLIST_OUTPUT_SCR:
	case SLIDER_KEYLIST_CLOSED_SCR:
	case SLIDER_KEYLIST_OPENED_SCR:  
		{
		    nParm = FLIP_PARM_KEYLIST;
			bIsParmSupported = FALSE;

			// Sets IStatic title according to te current active application state

			if(PRI_KEYLIST_OUTPUT_SCR == pMe->currentAppState)
			{
			    MEMSET(pMe->pOpenKeyList,0, TEXT_BUFFER_SIZE);
				ISTATIC_SetText(pMe->pIStatic, L"KeyList(Flip open)", NULL, AEE_FONT_BOLD, NULL);
			}
			else if(SLIDER_KEYLIST_CLOSED_SCR == pMe->currentAppState)
			{
			    MEMSET(pMe->pOpenKeyList,0, TEXT_BUFFER_SIZE);
				ISTATIC_SetText(pMe->pIStatic, L"KeyList(Slider closed)", NULL, AEE_FONT_BOLD, NULL);
			}
			else if(SLIDER_KEYLIST_OPENED_SCR == pMe->currentAppState)
			{
			    MEMSET(pMe->pOpenKeyList,0, TEXT_BUFFER_SIZE);
				ISTATIC_SetText(pMe->pIStatic, L"KeyList(Slider Opened)", NULL, AEE_FONT_BOLD, NULL);
			}
			else if(SEC_KEYLIST_OUTPUT_SCR == pMe->currentAppState)
			{
			    MEMSET(pMe->pCloseKeyList,0, TEXT_BUFFER_SIZE);
		
			}

			// First check for FLIP_PARM_KEYLIST support

			IFLIP_IsSupport(pMe->pIFlip,NULL,(int32 *)nParm,(int32 *)&bIsParmSupported);

			// if FLIP_PARM_KEYLIST supported then fetch keylist

			if(bIsParmSupported)
			{
			   // First get the number of keys available
			   IFLIP_GetKeyList(pMe->pIFlip,NULL,(int32 *)&numKeys);
				
			   // Allocate memory depending on number of keys(primary/secondary)

			   if(pKeyList == NULL)
			   {
			      pKeyList = (AVKType *)(MALLOC (sizeof(AVKType) * numKeys));
			   }

			   DBGPRINTF("IFLIP_GetKeyList, numKeys %d",numKeys);

			   // Gets the key list
			   if(SUCCESS != (nErr = IFLIP_GetKeyList
        (pMe->pIFlip,(int32 *)pKeyList,(int32 *)&numKeys)))
			   {
			      DBGPRINTF("IFLIP_GetKeyList Failed");
				  return  ;
			   }
				
			   // Fetch out each key and store on buffer
			   if((PRI_KEYLIST_OUTPUT_SCR == pMe->currentAppState) 
					|| (SLIDER_KEYLIST_CLOSED_SCR == pMe->currentAppState)
					|| (SLIDER_KEYLIST_OPENED_SCR == pMe->currentAppState))
			   {
			      for (i=0; i < numKeys;i++)
				  {
				     DBGPRINTF("Key Code%d ",*(pKeyList+i)); 
					 SPRINTF(buff," Key Code    %d ",*(pKeyList+i));
                     STRCAT(pMe->pOpenKeyList,buff);
					 STRCAT(pMe->pOpenKeyList, "\n");
				  }
				  ISTATIC_SetTextEx(pMe->pIStatic, (byte*)pMe->pOpenKeyList, NULL, FALSE);
			   }
			// When flip is closed, only access the key list but display it only when flip is 
   // opened again.
			   else if (SEC_KEYLIST_OUTPUT_SCR == pMe->currentAppState)
			   {
			      for (i=0; i < numKeys;i++)
				  {
				     DBGPRINTF("Key %d ",*(pKeyList+i)); 
					 SPRINTF(buff," Key Code    %d ",*(pKeyList+i));
                     STRCAT(pMe->pCloseKeyList,buff);
					 STRCAT(pMe->pCloseKeyList, "\n");
				  }
				}
			}
			else
			{
				DBGPRINTF("FLIP_PARM_KEYLIST not supported");
			}
			FREE(pKeyList); 
		}
	   break;
	   default:
		   break;
   }


   // Display 'Next' on the right bottom screen
   if((pMe->currentAppState != SEC_KEYLIST_OUTPUT_SCR) ||
      (pMe->currentAppState != SECONDARY_SCR))
   {
      IDISPLAY_SetColor(pMe->a.m_pIDisplay,CLR_USER_TEXT,MAKE_RGB(0,0,255));
      if(pMe->currentAppState != NOTICE_SCR)
	  {
	     IDISPLAY_DrawText(pMe->a.m_pIDisplay, 
                        AEE_FONT_NORMAL, L"NEXT", -1, 0, 0, NULL , 
                        IDF_ALIGN_RIGHT|IDF_ALIGN_BOTTOM);
	  }
  	  ISTATIC_Redraw(pMe->pIStatic);
      IDISPLAY_Update(pMe->a.m_pIDisplay);
   }
  
}


// Invoked after displaying notice
static void c_iflipapp_timerCB(void *pIn)
{
   c_iflipapp* pMe = (c_iflipapp*)pIn;
   c_iflipapp_DrawScreen(pMe, PRIMARY_OUTPUT_SCR);
}