Added dual debug

This commit is contained in:
MATBckh22 2025-09-21 00:41:42 +08:00
parent 8b87e4c3ac
commit 3fc2951e3c
6 changed files with 131 additions and 2 deletions

View File

@ -37,8 +37,8 @@ ScanI2C::FoundDevice ScanI2C::firstKeyboard() const
ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
{
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160, STK8BAXX, ICM20948, QMA6100P, BMM150};
return firstOfOrNONE(9, types);
ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3, BMX160, STK8BAXX, ICM20948, QMA6100P, BMM150, QMC6310};
return firstOfOrNONE(10, types);
}
ScanI2C::FoundDevice ScanI2C::firstAQI() const

View File

@ -128,6 +128,9 @@ ButtonThread *CancelButtonThread = nullptr;
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C
#include "motion/AccelerometerThread.h"
AccelerometerThread *accelerometerThread = nullptr;
#if defined(IMU_CS)
AccelerometerThread *qmi8658DebugThread = nullptr;
#endif
#endif
#ifdef HAS_I2S
@ -826,6 +829,13 @@ void setup()
#if !defined(ARCH_STM32WL)
if (acc_info.type != ScanI2C::DeviceType::NONE) {
accelerometerThread = new AccelerometerThread(acc_info.type);
#if defined(IMU_CS) && defined(QMI8658_DEBUG_STREAM)
// Also start a parallel SPI QMI8658 thread for debug streaming
if (!qmi8658DebugThread) {
LOG_INFO("Starting SPI QMI8658 debug thread");
qmi8658DebugThread = new AccelerometerThread(ScanI2C::DeviceType::QMI8658);
}
#endif
}
#ifdef IMU_CS
else {

View File

@ -68,6 +68,9 @@ extern graphics::Screen *screen;
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C
#include "motion/AccelerometerThread.h"
extern AccelerometerThread *accelerometerThread;
#if defined(IMU_CS)
extern AccelerometerThread *qmi8658DebugThread;
#endif
#endif
extern bool isVibrating;

View File

@ -11,6 +11,7 @@
#include "BMA423Sensor.h"
#endif
#include "BMM150Sensor.h"
#include "QMC6310Sensor.h"
#include "BMX160Sensor.h"
#include "ICM20948Sensor.h"
#include "LIS3DHSensor.h"
@ -123,6 +124,11 @@ class AccelerometerThread : public concurrency::OSThread
case ScanI2C::DeviceType::BMM150:
sensor = new BMM150Sensor(device);
break;
#if __has_include(<SensorQMC6310.hpp>)
case ScanI2C::DeviceType::QMC6310:
sensor = new QMC6310Sensor(device);
break;
#endif
#ifdef HAS_QMA6100P
case ScanI2C::DeviceType::QMA6100P:
sensor = new QMA6100PSensor(device);

View File

@ -0,0 +1,84 @@
#include "QMC6310Sensor.h"
#include <Arduino.h>
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include(<SensorQMC6310.hpp>)
#if !defined(MESHTASTIC_EXCLUDE_SCREEN)
// screen is defined in main.cpp
extern graphics::Screen *screen;
#endif
QMC6310Sensor::QMC6310Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
bool QMC6310Sensor::init()
{
#if defined(WIRE_INTERFACES_COUNT) && (WIRE_INTERFACES_COUNT > 1)
TwoWire &bus = (device.address.port == ScanI2C::I2CPort::WIRE1 ? Wire1 : Wire);
#else
TwoWire &bus = Wire; // fallback if only one I2C interface
#endif
LOG_DEBUG("QMC6310: begin on addr 0x%02X (port=%d)", device.address.address, device.address.port);
if (!sensor.begin(bus, device.address.address)) {
LOG_DEBUG("QMC6310: init failed (begin)");
return false;
}
uint8_t id = sensor.getChipID();
LOG_DEBUG("QMC6310: chip id=0x%02x", id);
// Configure magnetometer for continuous sampling
int rc = sensor.configMagnetometer(SensorQMC6310::MODE_CONTINUOUS, // mode
SensorQMC6310::RANGE_2G, // measurement range
SensorQMC6310::DATARATE_50HZ, // ODR
SensorQMC6310::OSR_8, // oversample
SensorQMC6310::DSR_1); // downsample
if (rc < 0) {
LOG_DEBUG("QMC6310: configMagnetometer failed (%d)", rc);
return false;
}
// Optional: magnetic declination (degrees). Default 0.
sensor.setDeclination(0.0f);
LOG_DEBUG("QMC6310: init ok");
return true;
}
int32_t QMC6310Sensor::runOnce()
{
Polar p;
if (sensor.readPolar(p)) {
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) && HAS_SCREEN
float heading = p.polar;
switch (config.display.compass_orientation) {
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_0_INVERTED:
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_0:
break;
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_90:
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_90_INVERTED:
heading += 90;
break;
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_180:
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_180_INVERTED:
heading += 180;
break;
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_270:
case meshtastic_Config_DisplayConfig_CompassOrientation_DEGREES_270_INVERTED:
heading += 270;
break;
}
if (screen)
screen->setHeading(heading);
#endif
// Throttled debug output (once per second)
uint32_t now = millis();
if (now - lastLogMs > 1000) {
lastLogMs = now;
LOG_DEBUG("QMC6310: heading=%.1f deg, |B|=%.1f uT", p.polar, p.uT);
}
}
return MOTION_SENSOR_CHECK_INTERVAL_MS;
}
#endif

View File

@ -0,0 +1,26 @@
#pragma once
#ifndef _QMC6310_SENSOR_H_
#define _QMC6310_SENSOR_H_
#include "MotionSensor.h"
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && __has_include(<SensorQMC6310.hpp>)
#include <SensorQMC6310.hpp>
class QMC6310Sensor : public MotionSensor
{
private:
SensorQMC6310 sensor;
uint32_t lastLogMs = 0;
public:
explicit QMC6310Sensor(ScanI2C::FoundDevice foundDevice);
virtual bool init() override;
virtual int32_t runOnce() override;
};
#endif
#endif