Dino Martic / RTC-DS1307

Dependents:   Detektor_Pokreta Dino_Martic_Programski

RtcCls.h

Committer:
leihen
Date:
2013-06-23
Revision:
6:bba89618ee63
Parent:
5:30531f2121a2

File content as of revision 6:bba89618ee63:

/* RtcCls.h */
/*
Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef __RTCCLS_H__
#define __RTCCLS_H__


#include "Rtc_Ds1307.h"

typedef void (*RtcCallback_t) (void);


class RtcCls : public Rtc_Ds1307
{
protected:
    InterruptIn                 m_sqw;
    bool                        m_bUseSqw;
    time_t                      m_time;             //  Only used in case SQW is used
    
    bool                        m_bAlarmEnabled;
    RtcCallback_t               m_alarmfunc;
    time_t                      m_alarmTime;
    
public:
    RtcCls(PinName sda, PinName scl, PinName sqw, bool bUseSqw);
    
protected:
    static void _callback(void);
    
public:
    time_t                      getTime();
    void                        setTime(time_t t);
public:
    void                        setAlarm(int nSeconds, RtcCallback_t alarmfunc) {
        m_alarmfunc = alarmfunc;
        m_alarmTime = m_time + nSeconds;
        m_bAlarmEnabled = (alarmfunc == NULL) ? false : true;
    }
};

#endif //   __RTCCLS_H__