Skip to content

Commit d50727f

Browse files
committed
use fallback if higher frequency is missing
1 parent 65a7393 commit d50727f

File tree

1 file changed

+20
-0
lines changed
  • src/hhd/controller/physical

1 file changed

+20
-0
lines changed

src/hhd/controller/physical/imu.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ def prepare_dev(
121121
write_sysfs(sensor_dir, f"in_{a}_sampling_frequency", f)
122122
except Exception as e:
123123
logger.error(f"Could not set sampling frequency for {a}:\n{e}")
124+
try:
125+
# Select closest higher frequency instead
126+
sfn = os.path.join(
127+
sensor_dir, f"in_{a}_sampling_frequency_available"
128+
)
129+
if os.path.isfile(sfn):
130+
freqs = map(
131+
float,
132+
read_sysfs(
133+
sensor_dir, f"in_{a}_sampling_frequency_available"
134+
).split(),
135+
)
136+
f = next((x for x in freqs if x >= f), None)
137+
if f:
138+
write_sysfs(sensor_dir, f"in_{a}_sampling_frequency", f)
139+
logger.info(
140+
f"Selected higher sampling frequency {f} for {a}"
141+
)
142+
except Exception as e:
143+
logger.error(f"Could not set higher sampling frequency for {a}:\n{e}")
124144

125145
# Set scale
126146
if scales is not None:

0 commit comments

Comments
 (0)