|
|
|
@ -14,6 +14,8 @@
|
|
|
|
|
|
|
|
|
|
#include <Dps310.h> |
|
|
|
|
|
|
|
|
|
#include <Adafruit_ADS1X15.h> |
|
|
|
|
|
|
|
|
|
#include "wifi-credentials.h" |
|
|
|
|
|
|
|
|
|
#include <limits> |
|
|
|
@ -26,6 +28,7 @@ AsyncWebServer server(80);
|
|
|
|
|
|
|
|
|
|
ADC currentSensor(36); |
|
|
|
|
ADC batterySensor(39); |
|
|
|
|
Adafruit_ADS1015 currentSensor2; |
|
|
|
|
Dps310 pressureSensor = Dps310(); |
|
|
|
|
const int8_t speedSensorPin = 13; |
|
|
|
|
const int8_t debugLedPin = 2; |
|
|
|
@ -38,7 +41,8 @@ const float wheelCircumferenceMeters = wheelDiameterInches * 0.0254f * 3.1415f /
|
|
|
|
|
const uint32_t wheelCircumferenceMillimeters = (uint32_t)(wheelCircumferenceMeters * 1000.0f + 0.5f); |
|
|
|
|
|
|
|
|
|
uint16_t batteryVoltage = 0; // in mV
|
|
|
|
|
uint16_t batteryOutputCurrent = 0; // in mV
|
|
|
|
|
uint16_t batteryOutputCurrent = 0; // in mA
|
|
|
|
|
uint16_t batteryOutputCurrent2 = 0; // in mA
|
|
|
|
|
int16_t temperature = 0; // in tenth of °C
|
|
|
|
|
int32_t altitude = 0; // in mm above sea level (can be negative if below sea level, or depending on atmospheric conditions)
|
|
|
|
|
|
|
|
|
@ -197,6 +201,8 @@ void setup()
|
|
|
|
|
|
|
|
|
|
pressureSensor.begin(Wire); |
|
|
|
|
|
|
|
|
|
currentSensor2.begin(0x48, &Wire); |
|
|
|
|
|
|
|
|
|
server.on("/api/debug/log", HTTP_GET, [](AsyncWebServerRequest *request){ |
|
|
|
|
AsyncResponseStream *response = request->beginResponseStream("text/plain"); |
|
|
|
|
int logPartIdx = 0; |
|
|
|
@ -351,6 +357,12 @@ void handle_ADC_measures()
|
|
|
|
|
batteryVoltage = (uint16_t)(averageV * 1000.0f + 0.5f); |
|
|
|
|
batteryOutputCurrent = (uint16_t)(averageC * 1000.0f + 0.5f); |
|
|
|
|
|
|
|
|
|
int16_t batteryOutputCurrent2Int = currentSensor2.readADC_Differential_0_1(); |
|
|
|
|
float batteryOutputCurrent2Volts = (float)batteryOutputCurrent2Int * 3.0f / 1000.0f; |
|
|
|
|
const float shuntResistanceValue = 0.01f; // in ohms
|
|
|
|
|
float batteryOutputCurrent2Amps = batteryOutputCurrent2Volts / shuntResistanceValue; |
|
|
|
|
batteryOutputCurrent2 = (uint16_t)(batteryOutputCurrent2Amps * 1000.0f + 0.5f); |
|
|
|
|
|
|
|
|
|
#if DUMMY_DATA |
|
|
|
|
batteryVoltage = (uint16_t)((float)random(4000, 4020) / 100.0f * 1000.0f + 0.5f); |
|
|
|
|
batteryOutputCurrent = (uint16_t)(max(0.0f, sinf((float)millis()/30000.0f)) * 25.0f * 1000.0f + 0.5f); |
|
|
|
|