AceTimeClock  1.2.2
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 
24  int16_t toTemperature256() const {
25  return (int16_t) ((msb << 8) | lsb);
26  }
27 
29  void printTo(Print& printer) const {
30  uint8_t m;
31  uint8_t l;
32 
33  int16_t temp = toTemperature256();
34  if (temp < 0) {
35  temp = -temp;
36  m = ((uint16_t) temp) >> 8;
37  l = ((uint16_t) temp) & 0xFF;
38  printer.print('-');
39  } else {
40  m = msb;
41  l = lsb;
42  }
43 
44  uint8_t frac = (uint16_t) l * 100 / 256;
45  printer.print(m);
46  printer.print('.');
47  ace_common::printPad2To(printer, frac, '0');
48  }
49 
51  uint8_t msb;
52 
54  uint8_t lsb;
55 };
56 
61 inline bool operator==(const HardwareTemperature& a,
62  const HardwareTemperature& b) {
63 return a.lsb == b.lsb
64  && a.msb == b.msb;
65 }
66 
68 inline bool operator!=(const HardwareTemperature& a,
69  const HardwareTemperature& b) {
70 return ! (a == b);
71 }
72 
73 }
74 }
75 
76 #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.