Skip to content

Commit

Permalink
Merge branch 'main' into qmc-mag-new
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Nov 16, 2022
2 parents 4e50fae + 83550d2 commit cca0f5e
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 306 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Releases

on:
push:
tags:
- '*'

jobs:

build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: ncipollo/release-action@v1
with:
artifacts: "./build/*.bin"
draft: true
token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#define IMU_MPU6050_RUNTIME_CALIBRATION // Comment to revert to startup/traditional-calibration
#define BNO_USE_ARVR_STABILIZATION true // Set to false to disable stabilization for BNO085+ IMUs
#define BNO_USE_MAGNETOMETER_CORRECTION false // Set to true to enable magnetometer correction for BNO08x IMUs. Only works with USE_6_AXIS set to true.
#define USE_6_AXIS false // uses 9 DoF (with mag) if false (only for ICM-20948 and BNO08x currently)
#define LOAD_BIAS 1 // Loads the bias values from NVS on start (ESP32 Only)
#define SAVE_BIAS 1 // Periodically saves bias calibration data to NVS (ESP32 Only)
#define USE_6_AXIS false // uses 9 DoF (with mag) if false (only for ICM-20948 and BNO0xx currently)
#define LOAD_BIAS true // Loads the bias values from NVS on start
#define SAVE_BIAS true // Periodically saves bias calibration data to NVS
#define BIAS_DEBUG false // Printing BIAS Variables to serial (ICM20948 only)
#define ENABLE_TAP false // monitor accel for (triple) tap events and send them. Uses more cpu, disable if problems. Server does nothing with value so disabled atm
#define SEND_ACCELERATION true // send linear acceleration to the server
Expand Down Expand Up @@ -78,7 +78,7 @@
// Not recommended for production
#define ENABLE_INSPECTION false

#define FIRMWARE_BUILD_NUMBER 12
#define FIRMWARE_VERSION "0.2.3"
#define FIRMWARE_BUILD_NUMBER 13
#define FIRMWARE_VERSION "0.3.0"

#endif // SLIMEVR_DEBUG_H_
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void setup()

SerialCommands::setUp();

#if IMU == IMU_MPU6500 || IMU == IMU_MPU6050 || IMU == IMU_MPU9250
#if IMU == IMU_MPU6500 || IMU == IMU_MPU6050 || IMU == IMU_MPU9250 || IMU == IMU_BNO055 || IMU == IMU_ICM20948
I2CSCAN::clearBus(PIN_IMU_SDA, PIN_IMU_SCL); // Make sure the bus isn't stuck when resetting ESP without powering it down
// Do it only for MPU, cause reaction of BNO to this is not investigated yet
// Fixes I2C issues for certain IMUs. Only has been tested on IMUs above. Testing advised when adding other IMUs.
#endif
// join I2C bus

Expand Down
65 changes: 58 additions & 7 deletions src/network/wifihandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
unsigned long lastWifiReportTime = 0;
unsigned long wifiConnectionTimeout = millis();
bool isWifiConnected = false;
uint8_t wifiState = 0;
uint8_t wifiState = SLIME_WIFI_NOT_SETUP;
bool hadWifi = false;
unsigned long last_rssi_sample = 0;

Expand Down Expand Up @@ -64,7 +64,7 @@ void WiFiNetwork::setWiFiCredentials(const char * SSID, const char * pass) {
WiFi.begin(SSID, pass);
// Reset state, will get back into provisioning if can't connect
hadWifi = false;
wifiState = 2;
wifiState = SLIME_WIFI_SERVER_CRED_ATTEMPT;
wifiConnectionTimeout = millis();
}

