HomeWaterLeaksDetection
FreeMemoryMeasurement.cpp
Go to the documentation of this file.
2 
4 
5 #ifdef WEB_SERVER
6  String HTML_freeRAM(const FreeMemoryMeasurement& freeMemoryMeasurement);
7 #endif
8 
10  #ifdef WEB_SERVER
11  htmlData[16] = &HTML_freeRAM;
12  #endif
13 }
14 
16  if (instance == NULL)
18  return instance;
19 }
20 
22  char top;
23  #ifdef __arm__
24  return &top - reinterpret_cast<char*>(sbrk(0));
25  #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
26  return &top - __brkval;
27  #else // __arm__
28  return __brkval ? &top - __brkval : &top - __malloc_heap_start;
29  #endif // __arm__
30 }
31 
32 #ifdef LCD_DISPLAY
33  const String FreeMemoryMeasurement::getRow(int row) const {
34  switch(row) {
35  case 0:
36  return String("FREE SRAM");
37  case 1:
38  return String(getFreeRAM()) + "B";
39  break;
40  case 2:
41  return "";
42  break;
43  case 3:
44  return "";
45  break;
46  }
47  return "UNTITLED";
48  }
49 #endif
50 
51 #ifdef DEBUG
52  const String FreeMemoryMeasurement::getLogID() const {
53  return "[SRAM]";
54  }
55 
56  const String FreeMemoryMeasurement::getLogDescription() const {
57  return "[" +
58  String("FREE=") + String(getFreeRAM()) + "B" +
59  "]";
60  }
61 #endif
62 
63 #ifdef WEB_SERVER
64  const String FreeMemoryMeasurement::getHTMLData(const int id) const {
65  auto fce = htmlData.find(id);
66  if (fce == htmlData.end())
68  return fce->second(*this);
69  }
70 
71  String HTML_freeRAM(const FreeMemoryMeasurement& freeMemoryMeasurement) {
72  return String(freeMemoryMeasurement.getFreeRAM());
73  }
74 #endif
FreeMemoryMeasurement::instance
static FreeMemoryMeasurement * instance
the instance of the class
Definition: FreeMemoryMeasurement.h:69
FreeMemoryMeasurement::htmlData
std::map< int, String(*)(const FreeMemoryMeasurement &freeMemoryMeasurement)> htmlData
A map of different values (keys) and their associated functions which returns the appropriate values.
Definition: FreeMemoryMeasurement.h:125
FreeMemoryMeasurement::getRow
const String getRow(int row) const override
Returns the content of the row given as a parameter.
FreeMemoryMeasurement::FreeMemoryMeasurement
FreeMemoryMeasurement()
Constructor of the class.
Definition: FreeMemoryMeasurement.cpp:9
FreeMemoryMeasurement
Definition: FreeMemoryMeasurement.h:66
__brkval
char * __brkval
FreeMemoryMeasurement::HTML_freeRAM
friend String HTML_freeRAM(const FreeMemoryMeasurement &freeMemoryMeasurement)
Associated function for returing amount of memory being used at the moment.
HTMLDataSource::UNDEFINED_DATA
static const String UNDEFINED_DATA
string "UNDEFINED"
Definition: HTMLDataSource.h:17
FreeMemoryMeasurement::getInstance
static FreeMemoryMeasurement * getInstance()
Returns the instance of the class.
Definition: FreeMemoryMeasurement.cpp:15
FreeMemoryMeasurement.h
FreeMemoryMeasurement::getHTMLData
const String getHTMLData(const int id) const override
Since this class is registered as a source of data for the HTML content, it needs return the appropri...
FreeMemoryMeasurement::getFreeRAM
int getFreeRAM() const
Return the amount of RAM currently being used.
Definition: FreeMemoryMeasurement.cpp:21