int temperature; /* 1000 * temperature in dgr C */ int humidity; /* 1000 * relative humidity in %RH */
};
staticint shtc1_update_values(struct i2c_client *client, struct shtc1_data *data, char *buf, int bufsize)
{ int ret = i2c_master_send(client, data->command, SHTC1_CMD_LENGTH); if (ret != SHTC1_CMD_LENGTH) {
dev_err(&client->dev, "failed to send command: %d\n", ret); return ret < 0 ? ret : -EIO;
}
/* * In blocking mode (clock stretching mode) the I2C bus * is blocked for other traffic, thus the call to i2c_master_recv() * will wait until the data is ready. For non blocking mode, we * have to wait ourselves.
*/ if (!data->setup.blocking_io)
usleep_range(data->nonblocking_wait_time,
data->nonblocking_wait_time + 1000);
ret = i2c_master_recv(client, buf, bufsize); if (ret != bufsize) {
dev_err(&client->dev, "failed to read values: %d\n", ret); return ret < 0 ? ret : -EIO;
}
return 0;
}
/* sysfs attributes */ staticstruct shtc1_data *shtc1_update_client(struct device *dev)
{ struct shtc1_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; unsignedchar buf[SHTC1_RESPONSE_LENGTH]; int val; int ret = 0;
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ / 10) || !data->valid) {
ret = shtc1_update_values(client, data, buf, sizeof(buf)); if (ret) goto out;
/* * From datasheet: * T = -45 + 175 * ST / 2^16 * RH = 100 * SRH / 2^16 * * Adapted for integer fixed point (3 digit) arithmetic.
*/
val = be16_to_cpup((__be16 *)buf);
data->temperature = ((21875 * val) >> 13) - 45000;
val = be16_to_cpup((__be16 *)(buf + 3));
data->humidity = ((12500 * val) >> 13);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.