-
Notifications
You must be signed in to change notification settings - Fork 1
fix(wsen-hids): Restore sensor config after power cycle. #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3f42ec4
5fc7208
8066562
feaf8bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,9 @@ def __init__( | |
| self._calibration = {} | ||
| self._temp_gain = 1.0 | ||
| self._temp_offset = 0.0 | ||
| self._avg_t = avg_t | ||
| self._avg_h = avg_h | ||
| self._bdu = enable_bdu | ||
|
|
||
| if check_device: | ||
| self.check_device() | ||
|
|
@@ -167,10 +170,13 @@ def _read_calibration(self): | |
| # ------------------------------------------------------------------------- | ||
|
|
||
| def enable_bdu(self, enabled=True): | ||
| self._bdu = enabled | ||
| value = CTRL_1_BDU if enabled else 0 | ||
| self._update_reg(REG_CTRL_1, CTRL_1_BDU, value) | ||
|
|
||
| def set_average(self, avg_t=AVG_T_DEFAULT, avg_h=AVG_H_DEFAULT): | ||
| self._avg_t = avg_t | ||
| self._avg_h = avg_h | ||
| avg_t &= 0x07 | ||
| avg_h &= 0x07 | ||
| value = (avg_t << 3) | avg_h | ||
|
|
@@ -201,6 +207,10 @@ def power_on(self): | |
| ctrl1 = self._read_reg(REG_CTRL_1) | ||
| ctrl1 |= CTRL_1_PD | ||
| self._write_reg(REG_CTRL_1, ctrl1) | ||
| self.set_average(self._avg_t, self._avg_h) | ||
| if self._bdu: | ||
| self.enable_bdu(True) | ||
| self._read_calibration() | ||
|
Comment on lines
209
to
+213
|
||
|
|
||
| def enable_heater(self, enabled=True): | ||
| value = CTRL_2_HEATER if enabled else 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
power_on()now reappliesself._avg_t,self._avg_h, andself._bdu, but those fields are only initialized in__init__and never updated byset_average()/enable_bdu(). After a caller changes averaging or BDU at runtime, apower_off()/power_on()cycle silently reverts to constructor-time settings (for example,enable_bdu(False)can be undone if the instance was created withenable_bdu=True), so the driver mutates user-selected configuration unexpectedly.Useful? React with 👍 / 👎.