Skip to content

Commit

Permalink
Added a "latesttemp" node on the DS18B20, DS18S20, DS1822, and DS28EA00
Browse files Browse the repository at this point in the history
chips (and iButton versions). Intended for safe use of
/simultaneous/temperature.
  • Loading branch information
ianka committed Feb 2, 2016
1 parent db4b183 commit 4a48e55
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 17 deletions.
50 changes: 43 additions & 7 deletions module/owlib/src/c/ow_1820.c
Expand Up @@ -46,8 +46,10 @@
/* DS18S20&2 Temperature */
// READ_FUNCTION( FS_tempdata ) ;
READ_FUNCTION(FS_10temp);
READ_FUNCTION(FS_10latesttemp);
READ_FUNCTION(FS_10temp_link);
READ_FUNCTION(FS_22temp);
READ_FUNCTION(FS_22latesttemp);
READ_FUNCTION(FS_thermocouple);
READ_FUNCTION(FS_fasttemp);
READ_FUNCTION(FS_slowtemp);
Expand Down Expand Up @@ -101,6 +103,7 @@ static struct filetype DS18S20[] = {
{"temperature11", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_10temp_link, NO_WRITE_FUNCTION, INVISIBLE, NO_FILETYPE_DATA, },
{"temperature12", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_10temp_link, NO_WRITE_FUNCTION, INVISIBLE, NO_FILETYPE_DATA, },
{"fasttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_10temp_link, NO_WRITE_FUNCTION, INVISIBLE, NO_FILETYPE_DATA, },
{"latesttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_volatile, FS_10latesttemp, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
{"templow", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=1}, },
{"temphigh", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=0}, },
{"power", PROPERTY_LENGTH_YESNO, NON_AGGREGATE, ft_yesno, fc_volatile, FS_power, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
Expand All @@ -124,6 +127,7 @@ static struct filetype DS18B20[] = {
{"temperature11", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=11}, },
{"temperature12", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=12}, },
{"fasttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_fasttemp, NO_WRITE_FUNCTION, VISIBLE, {.i=9}, },
{"latesttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_volatile, FS_22latesttemp, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
{"templow", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=1}, },
{"temphigh", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=0}, },
{"power", PROPERTY_LENGTH_YESNO, NON_AGGREGATE, ft_yesno, fc_volatile, FS_power, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
Expand All @@ -146,6 +150,7 @@ static struct filetype DS1822[] = {
{"temperature11", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=11}, },
{"temperature12", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=12}, },
{"fasttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_fasttemp, NO_WRITE_FUNCTION, VISIBLE, {.i=9}, },
{"latesttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_volatile, FS_22latesttemp, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
{"templow", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=1}, },
{"temphigh", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE, {.i=0}, },
{"power", PROPERTY_LENGTH_YESNO, NON_AGGREGATE, ft_yesno, fc_volatile, FS_power, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
Expand All @@ -170,6 +175,7 @@ static struct filetype DS1825[] = {
{"temperature11", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE_DS1825, {.i=11}, },
{"temperature12", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=12}, },
{"fasttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_fasttemp, NO_WRITE_FUNCTION, VISIBLE_DS1825, {.i=9}, },
{"latesttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_volatile, FS_22latesttemp, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
{"templow", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE_DS1825, {.i=1}, },
{"temphigh", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE_DS1825, {.i=0}, },
{"thermocouple", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_thermocouple, NO_WRITE_FUNCTION, VISIBLE_MAX31850, {.i=12}, },
Expand Down Expand Up @@ -197,6 +203,7 @@ static struct filetype DS28EA00[] = {
{"temperature11", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=11}, },
{"temperature12", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_simultaneous_temperature, FS_22temp, NO_WRITE_FUNCTION, VISIBLE, {.i=12}, },
{"fasttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_link, FS_fasttemp, NO_WRITE_FUNCTION, VISIBLE, {.i=9}, },
{"latesttemp", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_volatile, FS_22latesttemp, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
{"templow", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE_DS1825, {.i=1}, },
{"temphigh", PROPERTY_LENGTH_TEMP, NON_AGGREGATE, ft_temperature, fc_stable, FS_r_templimit, FS_w_templimit, VISIBLE_DS1825, {.i=0}, },
{"power", PROPERTY_LENGTH_YESNO, NON_AGGREGATE, ft_yesno, fc_volatile, FS_power, NO_WRITE_FUNCTION, VISIBLE, NO_FILETYPE_DATA, },
Expand Down Expand Up @@ -289,8 +296,10 @@ enum temperature_problem_flag { allow_85C, deny_85C, } ;
/* ------- Functions ------------ */

/* DS1820*/
static GOOD_OR_BAD OW_10latesttemp(_FLOAT * temp, enum temperature_problem_flag accept_85C, const struct parsedname *pn);
static GOOD_OR_BAD OW_10temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn);
static GOOD_OR_BAD OW_thermocouple(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn);
static GOOD_OR_BAD OW_22latesttemp(_FLOAT * temp, enum temperature_problem_flag accept_85C, const struct parsedname *pn);
static GOOD_OR_BAD OW_22temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn);
static GOOD_OR_BAD OW_power(BYTE * data, const struct parsedname *pn);
static GOOD_OR_BAD OW_r_templimit(_FLOAT * T, const int Tindex, const struct parsedname *pn);
Expand Down Expand Up @@ -365,6 +374,11 @@ static ZERO_OR_ERROR FS_10temp(struct one_wire_query *owq)
return GB_to_Z_OR_E(OW_10temp(&OWQ_F(owq), allow_85C, 0, pn));
}

static ZERO_OR_ERROR FS_10latesttemp(struct one_wire_query *owq)
{
return GB_to_Z_OR_E(OW_10latesttemp(&OWQ_F(owq), 1, PN(owq)));
}

static ZERO_OR_ERROR FS_10temp_link(struct one_wire_query *owq)
{
return FS_r_sibling_F(&OWQ_F(owq),"temperature",owq) ;
Expand All @@ -388,6 +402,11 @@ static ZERO_OR_ERROR FS_22temp(struct one_wire_query *owq)
return GB_to_Z_OR_E(OW_22temp(&OWQ_F(owq), allow_85C, 0, pn));
}

static ZERO_OR_ERROR FS_22latesttemp(struct one_wire_query *owq)
{
return GB_to_Z_OR_E(OW_22latesttemp(&OWQ_F(owq), 1, PN(owq)));
}

// use sibling function for fasttemp to keep cache value consistent
static ZERO_OR_ERROR FS_fasttemp(struct one_wire_query *owq)
{
Expand Down Expand Up @@ -839,14 +858,12 @@ static GOOD_OR_BAD OW_temperature_ready( enum temperature_problem_flag accept_85
}

/* DS18S20 */
/* get the temp from the scratchpad buffer after starting a conversion and waiting */
static GOOD_OR_BAD OW_10temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn)
/* get the temp from the scratchpad buffer */
static GOOD_OR_BAD OW_10latesttemp(_FLOAT * temp, enum temperature_problem_flag accept_85C, const struct parsedname *pn)
{
BYTE data[SCRATCHPAD_LENGTH];
struct tempresolution * Resolution = &ResolutionS ;

RETURN_BAD_IF_BAD( OW_temperature_ready( accept_85C, simul_good, Resolution, pn ) ) ;

RETURN_BAD_IF_BAD(OW_r_scratchpad(data, pn)) ;

// Correction thanks to Nathan D. Holmes
Expand All @@ -864,15 +881,23 @@ static GOOD_OR_BAD OW_10temp(_FLOAT * temp, enum temperature_problem_flag accept
return gbBAD ;
}

static GOOD_OR_BAD OW_22temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn)
/* get the temp from the scratchpad buffer after starting a conversion and waiting */
static GOOD_OR_BAD OW_10temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn)
{
struct tempresolution * Resolution = &ResolutionS ;

RETURN_BAD_IF_BAD( OW_temperature_ready( accept_85C, simul_good, Resolution, pn ) ) ;

return OW_10latesttemp(temp, accept_85C, pn);
}

static GOOD_OR_BAD OW_22latesttemp(_FLOAT * temp, enum temperature_problem_flag accept_85C, const struct parsedname *pn)
{
BYTE data[SCRATCHPAD_LENGTH];
struct tempresolution *Resolution ;

RETURN_BAD_IF_BAD( OW_set_resolution( &Resolution, pn ) ) ;

RETURN_BAD_IF_BAD( OW_temperature_ready( accept_85C, simul_good, Resolution, pn ) ) ;

RETURN_BAD_IF_BAD( OW_r_scratchpad(data, pn) ) ;

temp[0] = OW_masked_temperature( data, Resolution ) ;
Expand All @@ -883,6 +908,17 @@ static GOOD_OR_BAD OW_22temp(_FLOAT * temp, enum temperature_problem_flag accept
return gbBAD ;
}

static GOOD_OR_BAD OW_22temp(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn)
{
struct tempresolution *Resolution ;

RETURN_BAD_IF_BAD( OW_set_resolution( &Resolution, pn ) ) ;

RETURN_BAD_IF_BAD( OW_temperature_ready( accept_85C, simul_good, Resolution, pn ) ) ;

return OW_22latesttemp(temp, accept_85C, pn);
}

/* MAX31850 Thermocouple */
/* get the temp from the scratchpad buffer after starting a conversion and waiting */
static GOOD_OR_BAD OW_thermocouple(_FLOAT * temp, enum temperature_problem_flag accept_85C, int simul_good, const struct parsedname *pn)
Expand Down
8 changes: 8 additions & 0 deletions src/man/man3/DS1822.man
Expand Up @@ -19,6 +19,8 @@ Thermometer.
[.]XXXXXXXXXXXX[XX][/[
.so man3/temperatures_mini.3so
|
.B latesttemp
|
.B die
|
.B power
Expand Down Expand Up @@ -49,7 +51,13 @@ Is the chip powered externally (=1) or from the parasitically from the data bus
Measured temperature with 12 bit resolution.
.SS temperature9 temperature10 temperature11 temperature12
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution. There is a tradeoff of time versus accuracy in the temperature measurement.
.SS latesttemp
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution, depending on the resolution of the latest conversion on this chip. Reading this node will never trigger a temperature conversion. Intended for use in conjunction with
.B /simultaneous/temperature.
.SS fasttemp
.I read-only, floating point
.br
Expand Down
11 changes: 10 additions & 1 deletion src/man/man3/DS18B20.man
Expand Up @@ -15,13 +15,16 @@
\- Programmable Resolution 1-Wire Digital Thermometer
.TP
.B MAX31820
Ambient Temperature Sensor
\- Ambient Temperature Sensor
.SH SYNOPSIS
Thermometer.
.PP
.B 28
[.]XXXXXXXXXXXX[XX][/[
.so man3/temperatures_mini.3so
|
.B latesttemp
|
.B die
|
.B power
Expand Down Expand Up @@ -54,7 +57,13 @@ Is the chip powered externally (=1) or from the parasitically from the data bus
Measured temperature with 12 bit resolution.
.SS temperature9 temperature10 temperature11 temperature12
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution. There is a tradeoff of time versus accuracy in the temperature measurement.
.SS latesttemp
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution, depending on the resolution of the latest conversion on this chip. Reading this node will never trigger a temperature conversion. Intended for use in conjunction with
.B /simultaneous/temperature.
.SS fasttemp
.I read-only, floating point
.br
Expand Down
29 changes: 20 additions & 9 deletions src/man/man3/DS18S20.man
Expand Up @@ -10,6 +10,7 @@
'\"
.TH DS18S20 3 2003 "OWFS Manpage" "One-Wire File System"
.SH NAME
.TP
.B DS18S20
\- High-Precision 1-Wire Digital Thermometer
.TP
Expand All @@ -20,12 +21,14 @@ Thermometer.
.PP
.B 10
[.]XXXXXXXXXXXX[XX][/[
.so man3/temperatures_mini.3so
|
.B latesttemp
|
.B die
|
.B power
|
.B temperature
|
.B temphigh
|
.B templow
Expand All @@ -49,13 +52,21 @@ Is the chip powered externally (=1) or from the parasitically from the data bus
.SS temperature
.I read-only, floating point
.br
.I Temperature
read by the chip at high resolution (~12 bits). Units are selected from the invoking command line. See
.B owfs(1)
or
.B owhttpd(1)
for choices. Default is Celsius.
Conversion takes 1000 msec.
Measured temperature with 12 bit resolution.
.SS temperature9 temperature10 temperature11 temperature12
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution. There is a tradeoff of time versus accuracy in the temperature measurement.
.SS latesttemp
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution, depending on the resolution of the latest conversion on this chip. Reading this node will never trigger a temperature conversion. Intended for use in conjunction with
.B /simultaneous/temperature.
.SS fasttemp
.I read-only, floating point
.br
Equivalent to
.I temperature9
.so man3/temperature_threshold.3so
.so man3/temperature_errata.3so
.SH STANDARD PROPERTIES
Expand Down
9 changes: 9 additions & 0 deletions src/man/man3/DS28EA00.man
Expand Up @@ -18,6 +18,9 @@ Thermometer, PIO and Chain.
.B 42
[.]XXXXXXXXXXXX[XX][/[
.so man3/temperatures_mini.3so
|
.B latesttemp
|
.B die
|
.B power
Expand Down Expand Up @@ -49,7 +52,13 @@ Is the chip powered externally (=1) or from the parasitically from the data bus
Measured temperature with 12 bit resolution.
.SS temperature9 temperature10 temperature11 temperature12
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution. There is a tradeoff of time versus accuracy in the temperature measurement.
.SS latesttemp
.I read-only, floating point
.br
Measured temperature at 9 to 12 bit resolution, depending on the resolution of the latest conversion on this chip. Reading this node will never trigger a temperature conversion. Intended for use in conjunction with
.B /simultaneous/temperature.
.SS fasttemp
.I read-only, floating point
.br
Expand Down

0 comments on commit 4a48e55

Please sign in to comment.