89 count =
write(&cmd,
sizeof(cmd));
90 if (count !=
sizeof(cmd))
goto err;
91 count =
read(sna,
sizeof(sna));
92 if (count !=
sizeof(sna))
goto err;
95 for (
size_t i = 0; i <
sizeof(sna);) {
98 if (sna[i++] != crc)
goto err;
103 count =
write(&cmd,
sizeof(cmd));
104 if (count !=
sizeof(cmd))
goto err;
105 count =
read(&snb,
sizeof(snb));
106 if (count !=
sizeof(snb))
goto err;
108 for (
size_t i = 0; i <
sizeof(snb); ) {
113 if (snb[i++] != crc)
goto err;
132 if (!
acquire())
return (
false);
133 count =
write(&cmd,
sizeof(cmd));
134 count =
read(&rev,
sizeof(rev));
135 if (!
release())
return (
false);
136 return (count ==
sizeof(rev));
157 if (!
read(value)) (NAN);
158 return (((125.00 * value) / 65536) - 6.00);
170 if (!
read(value,
false))
return (NAN);
171 return (((175.72 * value) / 65536) - 46.85);
193 if (!
read(value))
return (NAN);
194 return (((175.72 * value) / 65536) - 46.85);
213 } __attribute__((packed));
222 if (!
acquire())
return (
false);
223 int count =
write(&cmd,
sizeof(cmd));
224 if (!
release())
return (
false);
225 return (count ==
sizeof(cmd));
235 bool read(uint16_t& value,
bool check =
true)
241 size = check ?
sizeof(buf) :
sizeof(buf) - 1;
242 for (
int retry = 0; retry < 20; retry++) {
244 count =
read(buf, size);
245 if (
release() && count != -1)
break;
249 if (count != size)
return (
false);
250 value = ((buf[0] << 8) | buf[1]);
251 if (!check)
return (
true);
256 return (crc == buf[2]);
266 bool read(uint8_t cmd, uint8_t& value)
270 if (!
acquire())
return (
false);
271 write(&cmd,
sizeof(cmd));
272 count =
read(®,
sizeof(reg));
273 if (!
release() || count !=
sizeof(reg))
return (
false);
281 for (uint8_t i =
CHARBITS; i != 0; i--) {
282 uint8_t msb = (crc & 0x80);
284 if (msb) crc ^= 0x31;
static uint8_t crc_update(uint8_t crc, uint8_t data)
Measure Relative Humidity, Hold Master Mode.
bool read_electronic_serial_number(uint8_t snr[8])
Write RH/T User Register 1.
bool read_firmware_revision(uint8_t &rev)
Dito, No Hold Master Mode.
Read RH/T User Register 1.
Read Temperature from RH Measurement.
bool measure_temperature()
bool read(uint8_t cmd, uint8_t &value)
bool read_user_register(uint8_t ®)
Hardware::TWI twi(100000UL)
float read_humidity_temperature()
Dito, No Hold Master Mode.
int write(const void *buf, size_t count)
Device(TWI &twi, uint8_t addr)
bool read(uint16_t &value, bool check=true)
Measure Temperature, Hold Master Mode.