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.
HardwareTemperature.h
1 #ifndef ACE_TIME_HW_TEMPERATURE_H
2 #define ACE_TIME_HW_TEMPERATURE_H
3 
4 #if defined(ARDUINO)
5 
6 #include <stdint.h>
7 #include <Print.h> // Print
8 #include "../common/util.h" // printPad2
9 
10 namespace ace_time {
11 namespace hw {
12 
19 struct HardwareTemperature {
21  int16_t toTemperature256() const {
22  return (int16_t) ((msb << 8) | lsb);
23  }
24 
26  void printTo(Print& printer) const {
27  uint8_t m;
28  uint8_t l;
29 
30  int16_t temp = toTemperature256();
31  if (temp < 0) {
32  temp = -temp;
33  m = ((uint16_t) temp) >> 8;
34  l = ((uint16_t) temp) & 0xFF;
35  printer.print('-');
36  } else {
37  m = msb;
38  l = lsb;
39  }
40 
41  uint8_t frac = (uint16_t) l * 100 / 256;
42  printer.print(m);
43  printer.print('.');
44  common::printPad2(printer, frac);
45  }
46 
47  uint8_t msb;
48  uint8_t lsb;
49 };
50 
55 inline bool operator==(const HardwareTemperature& a,
56  const HardwareTemperature& b) {
57 return a.lsb == b.lsb
58  && a.msb == b.msb;
59 }
60 
62 inline bool operator!=(const HardwareTemperature& a,
63  const HardwareTemperature& b) {
64 return ! (a == b);
65 }
66 
67 }
68 }
69 
70 #endif
71 
72 #endif