Skip to content

Commit ac89ca2

Browse files
authored
RSSI draw/ Level app opt (#2403)
* change peak from green to orange * add db
1 parent 498369b commit ac89ca2

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

firmware/application/apps/ui_level.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
187187
if (last_max_db != statistics.max_db) {
188188
last_max_db = statistics.max_db;
189189
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
190+
rssi.set_db(statistics.max_db);
190191
}
191192
// refresh rssi
192193
if (last_min_rssi != rssi_graph.get_graph_min() || last_avg_rssi != rssi_graph.get_graph_avg() || last_max_rssi != rssi_graph.get_graph_max()) {

firmware/application/ui/ui_rssi.cpp

+29-4
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,19 @@ void RSSI::paint(Painter& painter) {
100100
const Rect r5{r.left() + peak - 3, r.top(), 3, r.height()};
101101
painter.fill_rectangle(
102102
r5,
103-
Theme::getInstance()->fg_green->foreground);
103+
Theme::getInstance()->fg_orange->foreground);
104104
}
105+
106+
// dB - x
107+
constexpr int db_min = -80;
108+
constexpr int db_max = 10;
109+
constexpr int db_delta = db_max - db_min;
110+
const range_t<int> x_db_range{0, r.width() - 1};
111+
const int16_t x_db = x_db_range.clip((db_ - db_min) * r.width() / db_delta);
112+
113+
const Rect r_db{r.left() + x_db, r.top(), 1, r.height()};
114+
115+
if (db_) painter.fill_rectangle(r_db, Color::green());
105116
} else {
106117
// vertical bottom to top level meters
107118
const range_t<int> y_avg_range{0, r.height() - 1};
@@ -115,7 +126,7 @@ void RSSI::paint(Painter& painter) {
115126

116127
// y_min
117128
const Rect r0{r.left(), r.bottom() - y_min, r.width(), y_min};
118-
painter.fill_rectangle(
129+
painter.fill_rectangle( // TODO: the blue plot is broken in vertical bars, not from the dB PR (#2403)
119130
r0,
120131
Color::blue());
121132

@@ -149,8 +160,18 @@ void RSSI::paint(Painter& painter) {
149160
const Rect r5{r.left(), r.bottom() - peak - 3, r.width(), 3};
150161
painter.fill_rectangle(
151162
r5,
152-
Color::green());
163+
Color::orange());
153164
}
165+
166+
// dB - y
167+
constexpr int db_min = -80;
168+
constexpr int db_max = 10;
169+
constexpr int db_delta = db_max - db_min;
170+
const range_t<int> y_db_range{0, r.height() - 1};
171+
const int16_t y_db = y_db_range.clip((db_ - db_min) * r.height() / db_delta);
172+
173+
const Rect r_db{r.left(), r.bottom() - y_db, r.width(), 3};
174+
if (db_) painter.fill_rectangle(r_db, Color::green());
154175
}
155176
if (pitch_rssi_enabled) {
156177
baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true);
@@ -159,7 +180,7 @@ void RSSI::paint(Painter& painter) {
159180
const Rect r6{r.left(), r.top(), r.width(), r.height()};
160181
painter.draw_rectangle(
161182
r6,
162-
Color::white());
183+
Color::white()); // TODO this and all the following Color struct call should satisfy the new "theme" system ref
163184
}
164185
}
165186

@@ -500,4 +521,8 @@ bool RSSI::on_touch(const TouchEvent event) {
500521
return false;
501522
}
502523
}
524+
525+
void RSSI::set_db(int16_t db) {
526+
db_ = db;
527+
}
503528
} /* namespace ui */

firmware/application/ui/ui_rssi.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ class RSSI : public Widget {
6161
void on_focus() override;
6262
bool on_key(const KeyEvent key) override;
6363
bool on_touch(const TouchEvent event) override;
64+
void set_db(int16_t db);
6465

6566
private:
6667
int8_t min_ = 0;
6768
int8_t avg_ = 0;
6869
int8_t max_ = 0;
6970
int8_t peak_ = 0;
7071
size_t peak_duration_ = 0;
72+
int16_t db_ = 0;
7173
bool instant_exec_{false};
7274

7375
bool pitch_rssi_enabled = false;

0 commit comments

Comments
 (0)