rasProject_01 / weSweetHome  R. 240
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
we1wire.h File Reference

Common types and values for 1-wire sensors. More...

#include "sysBasic.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

Data Structures

struct  oneWireDevice_t
 A structure for 1-wire devices. More...
 

Macros

#define BAD_TEMP_FLOAT
 Bad temperature reading as float string. More...
 
#define BAD_TEMP_READ
 Bad temperature reading. More...
 
#define STD_DEVICES_PATH
 The standard devices location. More...
 
#define STD_DEVICES_PATH_LEN
 Standard 1-wire device path length. More...
 

Functions

int getTemp (oneWireDevice_t *const tempSensor)
 Get temperature. More...
 
void initTempSensor (oneWireDevice_t *const tempSensor, char const *const name, char const *const valueFile)
 Initialise a 1-wire sensor structure. More...
 

Detailed Description

Common types and values for 1-wire sensors.

Copyright (c) 2018, 2020 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 249 30.06.2023
Rev. 168 21.07.2018 : new
Rev. 190 12.02.2019 : safe water temperature reduced to 65‹¨«C
Rev. 222 18.03.2020 : safe water temperature set to 69‹¨«C

1-wire devices and especially 1-wire temperature sensors are an attractive way to enrich Raspberry's process I/O repertoire. Up to some dozen devices can share one digital I/O pin; the default is GPIO04 (Pin7).

In most Linuxes and in Raspbian 1-wire devices are accessed by Linux's "device as file" approach. The behaviour is being implemented in kernel modules (i.e. .so files) which must be activated in OS's configuration files. Access to a 1-wire device's I/O values, configuration data etc. is done by a) opening, b) reading from respectively writing to and, finally, c) closing the corresponding (pseudo) file. The sheer number of files for a small un-complicated device and the content semantics seam neither clearly designed nor documented. One order principle is to have those pseudo files in one directory named according to 1-wire devices' unique readable serial number.

As the I/O pin used for 1-wire (default GPIO04, Pin7) is governed by those kernel modules no other process control software must touch this port directly.

This include file introduces some types and functions to handle 1-wire.

Macro Definition Documentation

◆ STD_DEVICES_PATH

#define STD_DEVICES_PATH

The standard devices location.

This is the directory wer each device's sub-directory is located.
Value: /sys/bus/w1/devices/

◆ STD_DEVICES_PATH_LEN

#define STD_DEVICES_PATH_LEN

Standard 1-wire device path length.

This is the length of "/sys/bus/w1/devices/" without the trailing '/' respectively the index of that trailing slash.

This path length +1 would be the index of the device directory name "28-..." in "/sys/bus/w1/devices/28-01e63c07010c/".

This path length +15 — i.e. + STD_DEVICES_PATH_LEN — would be the end of the concrete device's directory path respectively the index of its trailing respectively separating slash.

◆ BAD_TEMP_READ

#define BAD_TEMP_READ

Bad temperature reading.

The integer value for bad temperature sensor reading is +987650 m°C respectively +987.650 °C far beyond the 1-wire temperature sensors range.

Rationale for choosing a (too) high value as bad value: The usual and safe "turn XYZ off" when temperature exceeds xy¶øC" requires no special treatment for sensor outage.

◆ BAD_TEMP_FLOAT

#define BAD_TEMP_FLOAT

Bad temperature reading as float string.

The integer value for bad temperature sensor reading as °C string is "987.6 " (float string, 6 characters including trailing blank.

Function Documentation

◆ getTemp()

int getTemp ( oneWireDevice_t *const  tempSensor)

Get temperature.

This function tries a new measurement on the 1-wire temperature sensor provided. On success the new value is returned. On failure the last good value is returned, but at most 7 times after 7 good readings before. On total failure -99900 (-99.9 °C, 0 K, BAD_TEMP_READ) is returned.

Additionally on temperature changes, the integer reading (.value) and the floating point string (valueGrdC[]) will be set in the structure.

Parameters
tempSensorpointer to the sensor's structure
Returns
the actual or last reading or -2721500 if no good / not enough past good readings

◆ initTempSensor()

void initTempSensor ( oneWireDevice_t *const  tempSensor,
char const *const  name,
char const *const  valueFile 
)

Initialise a 1-wire sensor structure.

This function does basic initial settings for a 1-wire temperature sensor. tempSensor.name and tempSensor.valueFile are set by the respective parameters.
The temperature values are set to bad value; see BAD_TEMP_READ and BAD_TEMP_FLOAT

Parameters
tempSensorpointer to the sensor's structure (never NULL!)
namethe sensor's short name or its directory name; NULL / empty: no change
valueFilethe canonical absolute path to its value file; NULL / empty: no change