-
Notifications
You must be signed in to change notification settings - Fork 1
/
HeaderSample.h
71 lines (62 loc) · 1.81 KB
/
HeaderSample.h
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
#ifndef _HEADERSAMPLE_H_
#define _HEADERSAMPLE_H_
#include <M5Stack.h>
#include <WiFi.h>
#include <WiFiType.h>
#include <esp_wifi.h>
class HeaderSample {
public:
HeaderSample() {};
uint16_t colorFill = 0x630C;
uint16_t colorFont = 0xffff;
uint8_t font = 0;
int drawStr(const String& src, int x)
{
M5.Lcd.drawString(src, x, 0);
return x + M5.Lcd.textWidth(src);
}
String wifiStatus(wl_status_t src) {
switch (src)
{
case WL_IDLE_STATUS : return "IDLE_STATUS";
case WL_NO_SSID_AVAIL : return "NO_SSID_AVAIL";
case WL_SCAN_COMPLETED : return "SCAN_COMPLETED";
case WL_CONNECTED : return ""; // CONNECTED";
case WL_CONNECT_FAILED : return "CONNECT_FAILED";
case WL_CONNECTION_LOST: return "CONNECTION_LOST";
case WL_DISCONNECTED : return "DISCONNECTED";
default:
break;
}
return "";
}
void draw()
{
M5.Lcd.setTextFont(0);
M5.Lcd.setTextFont(font);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(colorFont, colorFill);
M5.Lcd.drawFastHLine(0, 8, M5.Lcd.width(), 0xC618);
int x = 0;
wifi_mode_t mode;
esp_wifi_get_mode(&mode);
if (mode == WIFI_AP || mode == WIFI_AP_STA) {
x = drawStr("AP:", x);
x = drawStr(WiFi.softAPIP().toString(), x);
x = drawStr(" ", x);
}
if (mode == WIFI_STA || mode == WIFI_AP_STA) {
wl_status_t s = WiFi.status();
x = drawStr(wifiStatus(s), x);
x = drawStr(" ", x);
if (s == WL_CONNECTED) {
x = drawStr(WiFi.localIP().toString(), x);
x = drawStr(" ", x);
}
}
M5.Lcd.setCursor(M5.Lcd.width() - 96, 0);
M5.Lcd.printf("Free%7d Byte", esp_get_free_heap_size());
M5.Lcd.fillRect(x, 0, M5.Lcd.width() - 96-x, 8, colorFill);
}
};
#endif