-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_page.cpp
More file actions
59 lines (48 loc) · 1.96 KB
/
settings_page.cpp
File metadata and controls
59 lines (48 loc) · 1.96 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
#include "settings_page.h"
#include "config.h"
#include "freertos/idf_additions.h"
#include "jammer.h"
#include "kbd.h"
#include "state.h"
#include "terminal.h"
#include "utils.h"
#include <Arduino.h>
SettingsPage::SettingsPage() {
options.push_back({"TX POWER", 0,
COUNT_OF(GlobalSettings::tx_power_to_dbm) - 1,
[]() { return SystemState::instance().global.tx_power; },
[](int v) { SystemState::instance().global.tx_power = v; },
[](char *buf, int v) {
snprintf(buf, 32, "TX POWER: %ddBm",
GlobalSettings::tx_power_to_dbm[v]);
}});
options.push_back({"SPEED", 0,
COUNT_OF(GlobalSettings::tx_speed_to_bw_mhz) - 1,
[]() { return SystemState::instance().global.tx_speed; },
[](int v) { SystemState::instance().global.tx_speed = v; },
[](char *buf, int v) {
snprintf(buf, 32, "SPEED=%.2fMbps(%dMHz)",
GlobalSettings::tx_speed_to_mbps[v],
GlobalSettings::tx_speed_to_bw_mhz[v]);
}});
}
void SettingsPage::draw() {
auto display = Terminal::instance().get_display();
const int font_cols = Terminal::instance().get_font_cols();
const int font_rows = Terminal::instance().get_font_rows();
const int info_rows = options.size() * font_rows;
display->fillRect(0, 0, DISP_COLS, info_rows, SSD1306_BLACK);
char buffer[64];
for (int i = 0; i < options.size(); ++i) {
int y_pos = i * font_rows;
int current_val = options[i].get_val();
options[i].format_text(buffer, current_val);
draw_text_field(0, y_pos, buffer, i == highlighted);
}
Terminal::instance().get_display()->display();
}
void SettingsPage::handle_input(InputEvent *ev) {
if (handle_basic_select(ev, options, highlighted, selected))
return;
draw();
}