AceTimeClock  1.3.0
Clock classes for Arduino 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 #include <stdint.h>
10 #include <Print.h> // Print
11 #include <AceCommon.h> // printPad2To
12 
13 namespace ace_time {
14 namespace hw {
15 
23  public:
25  int16_t toTemperature256() const {
26  return (int16_t) ((msb << 8) | lsb);
27  }
28 
30  void printTo(Print& printer) const {
31  uint8_t m;
32  uint8_t l;
33 
34  int16_t temp = toTemperature256();
35  if (temp < 0) {
36  temp = -temp;
37  m = ((uint16_t) temp) >> 8;
38  l = ((uint16_t) temp) & 0xFF;
39  printer.print('-');
40  } else {
41  m = msb;
42  l = lsb;
43  }
44 
45  uint8_t frac = (uint16_t) l * 100 / 256;
46  printer.print(m);
47  printer.print('.');
48  ace_common::printPad2To(printer, frac, '0');
49  }
50 
52  uint8_t msb;
53 
55  uint8_t lsb;
56 };
57 
62 inline bool operator==(const HardwareTemperature& a,
63  const HardwareTemperature& b) {
64 return a.lsb == b.lsb
65  && a.msb == b.msb;
66 }
67 
69 inline bool operator!=(const HardwareTemperature& a,
70  const HardwareTemperature& b) {
71 return ! (a == b);
72 }
73 
74 }
75 }
76 
77 #endif
The temperature in Celcius as a signed (8.8) fixed-point integer.
uint8_t msb
Upper byte of signed (8.8) fixed point temperature.
uint8_t lsb
Lower byte of signed (8.8) fixed point temperature.
void printTo(Print &printer) const
Print HardwareTemperature to 'printer'.
int16_t toTemperature256() const
Return temperature in units of 1/256 degrees.