mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
mcp9808: updated doxygen tags and formatted sources
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
85b5c8a64e
commit
90bf469245
Binary file not shown.
Before Width: | Height: | Size: 319 KiB After Width: | Height: | Size: 49 KiB |
@ -1,24 +1,19 @@
|
|||||||
|
|
||||||
#include "mraa.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "mcp9808.h"
|
#include "mcp9808.h"
|
||||||
|
|
||||||
|
#include "mraa.hpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
int command;
|
int command;
|
||||||
upm::MCP9808 *temp = new upm::MCP9808(6);
|
upm::MCP9808 *temp = new upm::MCP9808(6);
|
||||||
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "1 - read temp \t" ;
|
cout << "1 - read temp \t" ;
|
||||||
cout << "2 - sleep mode \t";
|
cout << "2 - sleep mode \t";
|
||||||
@ -43,7 +38,6 @@ int main()
|
|||||||
cout << "Enter a command: ";
|
cout << "Enter a command: ";
|
||||||
cin >> command;
|
cin >> command;
|
||||||
|
|
||||||
|
|
||||||
switch(command)
|
switch(command)
|
||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
@ -164,8 +158,6 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}while (command != -1 );
|
}while (command != -1 );
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -42,16 +42,23 @@
|
|||||||
#define MCP9808_CONFIG_INTCLR 0x2000
|
#define MCP9808_CONFIG_INTCLR 0x2000
|
||||||
|
|
||||||
namespace upm {
|
namespace upm {
|
||||||
|
/**
|
||||||
|
* @brief MCP9808 precision temperature sensor library
|
||||||
|
* @defgroup mcp9808 libupm-mcp9808
|
||||||
|
* @ingroup adafruit i2c temp
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* @library mcp9808
|
* @library mcp9808
|
||||||
* @sensor MCP9808
|
* @sensor MCP9808
|
||||||
* @comname MCP9808
|
* @comname MCP9808 Temperature Sensor
|
||||||
* @type Temperature, precision.
|
* @type temp
|
||||||
* @man https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide/overview
|
* @man adafruit
|
||||||
* @man http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf
|
|
||||||
* @con i2c
|
* @con i2c
|
||||||
|
* @web https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide/overview
|
||||||
|
* @web http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf
|
||||||
*
|
*
|
||||||
* @brief API for MCP9808 precision temprature sensor
|
* @brief API for MCP9808 precision temprature sensor
|
||||||
|
*
|
||||||
* The MCP9808 digital temperature sensor converts temperatures between -20°C and +100°C
|
* The MCP9808 digital temperature sensor converts temperatures between -20°C and +100°C
|
||||||
* to a digital word with ±0.5°C (max.) accuracy. The MCP9808 comes with user-programmable
|
* to a digital word with ±0.5°C (max.) accuracy. The MCP9808 comes with user-programmable
|
||||||
* registers that provide flexibility for temperature sensing applications. The registers
|
* registers that provide flexibility for temperature sensing applications. The registers
|
||||||
@ -71,78 +78,78 @@ namespace upm {
|
|||||||
class MCP9808 {
|
class MCP9808 {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @enum MCP9808_REG
|
* @enum MCP9808_REG
|
||||||
* @brief uint8_t enum containing register addresses
|
* @brief uint8_t enum containing register addresses
|
||||||
* used for setting temp thresholds for MCP9808
|
* used for setting temp thresholds for MCP9808
|
||||||
*
|
*
|
||||||
* @var MCP9808_REG::UPPER_TEMP = 0x02
|
* @var MCP9808_REG::UPPER_TEMP = 0x02
|
||||||
* @var MCP9808_REG::LOWER_TEMP = 0x03
|
* @var MCP9808_REG::LOWER_TEMP = 0x03
|
||||||
* @var MCP9808_REG::CRIT_TEMP = 0x04
|
* @var MCP9808_REG::CRIT_TEMP = 0x04
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
UPPER_TEMP = 0x02,
|
UPPER_TEMP = 0x02,
|
||||||
LOWER_TEMP = 0x03,
|
LOWER_TEMP = 0x03,
|
||||||
CRIT_TEMP = 0x04,
|
CRIT_TEMP = 0x04,
|
||||||
} MCP9808_REG;
|
} MCP9808_REG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum MCP9808_RESOLUTION
|
* @enum MCP9808_RESOLUTION
|
||||||
* @brief uint8_t enum containing the four possible
|
* @brief uint8_t enum containing the four possible
|
||||||
* values for MCP9808 resolution register.
|
* values for MCP9808 resolution register.
|
||||||
*
|
*
|
||||||
* @var MCP9808_RESOLUTION::RES_LOW = 0.5C
|
* @var MCP9808_RESOLUTION::RES_LOW = 0.5C
|
||||||
* @var MCP9808_RESOLUTION::RES_MEDIUM = 0.25C
|
* @var MCP9808_RESOLUTION::RES_MEDIUM = 0.25C
|
||||||
* @var MCP9808_RESOLUTION::RES_HIGH = 0.125C
|
* @var MCP9808_RESOLUTION::RES_HIGH = 0.125C
|
||||||
* @var MCP9808_RESOLUTION::RES_PRECISION = (default) 0.0625C
|
* @var MCP9808_RESOLUTION::RES_PRECISION = (default) 0.0625C
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
RES_LOW = 0x00,
|
RES_LOW = 0x00,
|
||||||
RES_MEDIUM = 0x01,
|
RES_MEDIUM = 0x01,
|
||||||
RES_HIGH = 0x02,
|
RES_HIGH = 0x02,
|
||||||
RES_PRECISION = 0x03
|
RES_PRECISION = 0x03
|
||||||
} MCP9808_RESOLUTION;
|
} MCP9808_RESOLUTION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum MCP9808_CONFIG
|
* @enum MCP9808_CONFIG
|
||||||
* @brief uint16_t enum containing alert and hysteresis options
|
* @brief uint16_t enum containing alert and hysteresis options
|
||||||
* for config register.
|
* for config register.
|
||||||
*
|
*
|
||||||
* @var MCP9808_CONFIG::ALERTSTAT - Alert Output Status bit
|
* @var MCP9808_CONFIG::ALERTSTAT - Alert Output Status bit
|
||||||
* 0 = Alert output is not asserted by the device (power-up default)
|
* 0 = Alert output is not asserted by the device (power-up default)
|
||||||
* 1 = Alert output is asserted as a comparator/Interrupt or critical
|
* 1 = Alert output is asserted as a comparator/Interrupt or critical
|
||||||
* temperature output
|
* temperature output
|
||||||
* @var MCP9808_CONFIG::ALERTCTRL - Alert Output Control bit
|
* @var MCP9808_CONFIG::ALERTCTRL - Alert Output Control bit
|
||||||
* 0 = Disabled (power-up default)
|
* 0 = Disabled (power-up default)
|
||||||
* 1 = Enabled
|
* 1 = Enabled
|
||||||
* @var MCP9808_CONFIG::ALERTSEL - Alert Output Select bit
|
* @var MCP9808_CONFIG::ALERTSEL - Alert Output Select bit
|
||||||
* 0 = Alert output for TUPPER, TLOWER and TCRIT (power-up default)
|
* 0 = Alert output for TUPPER, TLOWER and TCRIT (power-up default)
|
||||||
* 1 = TA > TCRIT only (TUPPER and TLOWER temperature boundaries are disabled)
|
* 1 = TA > TCRIT only (TUPPER and TLOWER temperature boundaries are disabled)
|
||||||
* @var MCP9808_CONFIG::ALERTPOL - Alert Output Polarity bit
|
* @var MCP9808_CONFIG::ALERTPOL - Alert Output Polarity bit
|
||||||
* 0 = Active-low (power-up default; pull-up resistor required)
|
* 0 = Active-low (power-up default; pull-up resistor required)
|
||||||
* 1 = Active-high
|
* 1 = Active-high
|
||||||
* @var MCP9808_CONFIG::ALERTMODE - Alert Output Mode bit
|
* @var MCP9808_CONFIG::ALERTMODE - Alert Output Mode bit
|
||||||
* 0 = Comparator output (power-up default)
|
* 0 = Comparator output (power-up default)
|
||||||
* 1 = Interrupt output
|
* 1 = Interrupt output
|
||||||
* @var MCP9808_CONFIG::HYST_0 : 0°C
|
* @var MCP9808_CONFIG::HYST_0 : 0°C
|
||||||
* @var MCP9808_CONFIG::HYST_1_5 : +1.5°C
|
* @var MCP9808_CONFIG::HYST_1_5 : +1.5°C
|
||||||
* @var MCP9808_CONFIG::HYST_3_0 : +3.0°C
|
* @var MCP9808_CONFIG::HYST_3_0 : +3.0°C
|
||||||
* @var MCP9808_CONFIG::HYST_6_0 : +6.0°C
|
* @var MCP9808_CONFIG::HYST_6_0 : +6.0°C
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
ALERTSTAT = 0x1000,
|
ALERTSTAT = 0x1000,
|
||||||
ALERTCTRL = 0x0800,
|
ALERTCTRL = 0x0800,
|
||||||
ALERTSEL = 0x0400,
|
ALERTSEL = 0x0400,
|
||||||
ALERTPOL = 0x0200,
|
ALERTPOL = 0x0200,
|
||||||
ALERTMODE = 0x0100,
|
ALERTMODE = 0x0100,
|
||||||
HYST_0 = 0x0000,
|
HYST_0 = 0x0000,
|
||||||
HYST_1_5 = 0x0002,
|
HYST_1_5 = 0x0002,
|
||||||
HYST_3_0 = 0x0004,
|
HYST_3_0 = 0x0004,
|
||||||
HYST_6_0 = 0x0006
|
HYST_6_0 = 0x0006
|
||||||
} MCP9808_CONFIG;
|
} MCP9808_CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MCP9808 constructor
|
* MCP9808 constructor
|
||||||
@ -166,15 +173,14 @@ namespace upm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current temperature.
|
* Returns current temperature.
|
||||||
*/
|
*/
|
||||||
float getTemp(void);
|
float getTemp(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will cause the devices to either sleep or wakeup.
|
* Will cause the devices to either sleep or wakeup.
|
||||||
*
|
*
|
||||||
* @param sleep . Bool, default true to sleep. false to wake.
|
* @param sleep . Bool, default true to sleep. false to wake.
|
||||||
*/
|
*/
|
||||||
void shutDown(bool sleep = true);
|
void shutDown(bool sleep = true);
|
||||||
|
|
||||||
@ -186,7 +192,7 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
void setMode(bool celsius = true)
|
void setMode(bool celsius = true)
|
||||||
{
|
{
|
||||||
m_celsius = celsius;
|
m_celsius = celsius;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,7 +201,7 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
bool isCelsius(void)
|
bool isCelsius(void)
|
||||||
{
|
{
|
||||||
return m_celsius;
|
return m_celsius;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,7 +211,7 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
bool isTcrit()
|
bool isTcrit()
|
||||||
{
|
{
|
||||||
return m_tcrit;
|
return m_tcrit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -215,7 +221,7 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
bool isTupper()
|
bool isTupper()
|
||||||
{
|
{
|
||||||
return m_tupper;
|
return m_tupper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,7 +231,7 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
bool isTlower()
|
bool isTlower()
|
||||||
{
|
{
|
||||||
return m_tlower;
|
return m_tlower;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +276,7 @@ namespace upm {
|
|||||||
* Sets hysteresis value.
|
* Sets hysteresis value.
|
||||||
*
|
*
|
||||||
* @param MCP9808_CONFIG enum value HYST_0, HYST_1_5,
|
* @param MCP9808_CONFIG enum value HYST_0, HYST_1_5,
|
||||||
* HYST_3_0 or HYST_6_0
|
* HYST_3_0 or HYST_6_0
|
||||||
*/
|
*/
|
||||||
void setHysteresis(MCP9808_CONFIG value);
|
void setHysteresis(MCP9808_CONFIG value);
|
||||||
|
|
||||||
@ -280,11 +286,11 @@ namespace upm {
|
|||||||
float getHysteresis();
|
float getHysteresis();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets resolution of temperature conversion.
|
* Sets resolution of temperature conversion.
|
||||||
*
|
*
|
||||||
* @param value - MCP9808_RESOLUTION enum value.
|
* @param value - MCP9808_RESOLUTION enum value.
|
||||||
* RES_LOW = +0.5 C
|
* RES_LOW = +0.5 C
|
||||||
* RES_MEDIUM = +0.25 C
|
* RES_MEDIUM = +0.25 C
|
||||||
* RES_HIGH = +0.125 C
|
* RES_HIGH = +0.125 C
|
||||||
* RES_PRECISION = +0.0625 C (default).
|
* RES_PRECISION = +0.0625 C (default).
|
||||||
*/
|
*/
|
||||||
@ -307,9 +313,6 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
uint16_t getDevicedId();
|
uint16_t getDevicedId();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
bool m_celsius;
|
bool m_celsius;
|
||||||
@ -317,13 +320,10 @@ namespace upm {
|
|||||||
bool m_tupper;
|
bool m_tupper;
|
||||||
bool m_tlower;
|
bool m_tlower;
|
||||||
|
|
||||||
mraa::I2c* i2c;
|
mraa::I2c* i2c;
|
||||||
|
|
||||||
float getTempValue(uint16_t value);
|
|
||||||
void updateConfigRegister(uint16_t update, bool on = true);
|
|
||||||
uint16_t swapWord(uint16_t value);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float getTempValue(uint16_t value);
|
||||||
|
void updateConfigRegister(uint16_t update, bool on = true);
|
||||||
|
uint16_t swapWord(uint16_t value);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user