COSA
An Object-Oriented Platform for Arduino Programming
|
#include <DS18B20.hh>
Classes | |
struct | scratchpad_t |
class | Search |
Public Types | |
enum | { FIRST = -1, ERROR = -1, LAST = ROMBITS } |
Public Member Functions | |
DS18B20 (OWI *pin, const char *name=NULL) | |
DS18B20 (OWI *pin, const uint8_t *rom, const char *name=NULL) | |
bool | connect (uint8_t index) |
void | resolution (uint8_t bits) |
void | set_trigger (int8_t low, int8_t high) |
int16_t | temperature () const |
uint8_t | resolution () const |
void | get_trigger (int8_t &low, int8_t &high) const |
bool | convert_request () |
bool | write_scratchpad () |
bool | read_scratchpad (bool flag=true) |
bool | copy_scratchpad () |
bool | recall () |
bool | read_power_supply () |
uint8_t * | rom () |
bool | update_rom () |
int8_t | search_rom (int8_t last=FIRST) |
bool | read_rom () |
bool | match_rom () |
bool | skip_rom () |
int8_t | alarm_search (int8_t last=FIRST) |
bool | connect (uint8_t family, uint8_t index) |
virtual void | on_alarm () |
Static Public Member Functions | |
static bool | convert_request (OWI *owi, uint8_t resolution=12, bool parasite=false) |
static void | print (IOStream &outs, int16_t temp) |
Public Attributes | |
str_P | NAME |
Protected Types | |
enum | { FAMILY_CODE = 0x28, CONVERT_T = 0x44, READ_SCRATCHPAD = 0xBE, WRITE_SCRATCHPAD = 0x4E, COPY_SCRATCHPAD = 0x48, RECALL_E = 0xB8, READ_POWER_SUPPLY = 0xB4 } |
Protected Member Functions | |
void | power_off () |
int8_t | search (int8_t last=FIRST) |
Protected Attributes | |
scratchpad_t | m_scratchpad |
uint8_t | m_parasite |
uint32_t | m_start |
uint8_t | m_converting |
uint8_t | m_rom [ROM_MAX] |
const uint8_t * | ROM |
Driver * | m_next |
OWI * | m_pin |
Static Protected Attributes | |
static const uint8_t | CONFIG_MAX = 3 |
static const uint16_t | MAX_CONVERSION_TIME = 750 |
static const uint16_t | MIN_COPY_PULLUP = 10 |
Friends | |
IOStream & | operator<< (IOStream &outs, DS18B20 &thermometer) |
Driver for the DS18B20 Programmable Resolution 1-Write Digital Thermometer.
May use parasite powering (connect DS18B20 VCC to GND) otherwise to VCC.
Definition at line 49 of file DS18B20.hh.
|
protected |
DS18B20 Function Commands (Table 3, pp. 12).
Enumerator | |
---|---|
FAMILY_CODE | |
CONVERT_T | |
READ_SCRATCHPAD | |
WRITE_SCRATCHPAD | |
COPY_SCRATCHPAD | |
RECALL_E | |
READ_POWER_SUPPLY |
Definition at line 248 of file DS18B20.hh.
Construct a DS18B20 device connected to the given 1-Wire bus. Use connect() to lookup, set power supply mode and configuration. Alternatively use read_power_supply() and read_scratchpad() directly if rom address is given.
[in] | pin | one wire bus pin. |
[in] | name | of device. |
Definition at line 80 of file DS18B20.hh.
Construct a DS18B20 device connected to the given 1-Wire bus and device identity (in EEPROM). Use connect() to lookup, set power supply mode and configuration. Alternatively use read_power_supply() and read_scratchpad() directly if rom address is given.
[in] | pin | one wire bus pin. |
[in] | rom | device identity. |
[in] | name | of device. In program memory (default NULL). |
Definition at line 97 of file DS18B20.hh.
|
inherited |
bool DS18B20::connect | ( | uint8_t | index | ) |
Connect to DS18B20 device with given index. Reads configuration, scratchpad, and power supply setting. Returns true(1) if connected, otherwise false(0).
[in] | index | device order. |
Definition at line 34 of file DS18B20.cpp.
|
inherited |
bool DS18B20::convert_request | ( | ) |
Initiate a single temperature conversion. With the default setting 12-bit resolution the max conversion time is 750 ms, MAX_CONVERSION_TIME.
Definition at line 50 of file DS18B20.cpp.
|
static |
Initiate connected devices to perform a simple temperature conversion (boardcast). With the default setting 12-bit resolution the max conversion time is 750 ms, MAX_CONVERSION_TIME. Give zero(0) as resolution to omit conversion wait. Parasite power by passing true for the mode flag. Returns true(1) if successful otherwise false(0).
[in] | owi | one-wire interface pin. |
[in] | resolution | of conversion. |
[in] | parasite | power mode flag. |
Definition at line 60 of file DS18B20.cpp.
bool DS18B20::copy_scratchpad | ( | ) |
Copy device scratchpad triggers and configuration data to device EEPROM. An internal delay is issued to allow the data to be written.
Definition at line 101 of file DS18B20.cpp.
|
inline |
Get alarm trigger values; low and high threshold values. Use connect(), or read_scratchpad() to read values from device.
[out] | low | threshold. |
[out] | high | threshold. |
Definition at line 165 of file DS18B20.hh.
|
inherited |
|
inlinevirtualinherited |
|
inlineprotected |
Turn power off if the device is parasite powered. Call connect() or read_power_supply() to set the parasite mode for the device.
Definition at line 293 of file DS18B20.hh.
|
static |
Print temperature reading (fixed point value) to given output stream.
[in] | outs | output stream. |
[in] | temp | temperature fixed point number. |
Definition at line 128 of file DS18B20.cpp.
bool DS18B20::read_power_supply | ( | ) |
Read power supply. Determine if the device requires parasite powering. The information is cached and used in read_scratchpad() and copy_scratchpad() for internal delay timing. The function connect() will call this function automatically.
Definition at line 119 of file DS18B20.cpp.
|
inherited |
bool DS18B20::read_scratchpad | ( | bool | flag = true | ) |
Read the contents of the scratchpad to local memory. A internal delay will occur if a convert_request() is pending. The delay is at most max conversion time (750 ms). The flag parameter may be used when a device has been addressed with search (alarm).
[in] | flag | to reset before reading (default true). |
Definition at line 75 of file DS18B20.cpp.
bool DS18B20::recall | ( | ) |
Recall the alarm triggers and configuration from device EEPROM.
Definition at line 111 of file DS18B20.cpp.
void DS18B20::resolution | ( | uint8_t | bits | ) |
Set conversion resolution from 9..12 bits. Use write_scratchpad() and copy_scratchpad() to update device.
[in] | bits | resolution. |
Definition at line 43 of file DS18B20.cpp.
|
inline |
Get conversion resolution. Use connect(), or read_scratchpad() to read values from device before calling this method.
Definition at line 152 of file DS18B20.hh.
|
inlineinherited |
|
protectedinherited |
|
inherited |
|
inline |
Set alarm trigger values; low and high threshold values. Use write_scratchpad() and copy_scratchpad() to update device.
[in] | low | threshold. |
[in] | high | threshold. |
Definition at line 126 of file DS18B20.hh.
|
inherited |
|
inline |
Get the latest temperature reading from the local memory scratchpad. Call convert_request() and read_scratchpad() before accessing the scratchpad. Returns at highest resolution a fixed point<12,4> point number. For 11-bit resolution, bit 0 is undefined, 10-bits bit 1 and 0, and so on (LSB).
Definition at line 141 of file DS18B20.hh.
|
inherited |
bool DS18B20::write_scratchpad | ( | ) |
Write the contents of the scratchpad triggers and configuration (3 bytes) to device.
Definition at line 93 of file DS18B20.cpp.
Print the name of the thermometer and latest temperature reading with two decimals to given output stream. The temperature is in Celcius.
[in] | outs | stream to print device information to. |
[in] | thermometer | device. |
Definition at line 141 of file DS18B20.cpp.
|
staticprotected |
Size of configuration; high/low trigger and configuration byte.
Definition at line 272 of file DS18B20.hh.
|
protected |
Convert request pending.
Definition at line 281 of file DS18B20.hh.
|
protected |
Parasite power mode.
Definition at line 275 of file DS18B20.hh.
|
protected |
Definition at line 269 of file DS18B20.hh.
|
protected |
Watchdog millis on convert_request().
Definition at line 278 of file DS18B20.hh.
|
staticprotected |
Max conversion time for 12-bit conversion in milli-seconds.
Definition at line 284 of file DS18B20.hh.
|
staticprotected |
Min copy configuration time in milli-seconds (parasite mode).
Definition at line 287 of file DS18B20.hh.
|
inherited |