-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.cpp
122 lines (101 loc) · 2.96 KB
/
settings.cpp
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
#include "settings.h"
Settings* Settings::fromJson(JsonDocument& json_document)
{
JsonVariant json_foreground = json_document["foreground"];
Color foreground = Color::fromJson(json_foreground);
JsonVariant json_background = json_document["background"];
Color background = Color::fromJson(json_background);
JsonVariant json_menu = json_document["menu"];
Menu menu = Menu::fromJson(json_menu);
JsonVariant json_led = json_document["led"];
LED led = LED::fromJson(json_led);
JsonVariant json_image = json_document["image"];
Image image = Image::fromJson(json_image);
JsonArray json_array = json_document["text"].as<JsonArray>();
std::vector<TextElement> text_elements;
text_elements.reserve(json_array.size());
for (JsonObject json_element: json_array)
{
text_elements.push_back(TextElement::fromJson(json_element));
}
JsonVariant json_qrcode = json_document["qrcode"];
QRCode qrcode = QRCode::fromJson(json_qrcode);
return new Settings(foreground, background, menu, led, image, text_elements, qrcode);
}
#ifdef ENABLE_SHT31
void Settings::begin(LGFX& lcd, Adafruit_NeoPixel& neopixel, Adafruit_SHT31& sht31)
#else
void Settings::begin(LGFX& lcd, Adafruit_NeoPixel& neopixel)
#endif
{
// 代入
_lcd = &lcd;
_neopixel = &neopixel;
// LCDクリア
clearLCD();
// 共通表示
showCommon();
// NeoPixel
_led.begin(_neopixel);
#ifdef ENABLE_SHT31
_sht31 = &sht31;
_sht31->begin(SHT31_ADDRESS);
#endif
}
void Settings::toggleLED()
{
_led.toggle();
}
void Settings::showCommon()
{
// 共通表示
for (TextElement& text_element: _text_elements)
{
text_element.show(_lcd);
}
_menu.show(_lcd);
// 電池アイコン
_lcd->fillRect(10, 7, 15, 10, _foreground.getRGB888());
_lcd->fillRect(25, 10, 3, 4, _foreground.getRGB888());
}
void Settings::showImage()
{
// 画像表示
_image.show(_lcd);
}
void Settings::showQR()
{
// QRコード表示
_qrcode.show(_lcd);
}
void Settings::clearLCD()
{
// LCDクリア
_lcd->fillScreen(_background.getRGB888());
}
void Settings::update()
{
// 更新
// テキスト色指定等
_lcd->setTextColor(_foreground.getRGB888(), _background.getRGB888());
_lcd->setTextDatum(TL_DATUM);
// バッテリ残量
#ifdef BOARD_M5CORE
// 電池残量
const int8_t battery_level = M5.Power.getBatteryLevel();
_lcd->drawString(String(battery_level) + "%", 40, 0);
#endif
#ifdef BOARD_M5CORE2
// 電圧
const float voltage = M5.Axp.GetBatVoltage();
_lcd->drawString(String(voltage) + "V", 40, 0);
#endif
#ifdef ENABLE_SHT31
// 温湿度
const float temperature = _sht31->readTemperature();
const float humidity = _sht31->readHumidity();
_lcd->drawString(String(temperature, 0) + "℃, " + String(humidity, 0) + "%", 40, 24);
#endif
// LED
_led.update(_neopixel);
}