rtc class

Dependencies:   RTC8563 mbed

Fork of rtc_class by HIMBED_3AHELI

Date.cpp

Committer:
bulmecisco
Date:
2015-04-23
Revision:
6:ebe2350041f1
Parent:
5:fc8c66a7c87a
Child:
8:54a6f83a2339

File content as of revision 6:ebe2350041f1:

/***********************************
name:   date.cpp    Version: 0.3
author: PE HTL BULME
email:  pe@bulme.at
description:
    Real Time Clock (RTC8563) on HIMBED M0 - LPC11U24 
    class Date inherited from class RTC8563
    Example methode GetDay implemented 
ToDo: 
    implement GetYear, GetMonth;
    Constructor to initialize Date on RTC
    Alarm methode
***********************************/

#include "mbed.h"
#include "Date.h"

// https://developer.mbed.org/teams/HIMBED_3AHELI/code/rtc_func/wiki/Klasse-Date-von-RTC8563-ableiten
uint8_t Date::bcdToUint(uint8_t const nybbles)
{
    uint8_t result;
    result = (nybbles>>4)*10 + (nybbles & 0x0F);
    return result;
}

string Date::toString(uint8_t value)
{
    //return std::to_string(value); // ab C++ version 11
    char buffer[2];
    sprintf (buffer, "%d", value);  // ToString()
    return buffer;
}    

uint8_t Date::GetDay()
{
    uint8_t day = rtc_read(DAYS);
    return bcdToUint(day & 0x3F);
}