-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handler.h
More file actions
65 lines (51 loc) · 1.67 KB
/
error_handler.h
File metadata and controls
65 lines (51 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* TT Control, advanced sinusoidal control of multi-phase turntable motors
* Created by Ashley Cox at The Blind Man’s Workshop
* https://theblindmansworkshop.com
* No part of this code may be used or reproduced for commercial purposes without written permission and contractual agreement
* All external libraries and frameworks are the property of their respective authors and governed by their respective licenses
*/
#ifndef ERROR_HANDLER_H
#define ERROR_HANDLER_H
#include <Arduino.h>
#include <LittleFS.h>
#include <vector>
#include "hal.h"
enum ErrorCode {
ERR_NONE = 0,
ERR_SYSTEM_FREEZE = 1,
ERR_MOTOR_STALL = 2,
ERR_SETTINGS_CORRUPT = 3,
ERR_I2C_FAILURE = 4,
ERR_OUT_OF_MEMORY = 5,
ERR_AMP_THERMAL = 6
};
/**
* @brief Centralized Error Handling and Logging.
*
* Capabilities:
* - Logs errors to Serial console
* - Appends errors to persistent file (/error.log)
* - Triggers UI alerts
* - Tracks critical system state
*/
class ErrorHandler {
public:
ErrorHandler();
void begin();
// Report an error occurrence
void report(ErrorCode code, const char* message, bool critical = false);
// Clear all persistent logs
void clearLogs();
// Stream entire log to output (e.g. Serial)
void dumpLog(Stream& out);
// Retrieve log lines for UI display
void getLogLines(std::vector<String>& lines, int maxLines = 50);
// Check if a critical error has occurred since boot
bool hasCriticalError() { return _criticalError; }
private:
bool _criticalError;
void logToFile(ErrorCode code, const char* message);
};
extern ErrorHandler errorHandler;
#endif // ERROR_HANDLER_H