DUDS
Distributed Update of Data from Something
MCP9808.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #ifndef MCP9808_HPP
11 #define MCP9808_HPP
12 
14 #include <duds/data/Quantity.hpp>
15 
16 namespace duds { namespace hardware { namespace devices { namespace instruments {
17 
31 class MCP9808 : boost::noncopyable {
35  std::unique_ptr<duds::hardware::interface::Smbus> com;
39  double temp;
43  std::uint16_t config;
47  char res;
51  char rev;
52 public:
53  enum Resolution {
58  };
74  MCP9808(
75  std::unique_ptr<duds::hardware::interface::Smbus> &c // no PEC!
76  );
80  ~MCP9808();
84  bool running() const {
85  return (config & 0x100) == 0;
86  }
90  void start();
94  void resume() {
95  start();
96  }
102  void suspend();
106  void resolution(Resolution r);
111  return (Resolution)res;
112  }
113  double resolutionDegrees() const;
121  void sample();
122 };
123 
124 } } } }
125 
126 #endif // #ifndef MCP9808_HPP
A container for a value and a unit to better describe the value.
Definition: Quantity.hpp:37
bool running() const
True when the device is sampling.
Definition: MCP9808.hpp:84
char rev
Device&#39;s revision byte.
Definition: MCP9808.hpp:51
char res
The raw data for the configured resolution.
Definition: MCP9808.hpp:47
std::unique_ptr< duds::hardware::interface::Smbus > com
Communication bus.
Definition: MCP9808.hpp:35
void sample()
Reads sample data from the device.
Definition: MCP9808.cpp:76
std::uint16_t config
The configuration word.
Definition: MCP9808.hpp:43
duds::data::Quantity temperature() const
Returns the last sampled temperature.
Definition: MCP9808.cpp:81
double temp
Last temperature sample.
Definition: MCP9808.hpp:39
MCP9808(std::unique_ptr< duds::hardware::interface::Smbus > &c)
Prepares to use a MCP9808 by identifying the device and reading, but not changing, its current configuration.
Definition: MCP9808.cpp:16
Resolution resolution() const
Returns the current sampling resolution.
Definition: MCP9808.hpp:110
Preliminary support for Microchip&#39;s MCP9808 temperature sensor.
Definition: MCP9808.hpp:31