⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alarm.c

📁 brew alarm小程序
💻 C
字号:
/*===========================================================================

FILE: alarm.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "alarm.bid"
#include "aeedisp.h"
#include "aee.h"
#include "AEEComdef.h"
#include "AEESTDLIB.h"
#include "AEEMedia.h"
#include "AEEFile.h"
#include "AEEFile.h"
#include "AEEStdLib.h"
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
#ifndef Max
#define Max( x, y ) ( ((x) > (y)) ? (x) : (y) )
#endif
#ifndef Min
#define Min( x, y ) ( ((x) < (y)) ? (x) : (y) )
#endif
typedef struct _alarm {
	AEEApplet      a ;	       // First element of this structure must be AEEApplet
    AEEDeviceInfo  deviceInfo; // always have access to the hardware device information
	IDisplay       *pIDisplay;
	IShell         *pIShell;
	IMedia         *pIMedia;	
	int            playtime;
	int            state;
	int            x;
	int            y;
	int            cxScreen;
	int            cyScreen;
} alarm;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static  boolean alarm_HandleEvent(alarm* pMe, AEEEvent eCode, 
                                             uint16 wParam, uint32 dwParam);
boolean alarm_InitAppData(alarm* pMe);
void    alarm_FreeAppData(alarm* pMe);
void    TimeControl(alarm* pMe);
void    DrawTime(alarm* pMe);
void    DrawRect(alarm* pMe);
void    PlayMusic(alarm* pMe);
void    DrawPict(alarm* pMe);
void    DrawBack(alarm* pMe);

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

	if( ClsId == AEECLSID_ALARM )
	{
		if( AEEApplet_New(sizeof(alarm),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)alarm_HandleEvent,
                          (PFNFREEAPPDATA)alarm_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
                          
		{
			if(alarm_InitAppData((alarm*)*ppObj))
			{
				return(AEE_SUCCESS);
			}
			else
			{
				IAPPLET_Release((IApplet*)*ppObj);
				return EFAILED;
			}

        } 

    }
	return(EFAILED);
}

/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent
===========================================================================*/
static boolean alarm_HandleEvent(alarm* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
		AEERect  rc;
    switch (eCode) 
	{
        case EVT_APP_START:				
			//DrawBack(pMe);
			DrawRect(pMe);
			IDISPLAY_Update(pMe->pIDisplay);	
			TimeControl(pMe);
			ISHELL_SetTimer(pMe->pIShell,5000,PlayMusic,pMe);
			ISHELL_SetTimer(pMe->pIShell,5001,DrawPict,pMe);
			pMe->state = 0;
			//DrawPict(pMe);
            return(TRUE);


        case EVT_APP_STOP:

			ISHELL_CancelTimer(pMe->pIShell,DrawTime,pMe);
			ISHELL_CancelTimer(pMe->pIShell,PlayMusic,pMe);

      		return(TRUE);


        case EVT_APP_SUSPEND:

      		return(TRUE);


        case EVT_APP_RESUME:

      		return(TRUE);

        case EVT_APP_MESSAGE:

      		return(TRUE);

        case EVT_KEY:
			
			IDISPLAY_ClearScreen(pMe->pIDisplay);
			ISHELL_GetDeviceInfo(pMe->pIShell, &pMe->deviceInfo);
			pMe->x = (pMe->deviceInfo.cxScreen - 8)/2;
			pMe->y = (pMe->deviceInfo.cyScreen - 8)/2;
			pMe->cxScreen = pMe->deviceInfo.cxScreen;
			pMe->cyScreen = pMe->deviceInfo.cyScreen;
			SETAEERECT(&rc,pMe->x,pMe->y,8,8);
			IDISPLAY_DrawRect(pMe->pIDisplay,&rc,0xff000000,0x00ff0000,IDF_RECT_FRAME|IDF_RECT_FILL);
			//IDISPLAY_Update(pMe->pIDisplay);

			switch(wParam)
			{
				case AVK_UP:
					pMe->y -= 4;
					break;
				case AVK_DOWN:
					pMe->y += 4;
					break;
				case AVK_LEFT:
					pMe->x -= 4;
					break;
				case AVK_RIGHT:
					pMe->y += 4;
					break;
				default:
					return FALSE;
			}
			pMe->x = Max(0, Min(pMe->x, pMe->cxScreen - 8));
			pMe->y = Max(0, Min(pMe->y, pMe->cyScreen - 8));
			//SETAEERECT(&rc,pMe->x,pMe->y,8,8);
			//IDISPLAY_DrawRect(pMe->a.m_pIDisplay,&rc,0xff000000,0x00ff0000,IDF_RECT_FRAME|IDF_RECT_FILL);
			IDISPLAY_Update (pMe->a.m_pIDisplay);
			pMe->state = 1;
      		return TRUE;

        default:
            break;
   }

   return FALSE;
}

