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

📄 clocktimer.cpp

📁 国内著名嵌入式培训机构内部资料,内含一些实例代码,包括技术专题书籍
💻 CPP
字号:
/*
 ============================================================================
 Name		: ClockTimer.cpp
 Author	  : hou maoqing
 Version	 : 1.0
 Copyright   : Copyright (c) Hou maoqing 2008
 Description : CClockTimer implementation
 ============================================================================
 */

#include "ClockTimer.h"
#include "ActiveObjectExam.h"
#include <e32cons.h>			// Console

CClockTimer::CClockTimer() :
	CActive(EPriorityStandard) // Standard priority
	{
	}

CClockTimer* CClockTimer::NewLC()
	{
	CClockTimer* self = new ( ELeave ) CClockTimer();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CClockTimer* CClockTimer::NewL()
	{
	CClockTimer* self = CClockTimer::NewLC();
	CleanupStack::Pop(); // self;
	return self;
	}

void CClockTimer::ConstructL()
	{
	User::LeaveIfError(iTimer.CreateLocal() ); // Initialize timer
	CActiveScheduler::Add( this); // Add to scheduler
	}

CClockTimer::~CClockTimer()
	{
	Cancel(); // Cancel any request, if outstanding
	iTimer.Close(); // Destroy the RTimer object
	// Delete instance variables if any
	}

void CClockTimer::DoCancel()
	{
	iTimer.Cancel();
	}

void CClockTimer::StartL(TTimeIntervalMicroSeconds32 aDelay)
	{
	m_nExitCount=5;
	Cancel(); // Cancel any request, just to be sure
	iState = EUninitialized;
	iTimer.After(iStatus, aDelay); // Set for later
	SetActive(); // Tell scheduler a request is active
	}

void CClockTimer::RunL()
	{
	m_nExitCount--;
	if(m_nExitCount<0)
		{
		CActiveScheduler::Stop();
		return;
		}
	
	if (iState == EUninitialized)
		{
		// Do something the first time RunL() is called
		iState = EInitialized;
		}
	else
		if (iState != EError)
			{
			// Do something
			}
	
	//GetConsole()->Write(_L("Hello, world!\n"));
	TTime tCur;
	tCur.HomeTime();
	
	TBuf<256> timeAsText;
	_LIT ( KTimeFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3 %H:%T:%S \n" );
	tCur.FormatL( timeAsText, KTimeFormat );
	
	
	GetConsole()->Write(timeAsText);
	
	iTimer.After(iStatus, 1000000); // Set for 1 sec later
	SetActive(); // Tell scheduler a request is active
	}

TInt CClockTimer::RunError(TInt aError)
	{
	return aError;
	}

⌨️ 快捷键说明

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