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

📄 alarm.c

📁 myTemp is used to connect PalmOS PDAs to Dallas Microlan(tm) Devices. It currently supports DS1820
💻 C
字号:
#include <PalmOS.h>#include "mytempRsc.h"#include "com.h"#include "alarm.h"#include "temp.h"#include "log.h"#define kLogFailIntervall	10void DisplayAlarm(SysDisplayAlarmParamType* cmdPBP) {	Err	err;	UInt32	tempErr;	err = FtrGet(kMyTempID, myTempFtrTempErr, &tempErr);	SndPlaySystemSound(sndError);	/*	error handling, only nonrecoverable errors are displayed, 	since logging stops utnil the user confirms the error*/		switch (tempErr)	{	case tempNoError:		break;	case tempSerErrNotOpen:		FrmCustomAlert(AlarmErrorAlert, "serial not open", NULL, NULL);		break;	case tempSerErrTimeOut:		FrmCustomAlert(AlarmErrorAlert, "serial timeout", NULL, NULL);		break;	case tempSerErrLineErr:		FrmCustomAlert(AlarmErrorAlert, "serial line error", NULL, NULL);		break;	case tempSerErrAlreadyOpen:		FrmCustomAlert(AlarmErrorAlert, "serial already open", NULL, NULL);		break;	case tempSerErrCantOpen:		FrmCustomAlert(AlarmErrorAlert, "serial can't open", NULL, NULL);		break;	case tempSerErrCantClose:		FrmCustomAlert(AlarmErrorAlert, "serial can't close", NULL, NULL);		break;	case tempSerErrLibCantLoad:		FrmCustomAlert(AlarmErrorAlert, "serial can't load lib", NULL, NULL);		break;	case tempSerErrBadParam:		FrmCustomAlert(AlarmErrorAlert, "serial bad parameter", NULL, NULL);		break;	case tempOWErrNothingDetected:		FrmCustomAlert(AlarmWarningAlert, "1-wire nothing detected", NULL, NULL);		break;	case tempErrCRCErr:		FrmCustomAlert(AlarmErrorAlert, "1-wire crc error", NULL, NULL);		break;	case tempErrConvErr:		FrmCustomAlert(AlarmErrorAlert, "1-wire temp conv error", NULL, NULL);		break;	case tempErrUnknownErr:		ErrDisplay("unknown error");		FrmCustomAlert(AlarmErrorAlert, "unknown error", NULL, NULL);		break;	default:		ErrDisplay("unexpected error");		FrmCustomAlert(AlarmErrorAlert, "unexpected error", NULL, NULL);		break;	}}void AlarmTriggered(SysAlarmTriggeredParamType* cmdPBP){/*	wait states before accessing the sensor 	after power up the serial port	and after the ReadTemperature command has been issued*/	const UInt32	tempWaitForState[] = {0, 2, 0, 2, 0, 0, 0};	const UInt32	LogIntervalls[] = kTempLogIntervalls;	UInt32	tempErr;	UInt32	state;	UInt16	serialRefNum;	UInt32	ftrSerialRefNum;	UInt32	logIntervallIndex;	UInt32	numErrors;	UInt32	flags;	volatile UInt32	time;	Int16	temp;	Err		err;		err = FtrGet(kMyTempID, myTempFtrTempState, &state);	err = FtrGet(kMyTempID, myTempFtrTempSerialRefNum, &ftrSerialRefNum);	serialRefNum = ftrSerialRefNum;		tempErr = TempGetTemp(&temp, &state, &serialRefNum);	err = FtrGet(kMyTempID, myTempFtrTempLogIntervallIndex, &logIntervallIndex);	err = FtrGet(kMyTempID, myTempFtrTempErrorCounter, &numErrors);	err = FtrGet(kMyTempID, myTempFtrFlags, &flags);	if (tempErr)	{		state = OpenSerialState;		cmdPBP->purgeAlarm = false;		numErrors++;		SetAlarm(TimGetSeconds() + kLogFailIntervall, 0);	} else {		cmdPBP->purgeAlarm = true;		if (state == TempReadyState)		{			SetAlarm(TimGetSeconds() + LogIntervalls[logIntervallIndex], 0);			state = OpenSerialState;			time = TimGetSeconds();			LogData(0, time, temp);			if (flags & myTempAlarmSndClick)			{				SndPlaySystemSound(sndClick);			}		} else if (state == OpenSerialState) { 		} else {			SetAlarm(TimGetSeconds() + tempWaitForState[state], 0);		}	}		ftrSerialRefNum = serialRefNum;	err = FtrSet(kMyTempID, myTempFtrTempErrorCounter, numErrors);	err = FtrSet(kMyTempID, myTempFtrTempErr, tempErr);	err = FtrSet(kMyTempID, myTempFtrTempSerialRefNum, ftrSerialRefNum);	err = FtrSet(kMyTempID, myTempFtrTempState, state);}UInt32	AlarmStopLogging(void){	Err	err;	UInt32	state;	UInt32	ftrSerialRefNum;	UInt32	tempErr;	UInt16	serialRefNum;		err = FtrGet(kMyTempID, myTempFtrTempState, &state);	err = FtrGet(kMyTempID, myTempFtrTempSerialRefNum, &ftrSerialRefNum);	serialRefNum = ftrSerialRefNum;		tempErr = TempStopLogging(&state, &serialRefNum);		err = FtrSet(kMyTempID, myTempFtrTempState, state);	err = FtrSet(kMyTempID, myTempFtrTempSerialRefNum, ftrSerialRefNum);		return tempErr;}void SetAlarm(UInt32 alarmTime, UInt32 ref) {	UInt16	cardNo;	LocalID	dbID;	DmSearchStateType	searchInfo;			DmGetNextDatabaseByTypeCreator(true, &searchInfo, sysFileTApplication, kMyTempID, true, &cardNo, &dbID);	AlmSetAlarm(cardNo, dbID, ref, alarmTime, true);}UInt32 GetAlarm() {	UInt32	ref = 0;	UInt16	cardNo;	LocalID	dbID;	DmSearchStateType	searchInfo;	DmGetNextDatabaseByTypeCreator(true, &searchInfo, sysFileTApplication, kMyTempID, true, &cardNo, &dbID);	return AlmGetAlarm(cardNo, dbID, &ref);}void CommandNotify(SysNotifyParamType* cmdPBP){	if (cmdPBP->notifyType == sysNotifySleepNotifyEvent)	{	} else if (cmdPBP->notifyType == sysNotifyLateWakeupEvent) {	}}

⌨️ 快捷键说明

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