Repository navigation
Expand file tree
/
Copy pathBlinkerDebug.cpp
More file actions
129 lines (117 loc) · 2.65 KB
/
Copy pathBlinkerDebug.cpp
File metadata and controls
129 lines (117 loc) · 2.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "Blinker/BlinkerDebug.h"
#include <stddef.h>
#ifdef ESP8266
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "mem.h"
}
#include <Esp.h>
#else
#include <inttypes.h>
#endif
#if defined(ARDUINO)
#if (defined(__AVR__))
#include <avr/pgmspace.h>
#elif defined(ESP8266) || defined(ESP32)
#include <pgmspace.h>
#endif
#endif
uint32_t BLINKER_FreeHeap()
{
#if defined(ARDUINO)
#if defined(ESP8266) || defined(ESP32)
return ESP.getFreeHeap();
// #elif defined(ARDUINO) && defined(ESP32)
// return ESP.getFreeHeap();
#elif defined(__AVR__)
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
#else
return 0;
#endif
#else
return 0;
#endif
}
BlinkerDebug BLINKER_DEBUG;
void BlinkerDebug::stream(Stream& s, blinker_debug_level_t level)
{
isInit = true;
debugger = &s;
debug_level = level;
}
void BlinkerDebug::time()
{
if (debug_level != _debug_none)
{
debugger->print(BLINKER_DEBUG_F("["));
debugger->print(millis());
debugger->print(BLINKER_DEBUG_F("] "));
}
return;
}
// uint32_t BlinkerDebug::BLINKER_FreeHeap()
// {
// #if defined(ARDUINO)
// #if defined(ESP8266) || defined(ESP32)
// return ESP.getFreeHeap();
// // #elif defined(ARDUINO) && defined(ESP32)
// // return ESP.getFreeHeap();
// #elif defined(__AVR__)
// extern int __heap_start, *__brkval;
// int v;
// return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
// #else
// return 0;
// #endif
// #else
// return 0;
// #endif
// }
void BlinkerDebug::freeheap()
{
if (debug_level != _debug_none)
{
// time();
// debugger->print(BLINKER_DEBUG_F("Freeheap: "));
debugger->println(BLINKER_FreeHeap());
}
return;
}
void BLINKER_LOG_TIME()
{
if (BLINKER_DEBUG.isDebug())
{
BLINKER_DEBUG.print(BLINKER_DEBUG_F("["));
BLINKER_DEBUG.print(millis());
BLINKER_DEBUG.print(BLINKER_DEBUG_F("] "));
}
return;
}
void BLINKER_LOG_FreeHeap()
{
if (BLINKER_DEBUG.isDebug())
{
BLINKER_LOG_TIME();
BLINKER_DEBUG.print(BLINKER_DEBUG_F("Freeheap: "));
BLINKER_DEBUG.freeheap();
}
return;
}
void BLINKER_LOG_FreeHeap_ALL()
{
if (BLINKER_DEBUG.isDebugAll())
{
BLINKER_LOG_TIME();
BLINKER_DEBUG.print(BLINKER_DEBUG_F("Freeheap: "));
BLINKER_DEBUG.freeheap();
}
return;
}
void BLINKER_LOG_T()
{
if (BLINKER_DEBUG.isDebug()) BLINKER_DEBUG.println();
return;
}