#include "alarm.h"
#include <AlarmMgr.h>

Err  SetAlert(UInt32 delay, UInt32 refParam) {
    Err error = errNone;
    UInt32 alarmTime;
    UInt16 cardNo;
    LocalID dbID;
    UInt32 appFileCreator = 'LFhe'; /* must be set to the creator ID for the current program */
    DmSearchStateType searchInfo;

    /* find out what is the local program ID for the current program */
    error = DmGetNextDatabaseByTypeCreator(true, &searchInfo, sysFileTApplication, appFileCreator, true, &cardNo, &dbID);
    if (error!=errNone) return(error);

    /* calculate the alert time */    
    alarmTime = TimGetSeconds() + delay;

    /* set the alert */
    error = AlmSetAlarm(cardNo, dbID, refParam, alarmTime, true);
    return(error);
}



Err  ResetAlert(void) {
    Err error = errNone;
    UInt16 cardNo;
    LocalID dbID;
    UInt32 appFileCreator = 'LFhe'; /* must be set to the creator ID for the current program */
    DmSearchStateType searchInfo;

    error = DmGetNextDatabaseByTypeCreator(true, &searchInfo, sysFileTApplication, appFileCreator, true, &cardNo, &dbID);
    if (error!=errNone) return(error);

    error = AlmSetAlarm(cardNo, dbID, 0, 0, true);
    return(error);
}