boolean alarm_InitAppData(alarm* pMe)
{
    pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
    ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->deviceInfo);
	pMe->pIDisplay = pMe->a.m_pIDisplay;
	pMe->pIShell = pMe->a.m_pIShell;
 
    return TRUE;
}

void alarm_FreeAppData(alarm* 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
	// }
	//
		if(pMe->pIDisplay != NULL)
		{
			IDISPLAY_Release(pMe->pIDisplay);
				pMe->pIDisplay = NULL;
		}
		if(pMe->pIMedia != NULL)
		{
			AEEMediaData data;
			IMEDIA_Stop(pMe->pIMedia);
			//IMEDIA_GetMediaData(pMe->pIMedia,&data);
			//FREE(data.pData);
			IMEDIA_RegisterNotify(pMe->pIMedia,NULL,NULL);
			IMEDIA_Release(pMe->pIMedia);
			pMe->pIMedia = NULL;
		}
}
void DrawRect(alarm *pMe)
{
	AEERect         rect;
	rect.x= 25;
	rect.y = 100;
	rect.dx = 80;
	rect.dy = 30;
	IDISPLAY_SetColor(pMe->pIDisplay,CLR_USER_BACKGROUND,MAKE_RGB(187,255,255));
	
	IDISPLAY_ClearScreen(pMe->pIDisplay);
//	DrawBack(pMe);
	IDISPLAY_DrawRect(pMe->pIDisplay,&rect,MAKE_RGB(193,255,193),
	MAKE_RGB(221,160,221),IDF_RECT_FRAME|IDF_RECT_FILL|IDF_RECT_FRAME);
}
void TimeControl(alarm *pMe)
{
	pMe->playtime = 0;
	ISHELL_SetTimer(pMe->pIShell,1000,DrawTime,pMe);
	IDISPLAY_Update(pMe->pIDisplay);
}
void DrawTime(alarm *pMe)
{
	int             temp;
	char            time[6];
	AECHAR          nowtime[6];
	pMe->playtime++;
	temp = pMe->playtime/60;
	time[0]=temp/10+'0';
	time[1]=temp%10+'0';
	time[2]=':';
	temp=pMe->playtime%60;
	time[3]=temp/10+'0';
	time[4]=temp%10+'0';
	time[5]=0;
	STRTOWSTR(time,nowtime,12);
	IDISPLAY_ClearScreen(pMe->pIDisplay);
	//DrawBack(pMe);
	DrawRect(pMe);
	IDISPLAY_DrawText(pMe->pIDisplay,AEE_FONT_NORMAL,nowtime,-1,50,110,NULL,IDF_TEXT_TRANSPARENT);
	IDISPLAY_Update(pMe->pIDisplay);
	ISHELL_SetTimer(pMe->pIShell,1000,DrawTime,pMe);
}
void PlayMusic(alarm* pMe)
{	
	AEEMediaData    data;
	byte *pBuffer = NULL;

	ISHELL_CreateInstance(pMe->pIShell,AEECLSID_MEDIAMP3,(void **)&pMe->pIMedia);

	data.clsData = MMD_FILE_NAME;
	data.dwSize = 0;
	data.pData = "feel close to you.mp3";

	IMEDIA_SetMediaData(pMe->pIMedia,&data);
	IMEDIA_Play(pMe->pIMedia);
}
void DrawPict(alarm* pMe)
{
	IImage *pImage;
	AEEImageInfo imageInfo;
	pImage = ISHELL_LoadImage(pMe->pIShell,"c.bmp");
	IIMAGE_GetInfo(pImage,&imageInfo);
	IIMAGE_SetParm(pImage,IPARM_ROP,AEE_RO_TRANSPARENT,0);
	IIMAGE_Draw(pImage,37,30);
	IIMAGE_Release(pImage);
	IDISPLAY_Update(pMe->pIDisplay);
}
void DrawBack(alarm* pMe)
{
	IImage *pImage;
	AEEImageInfo imageInfo;
	pImage = ISHELL_LoadImage(pMe->pIShell,"bb.bmp");
	IIMAGE_GetInfo(pImage,&imageInfo);
	IIMAGE_SetParm(pImage,IPARM_ROP,AEE_RO_TRANSPARENT,0);
	IIMAGE_Draw(pImage,0,0);
	IIMAGE_Release(pImage);
	IDISPLAY_Update(pMe->pIDisplay);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -