Adding diagnostics
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
// Contains configuration constants:
|
||||
|
||||
#define FIRMWARE_VERSION "1.0.3"
|
||||
#define FIRMWARE_VERSION "1.0.6"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "diagnostics_state.h"
|
||||
|
||||
|
||||
void DiagnosticsState::update()
|
||||
{
|
||||
current.timestamp = millis();
|
||||
current.freeHeap =
|
||||
ESP.getFreeHeap();
|
||||
|
||||
current.minimumFreeHeap =
|
||||
ESP.getMinFreeHeap();
|
||||
|
||||
current.cpuFrequency =
|
||||
ESP.getCpuFreqMHz();
|
||||
|
||||
history[historyIndex] = current;
|
||||
|
||||
historyIndex++;
|
||||
if(historyIndex >= DIAGNOSTIC_HISTORY_SIZE)
|
||||
{
|
||||
historyIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
DiagnosticSample DiagnosticsState::getCurrent()
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DiagnosticSample DiagnosticsState::getHistory(uint8_t index)
|
||||
{
|
||||
if(index >= DIAGNOSTIC_HISTORY_SIZE)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
return history[index];
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
#define DIAGNOSTIC_HISTORY_SIZE 60
|
||||
|
||||
|
||||
struct DiagnosticSample
|
||||
{
|
||||
uint32_t timestamp;
|
||||
uint32_t freeHeap;
|
||||
uint32_t minimumFreeHeap;
|
||||
uint32_t cpuFrequency;
|
||||
};
|
||||
|
||||
|
||||
class DiagnosticsState
|
||||
{
|
||||
public:
|
||||
|
||||
void update();
|
||||
|
||||
|
||||
DiagnosticSample getCurrent();
|
||||
DiagnosticSample getHistory(uint8_t index);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
DiagnosticSample current;
|
||||
DiagnosticSample history[DIAGNOSTIC_HISTORY_SIZE];
|
||||
uint8_t historyIndex = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user