AceTime  0.5.2
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 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_HW_TEMPERATURE_H
7 #define ACE_TIME_HW_TEMPERATURE_H
8 
9 #if defined(ARDUINO)
10 
11 #include <stdint.h>
12 #include <Print.h> // Print
13 #include "../common/util.h" // printPad2
14 
15 namespace ace_time {
16 namespace hw {
17 
24 struct HardwareTemperature {
26  int16_t toTemperature256() const {
27  return (int16_t) ((msb << 8) | lsb);
28  }
29 
31  void printTo(Print& printer) const {
32  uint8_t m;
33  uint8_t l;
34 
35  int16_t temp = toTemperature256();
36  if (temp < 0) {
37  temp = -temp;
38  m = ((uint16_t) temp) >> 8;
39  l = ((uint16_t) temp) & 0xFF;
40  printer.print('-');
41  } else {
42  m = msb;
43  l = lsb;
44  }
45 
46  uint8_t frac = (uint16_t) l * 100 / 256;
47  printer.print(m);
48  printer.print('.');
49  common::printPad2(printer, frac);
50  }
51 
52  uint8_t msb;
53  uint8_t lsb;
54 };
55 
60 inline bool operator==(const HardwareTemperature& a,
61  const HardwareTemperature& b) {
62 return a.lsb == b.lsb
63  && a.msb == b.msb;
64 }
65 
67 inline bool operator!=(const HardwareTemperature& a,
68  const HardwareTemperature& b) {
69 return ! (a == b);
70 }
71 
72 }
73 }
74 
75 #endif
76 
77 #endif