Expand All @@ -76,12 +76,15 @@ void WiFiNetwork::setUp() {
wifiHandlerLogger.info("Setting up WiFi");
WiFi.persistent(true);
WiFi.mode(WIFI_STA);
#if ESP8266
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
#endif
WiFi.hostname("SlimeVR FBT Tracker");
wifiHandlerLogger.info("Loaded credentials for SSID %s and pass length %d", WiFi.SSID().c_str(), WiFi.psk().length());
setStaticIPIfDefined();
wl_status_t status = WiFi.begin(); // Should connect to last used access point, see https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#begin
wifiHandlerLogger.debug("Status: %d", status);
wifiState = 1;
wifiState = SLIME_WIFI_SAVED_ATTEMPT;
wifiConnectionTimeout = millis();

#if ESP8266
Expand Down Expand Up @@ -135,26 +138,74 @@ void WiFiNetwork::upkeep() {
reportWifiError();
if(wifiConnectionTimeout + 11000 < millis()) {
switch(wifiState) {
case 0: // Wasn't set up
case SLIME_WIFI_NOT_SETUP: // Wasn't set up
return;
case 1: // Couldn't connect with first set of credentials
case SLIME_WIFI_SAVED_ATTEMPT: // Couldn't connect with first set of credentials
#if ESP8266
// Try again but with 11G
// But only if there are credentials, otherwise we just waste time before
// switching to hardcoded credentials.
if (WiFi.SSID().length() > 0) {
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
setStaticIPIfDefined();
WiFi.begin();
wifiConnectionTimeout = millis();
wifiHandlerLogger.error("Can't connect from saved credentials, status: %d.", WiFi.status());
wifiHandlerLogger.debug("Trying saved credentials with PHY Mode G...");
} else {
wifiHandlerLogger.debug("Skipping PHY Mode G attempt on 0-length SSID...");
}
#endif
wifiState = SLIME_WIFI_SAVED_G_ATTEMPT;
return;
case SLIME_WIFI_SAVED_G_ATTEMPT: // Couldn't connect with first set of credentials with PHY Mode G
#if defined(WIFI_CREDS_SSID) && defined(WIFI_CREDS_PASSWD)
// Try hardcoded credentials now
#if ESP8266
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
#endif
setStaticIPIfDefined();
WiFi.begin(WIFI_CREDS_SSID, WIFI_CREDS_PASSWD);
wifiConnectionTimeout = millis();
wifiHandlerLogger.error("Can't connect from saved credentials, status: %d.", WiFi.status());
wifiHandlerLogger.debug("Trying hardcoded credentials...");
#endif
wifiState = 2;
wifiState = SLIME_WIFI_HARDCODE_ATTEMPT;
return;
case SLIME_WIFI_HARDCODE_ATTEMPT: // Couldn't connect with second set of credentials
#if defined(WIFI_CREDS_SSID) && defined(WIFI_CREDS_PASSWD) && ESP8266
// Try hardcoded credentials again, but with PHY Mode G
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
setStaticIPIfDefined();
WiFi.begin(WIFI_CREDS_SSID, WIFI_CREDS_PASSWD);
wifiConnectionTimeout = millis();
wifiHandlerLogger.error("Can't connect from saved credentials, status: %d.", WiFi.status());
wifiHandlerLogger.debug("Trying hardcoded credentials with WiFi PHY Mode G...");
#endif
wifiState = SLIME_WIFI_HARDCODE_G_ATTEMPT;
return;
case 2: // Couldn't connect with second set of credentials
case SLIME_WIFI_SERVER_CRED_ATTEMPT: // Couldn't connect with server-sent credentials.
#if ESP8266
// Try again silently but with 11G
WiFi.setPhyMode(WIFI_PHY_MODE_11G);
setStaticIPIfDefined();
WiFi.begin();
wifiConnectionTimeout = millis();
wifiState = SLIME_WIFI_SERVER_CRED_G_ATTEMPT;
#endif
return;
case SLIME_WIFI_HARDCODE_G_ATTEMPT: // Couldn't connect with second set of credentials with PHY Mode G.
case SLIME_WIFI_SERVER_CRED_G_ATTEMPT: // Or if couldn't connect with server-sent credentials
// Start smart config
if(!hadWifi && !WiFi.smartConfigDone() && wifiConnectionTimeout + 11000 < millis()) {
if(WiFi.status() != WL_IDLE_STATUS) {
wifiHandlerLogger.error("Can't connect from any credentials, status: %d.", WiFi.status());
wifiConnectionTimeout = millis();
}
// Return to the default PHY Mode N.
#if ESP8266
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
#endif
startProvisioning();
}
return;
Expand Down
13 changes: 12 additions & 1 deletion src/network/wifihandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ namespace WiFiNetwork {
IPAddress getAddress();
}

#endif // SLIMEVR_WIFI_H_
/** Wifi Reconnection Statuses **/
typedef enum {
SLIME_WIFI_NOT_SETUP = 0,
SLIME_WIFI_SAVED_ATTEMPT,
SLIME_WIFI_SAVED_G_ATTEMPT,
SLIME_WIFI_HARDCODE_ATTEMPT,
SLIME_WIFI_HARDCODE_G_ATTEMPT,
SLIME_WIFI_SERVER_CRED_ATTEMPT,
SLIME_WIFI_SERVER_CRED_G_ATTEMPT
} wifi_reconnection_statuses;

#endif // SLIMEVR_WIFI_H_
8 changes: 5 additions & 3 deletions src/sensors/bmi160sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ void BMI160Sensor::motionLoop() {
mahonyQuaternionUpdate(q, Axyz[0], Axyz[1], Axyz[2], Gxyz[0], Gxyz[1], Gxyz[2], Mxyz[0], Mxyz[1], Mxyz[2], deltat * 1.0e-6f);
#endif
quaternion.set(-q[2], q[1], q[3], q[0]);
quaternion *= sensorOffset;

#if SEND_ACCELERATION
{
this->acceleration[0] = Axyz[0];
this->acceleration[1] = Axyz[1];
// Use the same mapping as in quaternion.set(-q[2], q[1], q[3], q[0]);
this->acceleration[0] = -Axyz[1];
this->acceleration[1] = Axyz[0];
this->acceleration[2] = Axyz[2];

// get the component of the acceleration that is gravity
Expand All @@ -168,6 +168,8 @@ void BMI160Sensor::motionLoop() {
}
#endif

quaternion *= sensorOffset;

#if ENABLE_INSPECTION
{
Network::sendInspectionFusedIMUData(sensorId, quaternion);
Expand Down
6 changes: 6 additions & 0 deletions src/sensors/bno055sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
void BNO055Sensor::motionSetup() {
imu = Adafruit_BNO055(sensorId, addr);
delay(3000);
#if USE_6_AXIS
if (!imu.begin(Adafruit_BNO055::OPERATION_MODE_IMUPLUS))
#else
if (!imu.begin(Adafruit_BNO055::OPERATION_MODE_NDOF))
#endif
{
m_Logger.fatal("Can't connect to BNO055 at address 0x%02x", addr);
ledManager.pattern(50, 50, 200);
return;
}

delay(1000);
imu.setExtCrystalUse(true); //Adafruit BNO055's use external crystal. Enable it, otherwise it does not work.
imu.setAxisRemap(Adafruit_BNO055::REMAP_CONFIG_P0);
imu.setAxisSign(Adafruit_BNO055::REMAP_SIGN_P0);
m_Logger.info("Connected to BNO055 at address 0x%02x", addr);

working = true;
configured = true;
}
Expand Down
Loading

0 comments on commit cca0f5e

Please sign in to comment.