📄 camera_app.c
字号:
/**
*** camera_app.c
***
*** 偙偺僜乕僗僐乕僪偼丄僄儔乕張棟傗僒僗儁儞僪 / 儗僕儏乕儉張棟傪徣棯偟偰偄傑偡丅
*** 傑偨丄偙偺傾僾儕偼僄儈儏儗乕僞偱偼摦嶌偟傑偣傫丅
*** Copyright (C) 2006 SophiaCradle Incorporated.
*** All rights reserved.
**/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEECamera.h" // Camera interface definitions
#include "AEEStdLib.h" // for DBGPRINTF()
#include "camera_app.bid"
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _camera_app {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
IDisplay *pIDisplay; // give a standard way to access the Display interface
IShell *pIShell; // give a standard way to access the Shell interface
// add your own variables here...
// 僇儊儔娭學偺曄悢
ICamera *_camera; // ICAMERA 僀儞僞乕僼僃僀僗
} camera_app;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean camera_app_HandleEvent(camera_app* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean camera_app_InitAppData(camera_app* pMe);
void camera_app_FreeAppData(camera_app* pMe);
// 僇儊儔娭學偺娭悢
void camera_app_OnCamera(void *pUser, AEECameraNotify *pNotify);
int camera_app_InitializeCamera(camera_app *pMe);
int camera_app_StopCamera(camera_app *pMe);
int camera_app_PreviewCamera(camera_app *pMe);
void camera_app_OnPreview(camera_app *pMe);
// 偦偺懠偺娭悢
void camera_app_OnKey(camera_app *pMe, uint16 key);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;
if( ClsId == AEECLSID_CAMERA_APP )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(camera_app),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)camera_app_HandleEvent,
(PFNFREEAPPDATA)camera_app_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(camera_app_InitAppData((camera_app*)*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 camera_app_HandleEvent(camera_app* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
// Add your code here...
// 婲摦屻偼僇儊儔偺弶婜壔傪峴偄丄僾儗價儏乕傪奐巒
camera_app_InitializeCamera(pMe);
camera_app_PreviewCamera(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...
// 僉乕偑墴偝傟偨偲偒偺張棟
camera_app_OnKey(pMe, wParam);
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 camera_app_InitAppData(camera_app* 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);
// The display and shell interfaces are always created by
// default, so we'll asign them so that you can access
// them via the standard "pMe->" without the "a."
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
// Insert your code here for initializing or allocating resources...
// 僇儊儔娭學偺曄悢偺弶婜壔
pMe->_camera = 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 camera_app_FreeAppData(camera_app* 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
// }
//
// ICamera 僀儞僞乕僼僃僀僗偺夝曻傪峴偆
camera_app_StopCamera(pMe);
}
// 僇儊儔 僀儀儞僩梡僐乕儖僶僢僋娭悢
void camera_app_OnCamera(void *pUser, AEECameraNotify *pNotify)
{
camera_app *pMe = (camera_app *)pUser;
switch (pNotify->nStatus) {
case CAM_STATUS_START: // 僇儊儔偑婲摦偟偨
// 崱夞偼壗傕峴傢側偄
break;
case CAM_STATUS_FRAME: // 怴偨側僼儗乕儉傪庢摼偟偨
// 僾儗價儏乕梡夋憸偑庢摼偱偒偨
camera_app_OnPreview(pMe);
break;
case CAM_STATUS_DONE: // 僇儊儔偑掆巭偟偨
// ICamera 僀儞僞乕僼僃僀僗傪夝曻偡傞
ICAMERA_Release(pMe->_camera);
break;
case CAM_STATUS_FAIL: // 張棟拞偵僄儔乕偑敪惗偟偨
case CAM_STATUS_ABORT: // 張棟偑拞抐偝傟偨
// 崱夞偼壗傕峴傢側偄
break;
}
}
// 僇儊儔偺弶婜壔傪峴偆
int camera_app_InitializeCamera(camera_app *pMe)
{
int result = SUCCESS;
AEESize size;
// 僀儞僗僞儞僗偺惗惉傪峴偆
result = ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_CAMERA, (void **)&(pMe->_camera));
if (result == SUCCESS) {
// 僇儊儔 僀儀儞僩梡僐乕儖僶僢僋娭悢傪搊榐
result = ICAMERA_RegisterNotify(pMe->_camera, camera_app_OnCamera, pMe);
// 僾儗價儏乕 夋憸偺僒僀僘傪愝掕 (昁恵)
// 崱夞偼 QVGA 偵偡傞
size.cx = 240;
size.cy = 320;
ICAMERA_SetDisplaySize(pMe->_camera, &size);
// 昁梫側傜丄僼儗乕儉 儗乕僩偺愝掕傪偙偙偱峴偆
// 師偼 15 fps 偵愝掕偡傞応崌
// ICAMERA_SetFramesPerSecond(pMe->_camera, 15);
}
else {
pMe->_camera = NULL;
}
return result;
}
// 僇儊儔傪掆巭偡傞
int camera_app_StopCamera(camera_app *pMe)
{
return ICAMERA_Stop(pMe->_camera);
}
// 僾儗價儏乕傪奐巒偡傞
int camera_app_PreviewCamera(camera_app *pMe)
{
return ICAMERA_Preview(pMe->_camera);
}
// 僾儗價儏乕梡夋憸偑庢摼偱偒偨偲偒偺張棟
void camera_app_OnPreview(camera_app *pMe)
{
IBitmap *bitmap;
int result = SUCCESS;
// 夋憸傪庢摼
// 偙偺夋憸偼帺暘偱夝曻偟側偗傟偽側傜側偄
result = ICAMERA_GetFrame(pMe->_camera, &bitmap);
if (result != SUCCESS) {
return;
}
// 夋柺偵昤夋偡傞
IDISPLAY_BitBlt(pMe->pIDisplay, 0, 0, pMe->DeviceInfo.cxScreen, pMe->DeviceInfo.cyScreen, bitmap, 0, 0, AEE_RO_COPY);
IDISPLAY_Update(pMe->pIDisplay);
// 夋憸傪夝曻偡傞
IBITMAP_Release(bitmap);
}
// 僉乕偑墴偝傟偨偲偒偺張棟
void camera_app_OnKey(camera_app *pMe, uint16 key)
{
switch (key) {
case AVK_0:
case AVK_POWER:
ISHELL_CloseApplet(pMe->pIShell, FALSE);
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -