SetAlarm

Availability All terminals
Description This function can wake up the device at a specific time.
Syntax void SetAlarm( struct time *timep, unsigned short onoff );
Arguments
struct time *timep
A pointer to a time structure that defines the time when the alarm has to go off.
The time structure is defined as follows:
struct time
{
    unsigned char ti_hour;  // hours
    unsigned char ti_min;   // minutes
    unsigned char ti_sec;   // seconds
};
unsigned short onoff
onoff is a variable that defines whether the alarm should go off at the selected time.
ON Let the alarm function go off at the selected time.
OFF Disables the SetAlarm function.
Returns None
Remarks
  • After the alarm has occured, the alarm is cleared, so IsAlarmOn returns FALSE.
  • If the alarm occurs during power off state, the alarm will boot device from power off state
  • If the alarm occurs during power down (sleep) state, the alarm will wake-up from sleep
  • SetAlarm does not possess resolution to seconds. So your alarm must be set for 1 minute in the future or more.
  • Example
    // The following example demonstrates the use of SetAlarm() function.
    #include <stdio.h>
    #include "lib.h"
    
    void main( void )
    {
        struct time at = {0};
        bool alarmOn = false;
    
        AutoPowerDown(ON, 2*50); // 2 seconds
    
        AutoPowerDown(APD_SHUTDOWN_ON, 60*50);  // Alarm will boot device from off state
        // AutoPowerDown(APD_SHUTDOWN_OFF, 0);  // Alarm will wake-up device from sleep
    
        Sound(TSTANDARD, VHIGH, SLOW, SMEDIUM, SHIGH, SLOW, SMEDIUM, SHIGH, 0); // 6 tones: Start-up beep
    
        for(;;)
        {
            if(getchar() != EOF)
            {
                GoodReadLed(GREEN_FLASH, 0);
                GetTime(&at);
                at.ti_min = (at.ti_min+2) % 60; // Set alarm 2 minutes in the future
                at.ti_hour += (at.ti_min < 2) ? 1 : 0;
                SetAlarm(&at, ON);
                alarmOn = true;
                Sound(TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0); // 2 tones: alarm set
                printf("\rALARM SET\r%02d:%02d\rwaiting...", at.ti_hour, at.ti_min);
            }
    
            // Check to see if terminal is woken by the Alarm function
            if(alarmOn != IsAlarmOn())
            {
                alarmOn = false;
                Sound( TSTANDARD, VHIGH, SLOW, SMEDIUM, SHIGH, 0);  // 3 tones: wake from alarm beep
                GoodReadLed(GREEN_FLASH, 30*50);
            }
    
            Idle();
        }
    }