Steps involved to create Camera Api Program and it is working | developer.brewmp.com Steps involved to create Camera Api Program and it is working | developer.brewmp.com

Developer

Steps involved to create Camera Api Program and it is working

Forums:

I attached my Camera Application in this thread. For running this apllication we need to Check

1. The device supports Camera which is in the Data Sheet of the device.

2. Web Camera is Important.

3. Create the Mif file for your application. Again open the Mif file by thr Mif editor in which goto Dependencies tab in that their is a title : External Class used by this Module in that list select CAMERA1 and press ADD save that.

This is coding for ICamera Api. IF any problem ask me.

FILE: cameraapp.c
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEStdlib.h"

#include "AEECamera.h" // Camera interface definitions
#include "AEEDisp.h " // Display interface definitions

#include "AEEFile.h" // File interface definitions

#include "cameraapp.bid"

/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
typedef struct _cameraapp {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information

// add your own variables here...
ICamera * m_pICamera;
IDisplay * m_pIDisplay;
IBitmap * m_pIBitMap;

AEESize m_sizeFrame,m_sizePreview;

} cameraapp,CApp;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean cameraapp_HandleEvent(cameraapp* pMe,
AEEEvent eCode, uint16 wParam,
uint32 dwParam);
boolean cameraapp_InitAppData(cameraapp* pMe);
void cameraapp_FreeAppData(cameraapp* pMe);
static int CApp_StartCameraInPreviewMode(CApp * pMe);
static void CApp_CameraNotify(void * , AEECameraNotify *);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;

if( ClsId == AEECLSID_CAMERAAPP )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(cameraapp),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)cameraapp_HandleEvent,
(PFNFREEAPPDATA)cameraapp_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function

{
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(cameraapp_InitAppData((cameraapp*)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}

} // end AEEApplet_New

}

return(EFAILED);

/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent

DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.

PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.

ecode: Specifies the Event sent to this applet

wParam, dwParam: Event specific data.

DEPENDENCIES
none

RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event

SIDE EFFECTS
none
===========================================================================*/
static boolean cameraapp_HandleEvent(cameraapp* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{

switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
// Add your code here...

/*IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_BOLD, L"Sample Camera Appliocation", -1, 0,0, NULL, IDF_ALIGN_TOP|IDF_ALIGN_CENTER );
IDISPLAY_Update(pMe->a.m_pIDisplay);*/
CApp_StartCameraInPreviewMode(pMe);
return(TRUE);

// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...

return(TRUE);

// App is being suspended
case EVT_APP_SUSPEND:
// Add your code here...

return(TRUE);

// App is being resumed
case EVT_APP_RESUME:
// Add your code here...

return(TRUE);

// An SMS message has arrived for this app. Message is in the dwParam above as (char *)
// sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
// Add your code here...

return(TRUE);

// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
case EVT_KEY:
// Add your code here...

return(TRUE);

// If nothing fits up to this point then we'll just break out
default:
break;
}

return FALSE;

// this function is called when your application is starting up
boolean cameraapp_InitAppData(cameraapp* pMe)
{
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);

// Insert your code here for initializing or allocating resources...

pMe->m_sizePreview.cx = 120;
pMe->m_sizePreview.cy = 150;

pMe->m_pIDisplay = pMe->a.m_pIDisplay;
pMe->m_pICamera = NULL;

// if there have been no failures up to this point then return success
return TRUE;

// this function is called when your application is exiting
void cameraapp_FreeAppData(cameraapp* pMe)
{
// insert your code here for freeing any resources you have allocated...

// example to use for releasing each interface:
// if ( pMe->pIMenuCtl != NULL ) // check for NULL first
// {
// IMENUCTL_Release(pMe->pIMenuCtl) // release the interface
// pMe->pIMenuCtl = NULL; // set to NULL so no problems trying to free later
// }
//

}

static int CApp_StartCameraInPreviewMode(CApp * pme)
{
int nErr;
int nRet;
boolean bTrue;

IBitmap * pFrame;
AEEBitmapInfo bi;

// Create ICamera instance.

nErr = ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_CAMERA, (void **)&pme->m_pICamera);
if (nErr)
return nErr;
// Register callback notification function.
nRet = ICAMERA_RegisterNotify(pme->m_pICamera, CApp_CameraNotify, pme);
if (nErr)
return nErr;

nErr = ICAMERA_SetDisplaySize(pme->m_pICamera, &pme->m_sizePreview);
if(nErr)
return nErr;

/*nErr = ICAMERA_IsSupport(pme->m_pICamera, CAM_PARM_PREVIEW_TYPE, &bTrue);
if(bTrue)
return nErr;

nErr = ICAMERA_IsSupport(pme->m_pICamera, CAM_PREVIEW_SNAPSHOT, &bTrue);
if(!bTrue)
return nErr;*/

/*nErr = ICAMERA_SetParm(pme->m_pICamera, CAM_PARM_PREVIEW_TYPE, CAM_PREVIEW_SNAPSHOT, 0);
if (nErr)
return nErr;*/

pme->m_sizeFrame.cx = 130;
pme->m_sizeFrame.cy = 150;

ICAMERA_SetSize( pme->m_pICamera, &pme->m_sizeFrame);

nErr = ICAMERA_Preview(pme->m_pICamera);
if (nErr != SUCCESS)
return nErr;

return SUCCESS;
}

