コード例 #1
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief Clears AlarmA or AlarmB
 * 
 * \param ID     A or B - witch alarm must be cleared
 * 
 * \author Matthijs
 */
void ClearAlarm(char ID)
{
    if(ID == 'a')
    {
        X12RtcSetAlarm(0,NULL, 63);
    }
    
    if(ID == 'b')
    {
        X12RtcSetAlarm(1,NULL, 63);
    }
}
コード例 #2
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief sets AlarmB
 * 
 * \param alarm         : alarmBStruct of a alarm to set
 * 
 * \param index         : the index of the alarm
 * 
 * \author Matthijs
 */
void setAlarmB(alarmBStruct alarm, int index)
{
    alarmBArray[index] = alarm;
    alarmBStruct toSet = checkFirst();
	currentAlarm = toSet;
    X12RtcSetAlarm(1, &toSet.timeSet, 31);
}
コード例 #3
0
ファイル: rtc.c プロジェクト: Jordyderuijter/JTI2.3A4
/**
 * 
 * @param time, sets alarm B on time, in years, months, days, hours and minutes
 */
void set_alarm_b(tm* time)
{
    //time->tm_mon += 1;          // This should be added because the received date has a [0 - 11] range.
    
    X12RtcSetAlarm(1, time, 0b00011110);
    alarm_b_on = 1;
    alarmstatus_changed = true;
}
コード例 #4
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief sets AlarmA
 * 
 * \param hours        : 0 - 23 hours from midnight
 * 
 * \param minutes      : 0 - 59 minutes in hour
 * 
 * \param seconds     : 0 - 59 seconds in minutes
 * 
 * \author Matthijs
 */
void setAlarmA(int hours, int minutes, int seconds)
{
    tm alarmA;
    
    alarmA.tm_hour = hours;
    alarmA.tm_min = minutes;
    alarmA.tm_sec = seconds;
    
    // flags 7 becaus that is sec, min, hours in binary
    int succes = X12RtcSetAlarm(0, &alarmA, 7);
    
    if(succes == 0)
    {
          //goed
    }
    else
    {
        //fout
    }
}
コード例 #5
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief Initialize the interface to an Intersil X12xx hardware clock.
 *
 * \deprecated New applications must use NutRegisterRtc().
 *
 * \return 0 on success or -1 in case of an error.
 *
 */
int X12Init(void)
{
    int rc;
    u_long tmp;

    if ((rc = TwInit(0)) == 0)
    {
        rc = X12RtcGetStatus(&tmp);
    }
    
    // loading ands setting the alarm
    createAlarms();
    //load();
    alarmBStruct first = checkFirst();
	currentAlarm = first;
    X12RtcSetAlarm(1, &first.timeSet, 31);
    
	startAlarmThread();
    return (rc);
}
コード例 #6
0
ファイル: rtc.c プロジェクト: Jordyderuijter/JTI2.3A4
void disable_alarm_b()
{
    tm dummy;
    X12RtcSetAlarm(1, &dummy, 0b00000000);
}
コード例 #7
0
ファイル: rtc.c プロジェクト: Jordyderuijter/JTI2.3A4
/**
 * 
 * @param time, sets alarm A on time, in hours and minutes
 */
void set_alarm_a(tm* time)
{
    X12RtcSetAlarm(0, time, 0b00000110);
    alarm_a_on = 1;
    alarmstatus_changed = true;
}
コード例 #8
0
ファイル: alarm.c プロジェクト: yorickr/TI2A5
/*
* \param aflgs Each bit enables a specific comparision.
*              - Bit 0: Seconds
*              - Bit 1: Minutes
*              - Bit 2: Hours
*              - Bit 3: Day of month
*              - Bit 4: Month
*              - Bit 7: Day of week (Sunday is zero)
*/
void set_alarm(int alarmid, tm time){
    int flags = 0b00000110; // minutes, hours
    X12RtcSetAlarm(alarmid, &time, flags);
}
コード例 #9
0
ファイル: rtc.c プロジェクト: Tregan/JTI-2.3-A3-IMC
/*!
 * \brief thread that checks the alarms every 10 seconds
 * 
 * \author Matthijs
 */
