This commit is contained in:
Ton Huisman
2026-08-21 20:45:59 +02:00
6 changed files with 48 additions and 31 deletions
@@ -33,6 +33,12 @@
#include <stdlib.h>
#include "SparkFun_VL53L1X.h"
#include "st_src/RangeSensor.h"
#include "st_src/vl53l1_error_codes.h"
#include "st_src/ComponentObject.h"
#include "st_src/RangeSensor.h"
SFEVL53L1X::SFEVL53L1X()
{
_i2cPort = &Wire;
+1 -5
View File
@@ -33,12 +33,8 @@
#pragma once
#include "Arduino.h"
#include "Wire.h"
#include "st_src/RangeSensor.h"
#include "st_src/vl53l1_error_codes.h"
#include "st_src/vl53l1x_class.h"
#include "st_src/ComponentObject.h"
#include "st_src/RangeSensor.h"
#define DISTANCE_SHORT 1
#define DISTANCE_LONG 2
+16 -14
View File
@@ -21,9 +21,11 @@ void TimingStats::add(int32_t duration_usec) {
_timeTotal += static_cast<uint64_t>(duration_usec);
++_count;
if (static_cast<uint32_t>(duration_usec) > _maxVal) { _maxVal = duration_usec; }
const uint32_t duration_usec_u(static_cast<uint32_t>(duration_usec));
if (static_cast<uint32_t>(duration_usec) < _minVal) { _minVal = duration_usec; }
if (duration_usec_u > _maxVal) { _maxVal = duration_usec_u; }
if (duration_usec_u < _minVal) { _minVal = duration_usec_u; }
}
void TimingStats::reset() {
@@ -49,10 +51,7 @@ uint32_t TimingStats::getMinMax(uint32_t& minVal, uint32_t& maxVal) const {
}
bool TimingStats::thresholdExceeded(const uint32_t& threshold) const {
if (_count == 0) {
return false;
}
return _maxVal > threshold;
return (_count > 0u) && (_maxVal > threshold);
}
/********************************************************************************************\
@@ -208,9 +207,7 @@ bool mustLogCFunction(CPlugin::Function function) {
bool mustLogNWFunction(NWPlugin::Function function)
{
if (!Settings.EnableTimingStats()) { return false; }
return true;
return Settings.EnableTimingStats();
}
@@ -348,28 +345,33 @@ String getMiscStatsName(TimingStatsElements stat) {
void stopTimerTask(deviceIndex_t T, int F, uint32_t statisticsTimerStart)
{
if (mustLogFunction(F)) { pluginStats[static_cast<int>(T.value) * 256 + (F)].add(usecPassedSince_fast(statisticsTimerStart)); }
if (!mustLogFunction(F)) return;
pluginStats[(static_cast<int>(T.value) << 8) + (F)].add(usecPassedSince_fast(statisticsTimerStart));
}
void stopTimerController(protocolIndex_t T, CPlugin::Function F, uint32_t statisticsTimerStart)
{
if (mustLogCFunction(F)) { controllerStats[static_cast<int>(T) * 256 + static_cast<int>(F)].add(usecPassedSince_fast(statisticsTimerStart)); }
if (!mustLogCFunction(F)) return;
controllerStats[(static_cast<int>(T) << 8) + static_cast<int>(F)].add(usecPassedSince_fast(statisticsTimerStart));
}
void stopTimerNetwork(ESPEasy::net::networkDriverIndex_t T, NWPlugin::Function F, uint32_t statisticsTimerStart)
{
if (mustLogNWFunction(F)) { networkStats[static_cast<int>(T.value) * 256 + static_cast<int>(F)].add(usecPassedSince_fast(statisticsTimerStart)); }
if (!mustLogNWFunction(F)) return;
networkStats[(static_cast<int>(T.value) << 8) + static_cast<int>(F)].add(usecPassedSince_fast(statisticsTimerStart));
}
void stopTimer(TimingStatsElements L, uint32_t statisticsTimerStart)
{
if (Settings.EnableTimingStats()) { miscStats[L].add(usecPassedSince_fast(statisticsTimerStart)); }
if (!Settings.EnableTimingStats()) return;
miscStats[L].add(usecPassedSince_fast(statisticsTimerStart));
}
void addMiscTimerStat(TimingStatsElements L, int32_t T)
{
if (Settings.EnableTimingStats()) { miscStats[L].add(T); }
if (!Settings.EnableTimingStats()) return;
miscStats[L].add(T);
}
#endif // if FEATURE_TIMING_STATS
+17 -8
View File
@@ -207,15 +207,22 @@ uint8_t getTaskI2CAddress(taskIndex_t taskIndex) {
// ********************************************************************************
#if FEATURE_I2C
bool prepare_I2C_by_taskIndex(taskIndex_t taskIndex, deviceIndex_t DeviceIndex) {
if (!validTaskIndex(taskIndex) || !validDeviceIndex(DeviceIndex)) {
if (!Settings.TaskDeviceEnabled[taskIndex] ||
!validTaskIndex(taskIndex) ||
!validDeviceIndex(DeviceIndex)) {
return false;
}
if (Device[DeviceIndex].Type != DEVICE_TYPE_I2C) {
return true; // No I2C task, so consider all-OK
}
#if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = Settings.getI2CInterface(taskIndex);
#else // if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = 0;
#endif // if FEATURE_I2C_MULTIPLE
if (!Settings.isI2CEnabled(Settings.getI2CInterface(taskIndex))) {
if (!Settings.isI2CEnabled(i2cBus)) {
return false; // Plugin-selected I2C bus is not configured, fail
}
#if FEATURE_CLEAR_I2C_STUCK
@@ -223,11 +230,6 @@ bool prepare_I2C_by_taskIndex(taskIndex_t taskIndex, deviceIndex_t DeviceIndex)
return false; // Bus state is not OK, so do not consider task runnable
}
#endif
#if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = Settings.getI2CInterface(taskIndex);
#else // if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = 0;
#endif // if FEATURE_I2C_MULTIPLE
if (bitRead(Settings.I2C_SPI_bus_Flags[taskIndex], I2C_FLAGS_SLOW_SPEED)) {
I2CSelectLowClockSpeed(i2cBus); // Set to slow, also switch the bus
@@ -246,7 +248,9 @@ bool prepare_I2C_by_taskIndex(taskIndex_t taskIndex, deviceIndex_t DeviceIndex)
}
void post_I2C_by_taskIndex(taskIndex_t taskIndex, deviceIndex_t DeviceIndex) {
if (!validTaskIndex(taskIndex) || !validDeviceIndex(DeviceIndex)) {
if (!Settings.TaskDeviceEnabled[taskIndex] ||
!validTaskIndex(taskIndex) ||
!validDeviceIndex(DeviceIndex)) {
return;
}
@@ -258,6 +262,11 @@ void post_I2C_by_taskIndex(taskIndex_t taskIndex, deviceIndex_t DeviceIndex) {
#else // if FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = 0;
#endif // ifdef ESP32
if (!Settings.isI2CEnabled(i2cBus)) {
return; // Plugin-selected I2C bus is not configured, fail
}
#if FEATURE_I2CMULTIPLEXER
I2CMultiplexerOff(i2cBus);
#endif // if FEATURE_I2CMULTIPLEXER
@@ -2,6 +2,13 @@
#ifdef USES_P113
# if P113_USE_ROI
# include "../Static/WebStaticData.h" // Javascript and support functions
# endif // if P113_USE_ROI
# include <SparkFun_VL53L1X.h>
P113_data_struct::P113_data_struct(uint8_t i2c_addr, int timing, bool range) : i2cAddress(i2c_addr), timing(timing), range(range) {
sensor = new (std::nothrow) SFEVL53L1X();
}
+1 -4
View File
@@ -23,11 +23,8 @@
# endif // if defined(LIMIT_BUILD_SIZE) && defined(ESP8266)
# endif // ifndef P113_USE_ROI
# include <SparkFun_VL53L1X.h>
class SFEVL53L1X; // Forward declaration
# if P113_USE_ROI
# include "../Static/WebStaticData.h" // Javascript and support functions
# endif // if P113_USE_ROI
# define P113_I2C_ADDRESS PCONFIG(0)
# define P113_TIMING PCONFIG(1)