Skip to content

Commit

Permalink
Merge branch 'main' into new-bat
Browse files Browse the repository at this point in the history
  • Loading branch information
sctanf authored Jan 31, 2024
2 parents 9e9b3da + 2c8e41c commit e909f27
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ Firmware can work with both ESP8266 and ESP32. Please edit `defines.h` and set y

- Calibration data is written to the flash of your MCU and is unique for each BMI160, keep that in mind if you have detachable aux trackers.

## Infos about ESP32-C3 with direct connection to USB

The ESP32-C3 has two ways to connect the serial port. One is directly via the onboard USB CDC or via the onboard UART.
When the chip is connected to the USB CDC, the serial port shows as `USB Serial Port` in Device Manager. The SlimeVR server will currently not connect to this port.
If you want to set your WiFi credentials, you can use the PlatformIO serial console.
There you have to enter the following: `SET WIFI "SSID" "PASSWORD"`

## Uploading On Linux

Follow the instructions in this link [PlatformIO](https://docs.platformio.org/en/latest//faq.html#platformio-udev-rules), this should solve any permission denied errors
Expand Down
5 changes: 4 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ build_flags =
; -DWIFI_STATIC_GATEWAY=192,168,XXX,XXX
; -DWIFI_STATIC_SUBNET=255,255,255,0

; -DSERVER_IP='"192.168.XXX.XXX"'
; -DSERVER_PORT=6969

; Uncomment below if your board are using 40MHz crystal instead of 26MHz for ESP8266
; -DF_CRYSTAL=40000000

Expand Down Expand Up @@ -93,7 +96,7 @@ upload_speed = 921600

;[env:esp32c3]
;platform = espressif32 @ 6.1.0
;build_flags =
;build_flags =
; ${env.build_flags}
; -DESP32C3
;board = lolin_c3_mini
9 changes: 6 additions & 3 deletions src/batterymonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ void BatteryMonitor::Loop()
}
}
#endif
#if BATTERY_MONITOR == BAT_EXTERNAL
voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier;
#if ESP8266 && BATTERY_MONITOR == BAT_EXTERNAL
voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * ADCVoltageMax / ADCResolution * ADCMultiplier;
#endif
#if ESP32 && BATTERY_MONITOR == BAT_EXTERNAL
voltage = ((float)analogReadMilliVolts(PIN_BATTERY_LEVEL)) / 1000 * ADCMultiplier;
#endif
#if BATTERY_MONITOR == BAT_MCP3021 || BATTERY_MONITOR == BAT_INTERNAL_MCP3021
if (address > 0)
Expand All @@ -91,7 +94,7 @@ void BatteryMonitor::Loop()
if (status == 0)
{
float v = (((uint16_t)(MSB & 0x0F) << 6) | (uint16_t)(LSB >> 2));
v *= batteryADCMultiplier;
v *= ADCMultiplier;
voltage = (voltage > 0) ? min(voltage, v) : v;
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/batterymonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
#include "logging/Logger.h"

#if ESP8266
#define ADCResulution 1023.0 // ESP8266 has 12bit ADC
#define ADCResolution 1023.0 // ESP8266 has 10bit ADC
#define ADCVoltageMax 1.0 // ESP8266 input is 1.0 V = 1023.0
#endif
#if ESP32
#define ADCResulution 4095.0 // ESP32 has 12bit ADC
#define ADCVoltageMax 3.3 // ESP32 input is 3.3 V = 4095.0
#endif
#ifndef ADCResulution
#define ADCResulution 1023.0
#ifndef ADCResolution
#define ADCResolution 1023.0
#endif
#ifndef ADCVoltageMax
#define ADCVoltageMax 1.0
Expand Down Expand Up @@ -68,10 +64,10 @@
// Diagramm:
// (Battery)--- [BATTERY_SHIELD_RESISTANCE] ---(INPUT_BOARD)--- [BATTERY_SHIELD_R2] ---(ESP_INPUT)--- [BATTERY_SHIELD_R1] --- (GND)
// SlimeVR Board can handle max 5V > so analogRead of 5.0V input will result in 1023.0
#define batteryADCMultiplier ADCVoltageMax / ADCResulution * (BATTERY_SHIELD_R1 + BATTERY_SHIELD_R2 + BATTERY_SHIELD_RESISTANCE) / BATTERY_SHIELD_R1
#define ADCMultiplier (BATTERY_SHIELD_R1 + BATTERY_SHIELD_R2 + BATTERY_SHIELD_RESISTANCE) / BATTERY_SHIELD_R1
#elif BATTERY_MONITOR == BAT_MCP3021 || BATTERY_MONITOR == BAT_INTERNAL_MCP3021
// Default recommended resistors are 9.1k and 5.1k
#define batteryADCMultiplier 3.3 / 1023.0 * 14.2 / 9.1
#define ADCMultiplier 3.3 / 1023.0 * 14.2 / 9.1
#endif

class BatteryMonitor
Expand Down
14 changes: 7 additions & 7 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#define BMI160_QMC_REMAP AXIS_REMAP_BUILD(AXIS_REMAP_USE_Y, AXIS_REMAP_USE_XN, AXIS_REMAP_USE_Z, \
AXIS_REMAP_USE_YN, AXIS_REMAP_USE_X, AXIS_REMAP_USE_Z)
IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, PIN_IMU_SDA, BMI160_QMC_REMAP) \
IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, PIN_IMU_SDA, PRIMARY_IMU_OPTIONAL, BMI160_QMC_REMAP) \
*/

#ifndef IMU_DESC_LIST
Expand All @@ -53,8 +53,8 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#endif

// Battery monitoring options (comment to disable):
// BAT_EXTERNAL for ADC pin,
// BAT_INTERNAL for internal - can detect only low battery,
// BAT_EXTERNAL for ADC pin,
// BAT_INTERNAL for internal - can detect only low battery,
// BAT_MCP3021 for external ADC connected over I2C
#define BATTERY_MONITOR BAT_EXTERNAL

Expand All @@ -81,7 +81,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
// LED_PIN
// - Number or Symbol (D1,..) of the Output
// - To turn off the LED, set LED_PIN to LED_OFF
// LED_INVERTED
// LED_INVERTED
// - false for output 3.3V on high
// - true for pull down to GND on high

Expand All @@ -97,7 +97,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 0
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 10
#endif
#ifndef BATTERY_SHIELD_R2
Expand All @@ -117,7 +117,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 0
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 10
#endif
#ifndef BATTERY_SHIELD_R2
Expand All @@ -134,7 +134,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 180
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 100
#endif
#ifndef BATTERY_SHIELD_R2
Expand Down
10 changes: 10 additions & 0 deletions src/network/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ namespace Network {

class Connection {
public:
Connection() {
#ifdef SERVER_IP
m_ServerHost.fromString(SERVER_IP);
#endif

#ifdef SERVER_PORT
m_ServerPort = SERVER_PORT;
#endif
}

void searchForServer();
void update();
void reset();
Expand Down

0 comments on commit e909f27

Please sign in to comment.