Commit Graph

19 Commits

Author SHA1 Message Date
Kevin O'Connor 5ff555a705 sensor_mpu9250: No need to send messages when stopping queries
Simplify the mcu code as any messages are ignored by the host anyway.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-19 11:55:15 -05:00
Kevin O'Connor 1a1568c38b mpu9250: Fix incorrect use of time.sleep()
It is not valid to call time.sleep() in the host python code (it could
causes glitches in other processing, and it does not ensure there is a
pause between operations on the mcu).

Use minclock instead of time.sleep() to ensure there is a sufficient
pause during chip startup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2024-01-07 11:59:55 -05:00
Kevin O'Connor c716edafe2 bulk_sensor: Simplify the registration of internal clients in BatchBulkHelper
Previously, the BatchBulkHelper class was designed primarily to
register webhook clients, and internal clients used a wrapper class
that emulated a webhooks client.

Change BatchBulkHelper to support regular internal callbacks, and
introduce a new BatchWebhooksClient class that can translate these
internal callback to webhooks client messages.

This makes it easier to register internal clients that can process the
bulk messages every batch interval.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor 3370134593 bulk_sensor: Rework APIDumpHelper() to BatchBulkHelper()
The APIDumpHelper class is mainly intended to help process messages in
batches.  Rework the class methods to make that more clear.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor acde3720a4 bulk_sensor: New add_mux_endpoint() helper function in APIDumpHelper
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor ffd44c0219 bulk_sensor: Move APIDumpHelper() from motion_report.py to bulk_sensor.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor 3f84501955 adxl345: Add a read_axes_map() helper function
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor 43ce7c0b9a adxl345: No need to implement is_measuring()
The APIDumpHelper class already ensures that the start/stop callbacks
will only be called when needed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor d6a4669ce0 bulk_sensor: Add new ChipClockUpdater helper class
All the accelerometers use a standard response for their query_status
messages.  Create a common helper class to process those responses.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor e67cbbe5c1 bulk_sensor: Add new BulkDataQueue class
Move the bulk sample queue collection to a new helper class in
bulk_sensor.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor 978c294741 bulk_sensor: New file with helper code for reading bulk sensors
Move the ClockSyncRegression class from adxl345.py to a new
bulk_sensors.py file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-26 11:47:21 -05:00
Kevin O'Connor 2c2bb720fa adxl345: Simplify sequence and limit_count upconversion
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2023-12-10 14:59:18 -05:00
Dr. Matthew Swabey 80a7744b42
sensor_mpu9250: Fix or improve reliability (#6170)
Fixes common MPU-9250 accelerometer issues for RPi Linux MCU and
improves reliability on all other architectures by adjusting the MPU-*
reading algorithm to only read whole Klipper messages' worth of
data from MPU-* and eliminating many unnecessary checks of the MPU FIFO
fill-level that consumed bus bandwidth needed for data transfer. Fixes
intermittent "Lost communication with MCU 'rpi'" due to "Timer too
close" and transposed / corrupted data due to FIFO overrun/data loss
when using MPU-* accelerometers. In addition FIFO overrun checks are
performed by testing the MPU interrupt flag vs. inferring from the FIFO
fill level.

Stress tested for 13hrs with two MPU-6500 attached to one I2C bus on RPi
    and one on a PR2040
Stress tested for 23hrs with two MPU-6500 attached to one I2C bus on RPi
    and one on a ATmega328P (Seeduino Nano)

Signed-off-by: Matthew Swabey <matthew@swabey.org>
2023-04-19 12:34:22 -04:00
Yifei Ding d17ef95a3c
mpu9250: add MPU6500 (#5767)
Signed-off-by: Yifei Ding <yifeiding@protonmail.com>
2022-11-19 09:58:24 -05:00
Kevin O'Connor 247a409335 mpu9250: Inline twos_complement() code
Calling python functions can have high overhead.  Inline the
twos_complement code in the _extract_samples() inner loop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-06-20 12:41:24 -04:00
Kevin O'Connor f6734d83b3 mpu9250: Use adxl345.AccelCommandHelper directly
The MPU9250CommandHelper() class is nearly a duplicate of
ADXL345CommandHelper().  Rename ADXL345QueryHelper() to
AccelCommandHelper and remove user facing references to "adxl345". Use
it directly from mpu9250.py .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-06-20 12:41:24 -04:00
Kevin O'Connor 4a7b429115 mpu9250: Use adxl345.ClockSyncRegression directly
The mpu9250.ClockSyncRegression() class is a duplicate of
adxl345.ClockSyncRegression().  Remove the duplicate copy and use the
code from adxl345.py .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-06-20 12:41:24 -04:00
Kevin O'Connor f0ba3a8c52 mpu9250: Use adxl345.AccelQueryHelper directly
The MPU9250QueryHelper() class is a duplicate of ADXL345QueryHelper().
Rename ADXL345QueryHelper() to AccelQueryHelper() and use it directly
from mpu9250.py .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2022-06-20 12:41:24 -04:00
bluesforte f55b9d3e57 mpu9250: Adding support for MPU-9250 (and MPU-6050) accelerometer
Add support for mpu9250 accelerometer over I2C bus.

Signed-off-by: Harry Beyel <harry3b9@gmail.com>
2022-06-16 11:09:33 -04:00