Ejemplo n.º 1
0
/*
 * \AUTHOR Vincent & Ian
 */
int openPersistent(alarm_struct *src, int size)
{
	int result = 0;

	unsigned char *storage = (unsigned char *) malloc(sizeof(unsigned char) * size);
	if( storage != NULL )
	{
		At45dbPageRead(0x04, (unsigned char *)storage, size);
		memcpy( (alarm_struct *) src, (unsigned char *)storage, size );

		result = 1;
	}
	free(storage);
	return result;
}
Ejemplo n.º 2
0
/*
 * \AUTHOR Vincent & Ian
 */
void showPage(u_long pgn)
{
	unsigned char *pc = (unsigned char *) malloc(264);
	int idx;
	
	At45dbPageRead(pgn, (unsigned char *)pc, 264);
	for(idx = 0; idx < 264; idx++)
	{
		if( 0 == (idx % 32) )
			printf("\n");
		
		if( isalpha(pc[idx]) || isdigit(pc[idx]) )
		{
			printf("%c  ", pc[idx]);
		}
		else
		{
			printf("%02X ", pc[idx]);
		}
	}
	free(pc);
}
Ejemplo n.º 3
0
THREAD(AlarmPollingThread, arg)
{
    static u_int button_cooldown_counter = 0;
    static bool button_cooldown = true;
    u_long alarm_a;
    u_long alarm_b; 
    short snooze_time;
    tm snooze;
    tm alarm_a_backup;
    
    for(;;)
    {      
        X12RtcGetStatus(&alarm_a);
        alarm_b = alarm_a;
        alarm_a &= 0b00100000;

        alarm_b &= 0b01000000;

        if(alarm_a!=0 && alarm_a_on)
        {
            VsBeep((u_char)500, 1000);              //BeepBoop, beeps with (frequency, duration)
            VsSetVolume(0,0);
            puts("Volume on");
        }

        if(alarm_b!=0 && alarm_b_on)
        {
            VsBeep((u_char)1000, 1000);              //BeepBoop, beeps with (frequency, duration)
            VsSetVolume(0,0);
            puts("Volume on");
        }

        if(button_cooldown_counter >= 2)
        {
            button_cooldown = false;
            button_cooldown_counter = 0;
        }
    
        if(kb_button_is_pressed(KEY_ALT) && alarm_a!=0)
        {
            At45dbPageRead(2, &snooze_time, 2);
            X12RtcClearStatus(0b00100000);
            get_alarm_a(&snooze);
            snooze.tm_min+=snooze_time;
            set_alarm_a(&snooze);
        }
        
        if(!button_cooldown)
        {
            switch(kb_button_pressed())
            {
                case KEY_ESC:
                    puts("escape pressed");
                    if(VsGetVolume() != 0)
                    {
                        puts("volume on");
                        VsSetVolume(0, 0);
                    }
                    else if(VsGetVolume() == 0)  
                    {
                        puts("volume off");
                        VsSetVolume(100, 100);
                    } 
                    if(alarm_a != 0)
                    {
                        X12RtcClearStatus(0b00100000);
                        At45dbPageRead(3, &alarm_a_backup, sizeof(tm));
                        set_alarm_a(&alarm_a_backup);
                    }
                    if(alarm_b != 0)
                    {
                        X12RtcClearStatus(0b01000000);
                        disable_alarm_b();
                        alarm_b_on = false;
                    }
                    break;

                case KEY_01:
                    alarm_a_on = !alarm_a_on;
                    alarmstatus_changed = true;
                    break;

                case KEY_02:
                    alarm_b_on = !alarm_b_on;
                    alarmstatus_changed = true;
                    break;

                default:
                    break;
            }
            button_cooldown = true;
        }
        if(button_cooldown)
                button_cooldown_counter++; 
        NutSleep(100);
    }
}
Ejemplo n.º 4
0
void get_snooze(short* gmt)
{
    At45dbPageRead(2, gmt, 2);
}