// 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 );
}
}
}