Krolyxon
Commit eb3af5b

Branches

Tags

Refs →

orion-rfsrcutilssysinfo.cpp

84 lines · 2.3 KB · C++

1#include "ui/display.h"
2#include "buttons.h"
3#include <Arduino.h>
4#include <esp_chip_info.h>
5#include <esp_heap_caps.h>
6
7void runSystemInfoFeature() {
8 esp_chip_info_t chip_info;
9
10 esp_chip_info(&chip_info);
11
12 while (true) {
13 // u8g2.clearBuffer();
14
15 // char buf[32];
16
17 // sprintf(buf, "Cores: %d", chip_info.cores);
18 // u8g2.drawStr(0, 14, buf);
19
20 // sprintf(buf, "Heap: %d",
21 // heap_caps_get_free_size(MALLOC_CAP_DEFAULT));
22 // u8g2.drawStr(0, 28, buf);
23
24 // u8g2.drawStr(0, 60, "BACK to exit");
25
26 // Get RAM info
27 size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_DEFAULT);
28 size_t totalHeap = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
29 int ramUsage = 100 - ((freeHeap * 100) / totalHeap);
30
31 // Get Flash info
32 // uint32_t flashSize = spi_flash_get_chip_size();
33 uint32_t flashSize = ESP.getFlashChipSize();
34 uint32_t flashUsed = ESP.getSketchSize();
35 int flashUsage = (flashUsed * 100) / flashSize;
36
37 // Temperature (approx)
38 uint8_t temperature = temperatureRead();
39
40 // Chip info
41 esp_chip_info_t chip_info;
42 esp_chip_info(&chip_info);
43
44 u8g2.clearBuffer();
45 u8g2.setFont(u8g2_font_6x12_tr);
46
47 char buf[32];
48
49 // Box 1 - RAM
50 u8g2.drawFrame(0, 0, 128, 12);
51 sprintf(buf, "RAM: %d%% used", ramUsage);
52 u8g2.drawStr(4, 9, buf);
53
54 // Box 2 - Flash
55 u8g2.drawFrame(0, 12, 128, 12);
56 sprintf(buf, "Flash: %d%% used", flashUsage);
57 u8g2.drawStr(4, 21, buf);
58
59 // Box 3 - Temp (FULL WIDTH now)
60 u8g2.drawFrame(0, 24, 128, 12);
61 sprintf(buf, "Temp: %d C", temperature);
62 u8g2.drawStr(4, 33, buf);
63
64 // Box 4 - Chip info (FULL WIDTH)
65 u8g2.drawFrame(0, 36, 128, 12);
66 sprintf(buf, "Cores: %d Rev: %d", chip_info.cores, chip_info.revision);
67 u8g2.drawStr(4, 45, buf);
68
69 // Box 5 - PSRAM (KB)
70 u8g2.drawFrame(0, 48, 128, 12);
71 sprintf(buf, "PSRAM: %lu KB",
72 heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024);
73 u8g2.drawStr(4, 57, buf);
74
75 u8g2.sendBuffer();
76
77 if (btnBack()) {
78 delay(200);
79 return;
80 }
81
82 delay(100);
83 }
84}