mirror of
https://github.com/SlimeVR/SlimeVR-Tracker-ESP.git
synced 2026-04-06 02:01:57 +02:00
Add defines for different boards
Use INT pin for better reliability
This commit is contained in:
@@ -58,10 +58,10 @@ void BNO080Sensor::motionSetup(DeviceConfig * config)
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef FULL_DEBUG
|
||||
#ifdef FULL_DEBUG
|
||||
imu.enableDebugging(Serial);
|
||||
#endif
|
||||
if(!imu.begin(addr, Wire)) {
|
||||
#endif
|
||||
if(!imu.begin(addr, Wire, PIN_IMU_INT)) {
|
||||
Serial.print("Can't connect to ");
|
||||
Serial.println(IMU_NAME);
|
||||
signalAssert();
|
||||
@@ -69,11 +69,11 @@ void BNO080Sensor::motionSetup(DeviceConfig * config)
|
||||
}
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(IMU_NAME);
|
||||
#if defined(BNO_HAS_ARVR_STABILIZATION) && BNO_HAS_ARVR_STABILIZATION
|
||||
#if defined(BNO_HAS_ARVR_STABILIZATION) && BNO_HAS_ARVR_STABILIZATION
|
||||
imu.enableARVRStabilizedGameRotationVector(13);
|
||||
#else
|
||||
#else
|
||||
imu.enableGameRotationVector(13);
|
||||
#endif
|
||||
#endif
|
||||
lastReset = imu.resetReason();
|
||||
lastData = millis();
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void BNO080Sensor::sendData() {
|
||||
if(newData) {
|
||||
newData = false;
|
||||
sendQuat(&quaternion, PACKET_ROTATION);
|
||||
#ifdef FULL_DEBUG
|
||||
#ifdef FULL_DEBUG
|
||||
Serial.print("Quaternion: ");
|
||||
Serial.print(quaternion.x);
|
||||
Serial.print(",");
|
||||
@@ -116,7 +116,7 @@ void BNO080Sensor::sendData() {
|
||||
Serial.print(quaternion.z);
|
||||
Serial.print(",");
|
||||
Serial.println(quaternion.w);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,13 @@
|
||||
#define IMU_BNO085 4
|
||||
#define IMU_BNO055 5
|
||||
|
||||
#define BOARD_SLIMEVR 1
|
||||
#define BOARD_NODEMCU 2
|
||||
#define BOARD_CUSTOM 3 // Update pinout below if you're using custom board
|
||||
|
||||
// Set parameters of IMU and board used
|
||||
#define IMU IMU_BNO085
|
||||
#define BOARD BOARD_SLIMEVR
|
||||
|
||||
#if IMU == IMU_BNO085
|
||||
#define IMU_NAME "BNO085"
|
||||
@@ -62,6 +68,19 @@
|
||||
#error Select IMU in defines.h
|
||||
#endif
|
||||
|
||||
#if BOARD == BOARD_SLIMEVR
|
||||
#define PIN_IMU_SDA 4
|
||||
#define PIN_IMU_SCL 5
|
||||
#define PIN_IMU_INT 10
|
||||
#define PIN_BATTERY_LEVEL 17
|
||||
#elif BOARD == BOARD_NODEMCU
|
||||
#define PIN_IMU_SDA D3
|
||||
#define PIN_IMU_SCL D2
|
||||
#define PIN_IMU_INT D1
|
||||
#elif BOARD == BOARD_CUSTOM
|
||||
// Define pins by the examples above
|
||||
#endif
|
||||
|
||||
//Debug information
|
||||
//#define FULL_DEBUG
|
||||
#define serialDebug false // Set to true to get Serial output for debugging
|
||||
|
||||
22
src/main.cpp
22
src/main.cpp
@@ -84,7 +84,7 @@ void setup()
|
||||
|
||||
// join I2C bus
|
||||
Wire.flush();
|
||||
Wire.begin(D2, D1);
|
||||
Wire.begin(PIN_IMU_SDA, PIN_IMU_SCL);
|
||||
Wire.setClockStretchLimit(4000);
|
||||
Wire.setClock(100000);
|
||||
Serial.begin(serialBaudRate);
|
||||
@@ -137,13 +137,13 @@ void loop()
|
||||
sensor.startCalibration(0);
|
||||
isCalibrating = false;
|
||||
}
|
||||
#ifndef UPDATE_IMU_UNCONNECTED
|
||||
#ifndef UPDATE_IMU_UNCONNECTED
|
||||
if(isConnected()) {
|
||||
#endif
|
||||
#endif
|
||||
sensor.motionLoop();
|
||||
#ifndef UPDATE_IMU_UNCONNECTED
|
||||
#ifndef UPDATE_IMU_UNCONNECTED
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
// Send updates
|
||||
now_ms = millis();
|
||||
if (now_ms - last_ms >= samplingRateInMillis)
|
||||
@@ -151,19 +151,21 @@ void loop()
|
||||
last_ms = now_ms;
|
||||
processBlinking();
|
||||
|
||||
#ifndef SEND_UPDATES_UNCONNECTED
|
||||
#ifndef SEND_UPDATES_UNCONNECTED
|
||||
if(isConnected()) {
|
||||
#endif
|
||||
#endif
|
||||
sensor.sendData();
|
||||
#ifndef SEND_UPDATES_UNCONNECTED
|
||||
#ifndef SEND_UPDATES_UNCONNECTED
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#ifdef PIN_BATTERY_LEVEL
|
||||
if(now_ms - last_battery_sample >= batterySampleRate) {
|
||||
last_battery_sample = now_ms;
|
||||
float battery = ((float) analogRead(A0)) * batteryADCMultiplier;
|
||||
float battery = ((float) analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier;
|
||||
sendFloat(battery, PACKET_BATTERY_LEVEL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void processBlinking() {
|
||||
|
||||
Reference in New Issue
Block a user