C Language Development Kit/Functions/SetAlarm

From OptiWiki

Jump to: navigation, search
Description This function can wake the terminal when is has been turned off.
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:

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 Once the SetAlarm function has been set, it is repeated every 24 hours.

Setting a new time will overwrite the previous set time.

Example
// The following example demonstrates the use of SetAlarm() function.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib.h"
 
void main( void )
{
    struct time at = {0};
    struct time t = {0};
    int pos;
    int key;
    static char string[ 5 + 1];
 
    cursor( ON );
    cursor( NOWRAP );
    resetkey();
 
    for(;;)
    {
        strcpy( string, "00:00");
        pos = 0;
        for(;;)
        {
            printf("\fset alarm\n%s\n\n1=UP \trdone\tr 2=MV", string);
            gotoxy( pos, 1);
            while( ( key = getchar()) == EOF)
                idle();
            if( key == TRIGGER_KEY)
            {
                at.ti_hour = (unsigned char) atoi( string );
                at.ti_min = (unsigned char) atoi( string + 3 );
                at.ti_sec = 0;
                break;
            }
            if( key == Q2_KEY)
            {
                pos++;
                if( pos == 2)
                    pos++;
                if( pos > 4)
                    pos=0;
                continue;
            }
            if( key == Q1_KEY)
            {
                switch( pos )
                {
                    case 0:
                        string[0]++;
                        if( string[0] > '2')
                            string[0] = '0';
                        break;
                    case 1:
                        if( string[0] == '2')
                        {
                            string[1]++;
                            if( string[1] > '4')
                                string[1] = '0';
                        }
                        else
                        {
                            string[1]++;
                            if( string[1] > '9')
                                string[1] = '0';
                        }
                        break;
                    case 3:
                        string[3]++;
                        if( string[3] > '5')
                            string[3] = '0';
                        break;
                    case 4:
                        string[4]++;
                        if( string[4] > '9')
                            string[4] = '0';
                        break;
                }
            }
        }
        SetAlarm( , ON);
        printf("\fAL TIME SET\n%02d:%02d\nwaiting...", at.ti_hour, at.ti_min);
        for(;;)
        {
            gettime(  );
            resetkey();
            //
            // Check to see if terminal is woken by the Alarm function
            //
            if( (t.ti_hour == at.ti_hour) && (t.ti_min == at.ti_min))
            {
                //
                // Wakeup was done by alarm...
                //
                for(;;)
                {
                    printf("\fALARM\nALARM");
                    sound( TSTANDARD, VHIGH, SERROR, SLOW, SMEDIUM, SHIGH, SLOW, SMEDIUM, SHIGH, 0);
                    delay( 50 );
                    putchar('\f');
                    delay( 50 );
                    if( kbhit())
                    {
                        resetkey();
                        break;
                    }
                }
                break;
            }
            delay( 50 );
        }
    }
}


Views
Personal tools