rtc class

Dependencies:   RTC8563 mbed

Fork of rtc_class by HIMBED_3AHELI

Committer:
bulmecisco
Date:
Thu Apr 23 10:43:38 2015 +0000
Revision:
8:54a6f83a2339
Parent:
6:ebe2350041f1
Child:
9:83be0e4edb52
5. Ueberladene Methoden in Klasse Date und using::GetDay in Klasse Datestring

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bulmecisco 5:fc8c66a7c87a 1 /***********************************
bulmecisco 6:ebe2350041f1 2 name: date.cpp Version: 0.3
bulmecisco 5:fc8c66a7c87a 3 author: PE HTL BULME
bulmecisco 5:fc8c66a7c87a 4 email: pe@bulme.at
bulmecisco 5:fc8c66a7c87a 5 description:
bulmecisco 5:fc8c66a7c87a 6 Real Time Clock (RTC8563) on HIMBED M0 - LPC11U24
bulmecisco 5:fc8c66a7c87a 7 class Date inherited from class RTC8563
bulmecisco 5:fc8c66a7c87a 8 Example methode GetDay implemented
bulmecisco 5:fc8c66a7c87a 9 ToDo:
bulmecisco 5:fc8c66a7c87a 10 implement GetYear, GetMonth;
bulmecisco 5:fc8c66a7c87a 11 Constructor to initialize Date on RTC
bulmecisco 5:fc8c66a7c87a 12 Alarm methode
bulmecisco 5:fc8c66a7c87a 13 ***********************************/
bulmecisco 5:fc8c66a7c87a 14
bulmecisco 3:c6081814064d 15 #include "mbed.h"
bulmecisco 3:c6081814064d 16 #include "Date.h"
bulmecisco 3:c6081814064d 17
bulmecisco 5:fc8c66a7c87a 18 // https://developer.mbed.org/teams/HIMBED_3AHELI/code/rtc_func/wiki/Klasse-Date-von-RTC8563-ableiten
bulmecisco 3:c6081814064d 19 uint8_t Date::bcdToUint(uint8_t const nybbles)
bulmecisco 3:c6081814064d 20 {
bulmecisco 3:c6081814064d 21 uint8_t result;
bulmecisco 3:c6081814064d 22 result = (nybbles>>4)*10 + (nybbles & 0x0F);
bulmecisco 3:c6081814064d 23 return result;
bulmecisco 3:c6081814064d 24 }
bulmecisco 3:c6081814064d 25
bulmecisco 4:a4d39c018c65 26 string Date::toString(uint8_t value)
bulmecisco 4:a4d39c018c65 27 {
bulmecisco 4:a4d39c018c65 28 //return std::to_string(value); // ab C++ version 11
bulmecisco 4:a4d39c018c65 29 char buffer[2];
bulmecisco 4:a4d39c018c65 30 sprintf (buffer, "%d", value); // ToString()
bulmecisco 4:a4d39c018c65 31 return buffer;
bulmecisco 4:a4d39c018c65 32 }
bulmecisco 4:a4d39c018c65 33
bulmecisco 3:c6081814064d 34 uint8_t Date::GetDay()
bulmecisco 3:c6081814064d 35 {
bulmecisco 3:c6081814064d 36 uint8_t day = rtc_read(DAYS);
bulmecisco 3:c6081814064d 37 return bcdToUint(day & 0x3F);
bulmecisco 8:54a6f83a2339 38 }
bulmecisco 8:54a6f83a2339 39 // ueberladene Methoden von GetDay
bulmecisco 8:54a6f83a2339 40 uint8_t Date::GetDay(int value)
bulmecisco 8:54a6f83a2339 41 {
bulmecisco 8:54a6f83a2339 42 return value;
bulmecisco 8:54a6f83a2339 43 }
bulmecisco 8:54a6f83a2339 44 string Date::GetDay(string str)
bulmecisco 8:54a6f83a2339 45 {
bulmecisco 8:54a6f83a2339 46 string day = str + " In Date Day: " + toString(GetDay());
bulmecisco 8:54a6f83a2339 47 return day;
bulmecisco 3:c6081814064d 48 }