static void CApp_CameraNotify(void * pUser, AEECameraNotify * pn)
{
CApp * pme = (CApp *)pUser;

DBGPRINTF( "\n Inside Notify\n" );
if (!pme || !pn)
return;
switch (pn->nStatus)
{
case CAM_STATUS_START:
// Preview has begun...
DBGPRINTF( "\n Inside START\n" );
break;
case CAM_STATUS_FRAME:
{
IBitmap * pFrame;
AEEBitmapInfo bi;

//
// IMPORTANT NOTE: You need to do IBITMAP_Release(pFrame) after you're done with pFrame.
//
DBGPRINTF( "\n Inside Display\n" );
if (SUCCESS != ICAMERA_GetFrame(pme->m_pICamera, &pFrame))
return;
// Get the bitmap info...this can be saved in app global structure.
IBITMAP_GetInfo(pFrame, &bi, sizeof(bi));
// Display the frame at (0, 0) location of the screen
IDISPLAY_BitBlt(pme->a.m_pIDisplay, 0, 0, bi.cx, bi.cy, pFrame, 0, 0, AEE_RO_COPY);
IDISPLAY_Update(pme->a.m_pIDisplay);
IBITMAP_Release(pFrame);
break;
}

case CAM_STATUS_DONE:
// ICAMERA_Stop() was called and preview operation stopped.
DBGPRINTF( "CAM_STATUS_DONE\n" );

break;
case CAM_STATUS_ABORT:
// Preview got aborted.
DBGPRINTF( "CAM_STATUS_ABORT\n" );

break;
}

Hello,
Im sorry i could not get your point that "select CAMERA1" from you third point. Would you make it clear so that i can get your point.
Waiting for you fast reply.
Thank you & have a nice day.

Hello,
Im sorry i could not get your point that "select CAMERA1" from you third point. Would you make it clear so that i can get your point.
Waiting for you fast reply.
Thank you & have a nice day.

Hello,
Im new in BREW. Im writing an camera application for Motorola V710. I hav written code and as we press select key, i have capturde the image using RecordSnapshot( ) it is returning EBADSTATE first time and as we press the same key it returns 0 (i.e. SUCCESS). Means on pressing the button twice it is capturing the image. Why so? please help me. Im not getting the exact reason behind this.
Thank you.
Have a great day...

Hello,
Im new in BREW. Im writing an camera application for Motorola V710. I hav written code and as we press select key, i have capturde the image using RecordSnapshot( ) it is returning EBADSTATE first time and as we press the same key it returns 0 (i.e. SUCCESS). Means on pressing the button twice it is capturing the image. Why so? please help me. Im not getting the exact reason behind this.
Thank you.
Have a great day...