THREAD(AlarmThread, args)
{
    //time struct datetime can't be found when placed in main.h
    tm datetime;
    u_long flags;
       
    X12RtcGetClock(&datetime);
    
    for(;;)
    {
        int succes = X12RtcGetStatus(&flags);
        int i;
        
        for(i = 0; i <=10; i++)
        {
                NutSleep(1000);
        }
        
        //power fail
        if(flags == 0)
        {
            //printf("\n ========== Power Fail ========== \n");
            X12RtcClearStatus(0);
        }

        //alarm A
        if(flags == 32)
        {
            printf("\n ========== Alarm 0 =========== \n");       


            //get current alarm time to compare to the weekendtime, if weekendtime is
            //equal to currentAlarm and the day of the week is friday. The alarm should
            //not go off.
            tm currentAlarm;
            int iets = 0;
            X12RtcGetAlarm(0, &currentAlarm, &iets);

            int alarmASeconds = 0;
            alarmASeconds = (currentAlarm.tm_hour * 360) + (currentAlarm.tm_min * 6) + (currentAlarm.tm_sec / 10);

            int weekendtimeSeconds = 0;
            weekendtimeSeconds = (weekendtime.hour * 360) + (weekendtime.minute * 6) + (weekendtime.second / 10);


            printf("\nalarmASeconds: %d, weekendtimeSeconds: %d", alarmASeconds, weekendtimeSeconds);
            if((alarmASeconds != weekendtimeSeconds) && checkWeekend() == 1)
            {
                printf("\nHet is VRIJDAG!!! alarm is niet gelijk aan de weekendtijd en moet dus nog geset worden\n SOUND IS PLAYING");
                //SoundA();
                startSnoozeThreadA();
            }
            else if(((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 3)))
            {
                printf("\nalarm is niet gelijk aan de weekendtijd en het is weekend, dus set");
            }
            else if(((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 3)))
            {
                printf("\nalarm is gelijk aan de weekendtijd en het is weekend,\n SOUND IS PLAYING");
                //SoundA();
                startSnoozeThreadA();

                //if the alarm goes off and it is sunday set the alarm back to its
                //original settings
                if(checkWeekend() == 3)
                {
                    printf("het is blijkbaar zondag dus terug naar doordeweekse tijd");
                    setAlarmA(alarmA.tm_hour, alarmA.tm_min, alarmA.tm_sec);
                }
            }
            else if(checkWeekend() == 0)
            {
                printf("\nhet is doordeweeks,\nSOUND IS PLAYING");
                startSnoozeThreadA();
                //SoundA();
            }
            //else
            //{
            //	printf("weekendAlarm gaat af!!!");
            //}

            //when checkWeekend returns 1(Friday) or 2(Saturday) it means that it
            //will be weekend the next day. Therefore we set the alarm to the weekend
            //settings. Problem is that most likely the alarm in the weekends will go
            //off later then it would during the week. This problem is solved underneath
            //the if(checkWeekend() == 3){}.
            int currentTime = (datetime.tm_hour * 360) + (datetime.tm_min * 6) + (datetime.tm_sec / 10);

            if(checkWeekend() > 0 && checkWeekend() < 3)
            {
                printf("alarmA set to weekend time");
                setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second);
            }
            else if(checkWeekend() == 3 && (currentTime <= weekendtimeSeconds))
            {
                setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second);
            }

            X12RtcClearStatus(32);
        }

        //alarm B
        if(flags == 64)
        {
            printf("\n ============ Alarm 1================== \n");
           
            startSnoozeThreadB();
            ClearAlarm('b');
            X12RtcClearStatus(64);
			alarmBArray[currentAlarm.index].set = 0;
            alarmBStruct newSet = checkFirst();
            X12RtcSetAlarm(1, &newSet.timeSet, 31);
            currentAlarm = newSet;
        }

        //both alarms
        if(flags == 96)
        {
            //kijkt of alarm a of b nog niet heeft geluid, en speelt die dan
            printf("\n ========== Alarm 0 en 1  ========= \n");
            //kijkt welke van de 2 nog niet is afgegaan en speelt die dan nog af
            SoundA();  
            X12RtcClearStatus(32);
            SoundB();
            X12RtcClearStatus(64);
        }

        if(succes == 0)
        {
            //succes
        }
        else
        {
            //error
        }
    }
}