rasProject_01 / weSweetHome
R. 240
process control / RasPi software by weinert-automation
|
Common types and values for 1-wire sensors. More...
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... | |
Common types and values for 1-wire sensors.
Revision history
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.
#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/
#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.
#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.
#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.
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.
tempSensor | pointer to the sensor's structure |
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
tempSensor | pointer to the sensor's structure (never NULL!) |
name | the sensor's short name or its directory name; NULL / empty: no change |
valueFile | the canonical absolute path to its value file; NULL / empty: no change |