AceTime  0.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
util.h
1 #ifndef ACE_TIME_COMMON_UTIL_H
2 #define ACE_TIME_COMMON_UTIL_H
3 
4 #include <stdint.h>
5 #include <Print.h>
6 
7 namespace ace_time {
8 namespace common {
9 
14 template<typename T>
15 void incrementMod(T& d, T m) {
16  d++;
17  if (d >= m) d = 0;
18 }
19 
24 template<typename T>
25 void incrementMod(T& d, T m, T offset) {
26  d -= offset;
27  d++;
28  if (d >= m) d = 0;
29  d += offset;
30 }
31 
33 inline uint8_t decToBcd(uint8_t val) {
34  return (val/10*16) + (val%10);
35 }
36 
38 inline uint8_t bcdToDec(uint8_t val) {
39  return (val/16*10) + (val%16);
40 }
41 
43 inline void printPad2(Print& printer, uint8_t value, char padChar = '0') {
44  if (value < 10) printer.print(padChar);
45  printer.print(value);
46 }
47 
49 inline void printPad3(Print& printer, uint16_t val, char padChar = '0') {
50  if (val < 100) printer.print(padChar);
51  if (val < 10) printer.print(padChar);
52  printer.print(val);
53 }
54 
55 }
56 }
57 
58 #endif