DUDS
Distributed Update of Data from Something
duds::hardware::devices::instruments::MCP9808 Class Reference

Preliminary support for Microchip's MCP9808 temperature sensor. More...

#include <MCP9808.hpp>

Inheritance diagram for duds::hardware::devices::instruments::MCP9808:
Collaboration diagram for duds::hardware::devices::instruments::MCP9808:

Public Types

enum  Resolution { Half, Quarter, Eighth, Sixteenth }
 

Public Member Functions

 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. More...
 
 ~MCP9808 ()
 Stops sampling. More...
 
void resolution (Resolution r)
 Changes the sampling resolution. More...
 
Resolution resolution () const
 Returns the current sampling resolution. More...
 
double resolutionDegrees () const
 
void resume ()
 Begin sampling. More...
 
bool running () const
 True when the device is sampling. More...
 
void sample ()
 Reads sample data from the device. More...
 
void start ()
 Begin sampling. More...
 
void suspend ()
 Stop sampling. More...
 
duds::data::Quantity temperature () const
 Returns the last sampled temperature. More...
 

Private Attributes

std::unique_ptr< duds::hardware::interface::Smbuscom
 Communication bus. More...
 
std::uint16_t config
 The configuration word. More...
 
char res
 The raw data for the configured resolution. More...
 
char rev
 Device's revision byte. More...
 
double temp
 Last temperature sample. More...
 

Detailed Description

Preliminary support for Microchip's MCP9808 temperature sensor.

The device continually samples temperature and can provide interrupt or thermostat-like output.

Normally uses an address formed by a bit-wise OR of 0x18 and the state of of three address lines hardwired to the device that supply the 3 LSb (0x7). Some variation of the device uses 0x48 to OR with the hardwired line bits.

Does not use PEC; not quite a SMBus device.

Author
Jeff Jackowski
Examples:
mcp9808test.cpp.

Definition at line 31 of file MCP9808.hpp.

Member Enumeration Documentation

◆ Resolution

Enumerator
Half 
Quarter 
Eighth 
Sixteenth 

Definition at line 53 of file MCP9808.hpp.

Constructor & Destructor Documentation

◆ MCP9808()

duds::hardware::devices::instruments::MCP9808::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.

While sampling is a power-on default, this does not prevent a previously running process from suspending sampling. The constructor does not change the device's configuration, so do not assume the device is sampling after construction.

Todo:
Find way to reject bad SMBus config. Maybe find way to produce SMBus config.
Parameters
cThe SMBus interface to use for communication. PEC must be disabled.
Exceptions
DeviceMisidentifiedThe device did not respond as expected.

Definition at line 16 of file MCP9808.cpp.

◆ ~MCP9808()

duds::hardware::devices::instruments::MCP9808::~MCP9808 ( )

Stops sampling.

Definition at line 42 of file MCP9808.cpp.

Member Function Documentation

◆ resolution() [1/2]

void duds::hardware::devices::instruments::MCP9808::resolution ( Resolution  r)

Changes the sampling resolution.

Definition at line 56 of file MCP9808.cpp.

◆ resolution() [2/2]

Resolution duds::hardware::devices::instruments::MCP9808::resolution ( ) const
inline

Returns the current sampling resolution.

Definition at line 110 of file MCP9808.hpp.

Referenced by resume().

◆ resolutionDegrees()

double duds::hardware::devices::instruments::MCP9808::resolutionDegrees ( ) const
Examples:
mcp9808test.cpp.

Definition at line 61 of file MCP9808.cpp.

Referenced by resolution().

◆ resume()

void duds::hardware::devices::instruments::MCP9808::resume ( )
inline

Begin sampling.

Definition at line 94 of file MCP9808.hpp.

◆ running()

bool duds::hardware::devices::instruments::MCP9808::running ( ) const
inline

True when the device is sampling.

Definition at line 84 of file MCP9808.hpp.

◆ sample()

void duds::hardware::devices::instruments::MCP9808::sample ( )

Reads sample data from the device.

Examples:
mcp9808test.cpp.

Definition at line 76 of file MCP9808.cpp.

Referenced by resolution().

◆ start()

void duds::hardware::devices::instruments::MCP9808::start ( )

Begin sampling.

Definition at line 46 of file MCP9808.cpp.

Referenced by resume(), and running().

◆ suspend()

void duds::hardware::devices::instruments::MCP9808::suspend ( )

Stop sampling.

Postcondition
Reading a sample from the device will provide the last sampled temperature.

Definition at line 51 of file MCP9808.cpp.

Referenced by resume(), and ~MCP9808().

◆ temperature()

duds::data::Quantity duds::hardware::devices::instruments::MCP9808::temperature ( ) const

Returns the last sampled temperature.

Examples:
mcp9808test.cpp.

Definition at line 81 of file MCP9808.cpp.

Referenced by resolution().

Member Data Documentation

◆ com

std::unique_ptr<duds::hardware::interface::Smbus> duds::hardware::devices::instruments::MCP9808::com
private

Communication bus.

Definition at line 35 of file MCP9808.hpp.

Referenced by MCP9808(), resolution(), sample(), start(), and suspend().

◆ config

std::uint16_t duds::hardware::devices::instruments::MCP9808::config
private

The configuration word.

Definition at line 43 of file MCP9808.hpp.

Referenced by MCP9808(), start(), and suspend().

◆ res

char duds::hardware::devices::instruments::MCP9808::res
private

The raw data for the configured resolution.

Definition at line 47 of file MCP9808.hpp.

Referenced by MCP9808(), resolution(), and resolutionDegrees().

◆ rev

char duds::hardware::devices::instruments::MCP9808::rev
private

Device's revision byte.

Definition at line 51 of file MCP9808.hpp.

Referenced by MCP9808().

◆ temp

double duds::hardware::devices::instruments::MCP9808::temp
private

Last temperature sample.

Definition at line 39 of file MCP9808.hpp.

Referenced by sample(), and temperature().


The documentation for this class was generated from the following files: