Wolfgang Praschk
/
rtc_class2
rtc_class2
Fork of rtc_class by
Date.cpp@11:83c6939656e5, 2015-04-30 (annotated)
- Committer:
- Gm_070
- Date:
- Thu Apr 30 10:54:02 2015 +0000
- Revision:
- 11:83c6939656e5
- Parent:
- 10:83be0e4edb52
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 3:c6081814064d | 1 | #include "mbed.h" |
bulmecisco | 3:c6081814064d | 2 | #include "Date.h" |
bulmecisco | 3:c6081814064d | 3 | |
bulmecisco | 3:c6081814064d | 4 | uint8_t Date::bcdToUint(uint8_t const nybbles) |
bulmecisco | 3:c6081814064d | 5 | { |
bulmecisco | 3:c6081814064d | 6 | uint8_t result; |
bulmecisco | 3:c6081814064d | 7 | result = (nybbles>>4)*10 + (nybbles & 0x0F); |
bulmecisco | 3:c6081814064d | 8 | return result; |
bulmecisco | 3:c6081814064d | 9 | } |
bulmecisco | 3:c6081814064d | 10 | |
bulmecisco | 4:a4d39c018c65 | 11 | string Date::toString(uint8_t value) |
bulmecisco | 4:a4d39c018c65 | 12 | { |
bulmecisco | 4:a4d39c018c65 | 13 | char buffer[2]; |
Gm_070 | 11:83c6939656e5 | 14 | sprintf (buffer, "%d", value); |
bulmecisco | 4:a4d39c018c65 | 15 | return buffer; |
bulmecisco | 4:a4d39c018c65 | 16 | } |
bulmecisco | 4:a4d39c018c65 | 17 | |
bulmecisco | 3:c6081814064d | 18 | uint8_t Date::GetDay() |
bulmecisco | 3:c6081814064d | 19 | { |
bulmecisco | 3:c6081814064d | 20 | uint8_t day = rtc_read(DAYS); |
bulmecisco | 3:c6081814064d | 21 | return bcdToUint(day & 0x3F); |
bulmecisco | 9:54a6f83a2339 | 22 | } |
bulmecisco | 9:54a6f83a2339 | 23 | uint8_t Date::GetDay(int value) |
bulmecisco | 9:54a6f83a2339 | 24 | { |
bulmecisco | 9:54a6f83a2339 | 25 | return value; |
bulmecisco | 9:54a6f83a2339 | 26 | } |
bulmecisco | 9:54a6f83a2339 | 27 | string Date::GetDay(string str) |
bulmecisco | 9:54a6f83a2339 | 28 | { |
bulmecisco | 9:54a6f83a2339 | 29 | string day = str + " In Date Day: " + toString(GetDay()); |
bulmecisco | 9:54a6f83a2339 | 30 | return day; |
bulmecisco | 3:c6081814064d | 31 | } |