Skip to content

Commit f4cfb94

Browse files
committed
Move is_connected() and reset() to public section
1 parent 6cf4ee8 commit f4cfb94

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

XRPLib/imu.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -112,47 +112,6 @@ def _r_w_reg(self, reg, dat, mask):
112112
self.rb[0] = (self.rb[0] & mask) | dat
113113
self._setreg(reg, self.rb[0])
114114

115-
def is_connected(self):
116-
"""
117-
Checks whether the IMU is connected
118-
119-
:return: True if WHO_AM_I value is correct, otherwise False
120-
:rtype: bool
121-
"""
122-
who_am_i = self._getreg(LSM_REG_WHO_AM_I)
123-
return who_am_i == 0x6C
124-
125-
def reset(self, wait_for_reset = True, wait_timeout_ms = 100):
126-
"""
127-
Resets the IMU, and restores all registers to their default values
128-
129-
:param wait_for_reset: Whether to wait for reset to complete
130-
:type wait_for_reset: bool
131-
:param wait_timeout_ms: Timeout in milliseconds when waiting for reset
132-
:type wait_timeout_ms: int
133-
:return: False if timeout occurred, otherwise True
134-
:rtype: bool
135-
"""
136-
# Set BOOT and SW_RESET bits
137-
self.reg_ctrl3_c_byte[0] = self._getreg(LSM_REG_CTRL3_C)
138-
self.reg_ctrl3_c_bits.BOOT = 1
139-
self.reg_ctrl3_c_bits.SW_RESET = 1
140-
self._setreg(LSM_REG_CTRL3_C, self.reg_ctrl3_c_byte[0])
141-
142-
# Wait for reset to complete, if requested
143-
if wait_for_reset:
144-
# Loop with timeout
145-
t0 = time.ticks_ms()
146-
while time.ticks_ms() < (t0 + wait_timeout_ms):
147-
# Check if register has returned to default value (0x04)
148-
self.reg_ctrl3_c_byte[0] = self._getreg(LSM_REG_CTRL3_C)
149-
if self.reg_ctrl3_c_byte[0] == 0x04:
150-
return True
151-
# Timeout occurred
152-
return False
153-
else:
154-
return True
155-
156115
def _set_bdu(self, bdu = True):
157116
"""
158117
Sets Block Data Update bit
@@ -243,6 +202,47 @@ def _get_acc_gyro_rates(self):
243202
Public facing API Methods
244203
"""
245204

205+
def is_connected(self):
206+
"""
207+
Checks whether the IMU is connected
208+
209+
:return: True if WHO_AM_I value is correct, otherwise False
210+
:rtype: bool
211+
"""
212+
who_am_i = self._getreg(LSM_REG_WHO_AM_I)
213+
return who_am_i == 0x6C
214+
215+
def reset(self, wait_for_reset = True, wait_timeout_ms = 100):
216+
"""
217+
Resets the IMU, and restores all registers to their default values
218+
219+
:param wait_for_reset: Whether to wait for reset to complete
220+
:type wait_for_reset: bool
221+
:param wait_timeout_ms: Timeout in milliseconds when waiting for reset
222+
:type wait_timeout_ms: int
223+
:return: False if timeout occurred, otherwise True
224+
:rtype: bool
225+
"""
226+
# Set BOOT and SW_RESET bits
227+
self.reg_ctrl3_c_byte[0] = self._getreg(LSM_REG_CTRL3_C)
228+
self.reg_ctrl3_c_bits.BOOT = 1
229+
self.reg_ctrl3_c_bits.SW_RESET = 1
230+
self._setreg(LSM_REG_CTRL3_C, self.reg_ctrl3_c_byte[0])
231+
232+
# Wait for reset to complete, if requested
233+
if wait_for_reset:
234+
# Loop with timeout
235+
t0 = time.ticks_ms()
236+
while time.ticks_ms() < (t0 + wait_timeout_ms):
237+
# Check if register has returned to default value (0x04)
238+
self.reg_ctrl3_c_byte[0] = self._getreg(LSM_REG_CTRL3_C)
239+
if self.reg_ctrl3_c_byte[0] == 0x04:
240+
return True
241+
# Timeout occurred
242+
return False
243+
else:
244+
return True
245+
246246
def get_acc_x(self):
247247
"""
248248
:return: The current reading for the accelerometer's X-axis, in mg

0 commit comments

Comments
 (0)