AceTime  1.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 /*
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 
50  uint8_t msb;
51  uint8_t lsb;
52 };
53 
58 inline bool operator==(const HardwareTemperature& a,
59  const HardwareTemperature& b) {
60 return a.lsb == b.lsb
61  && a.msb == b.msb;
62 }
63 
65 inline bool operator!=(const HardwareTemperature& a,
66  const HardwareTemperature& b) {
67 return ! (a == b);
68 }
69 
70 }
71 }
72 
73 #endif
ace_time::hw::HardwareTemperature
The temperature in Celcius as a signed (8.8) fixed-point integer.
Definition: HardwareTemperature.h:22
ace_time::hw::HardwareTemperature::toTemperature256
int16_t toTemperature256() const
Return temperature in units of 1/256 degrees.
Definition: HardwareTemperature.h:24
ace_time::hw::HardwareTemperature::printTo
void printTo(Print &printer) const
Print HardwareTemperature to 'printer'.
Definition: HardwareTemperature.h:29