Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSSI draw/ Level app opt #2403

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firmware/application/apps/ui_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ void LevelView::on_statistics_update(const ChannelStatistics& statistics) {
rssi_graph.add_values(rssi.get_min(), rssi.get_avg(), rssi.get_max(), statistics.max_db);

// refresh db
rssi.set_db(statistics.max_db);
gullradriel marked this conversation as resolved.
Show resolved Hide resolved

if (last_max_db != statistics.max_db) {
last_max_db = statistics.max_db;
freq_stats_db.set("Power: " + to_string_dec_int(statistics.max_db) + " db");
Expand Down
34 changes: 30 additions & 4 deletions firmware/application/ui/ui_rssi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,19 @@ void RSSI::paint(Painter& painter) {
const Rect r5{r.left() + peak - 3, r.top(), 3, r.height()};
painter.fill_rectangle(
r5,
Theme::getInstance()->fg_green->foreground);
Theme::getInstance()->fg_orange->foreground);
}

// dB - x
constexpr int db_min = -80;
constexpr int db_max = 10;
constexpr int db_delta = db_max - db_min;
const range_t<int> x_db_range{0, r.width() - 1};
const int16_t x_db = x_db_range.clip((db_ - db_min) * r.width() / db_delta);

const Rect r_db{r.left() + x_db, r.top(), 1, r.height()};

if (db_) painter.fill_rectangle(r_db, Color::green());
} else {
// vertical bottom to top level meters
const range_t<int> y_avg_range{0, r.height() - 1};
Expand All @@ -115,7 +126,7 @@ void RSSI::paint(Painter& painter) {

// y_min
const Rect r0{r.left(), r.bottom() - y_min, r.width(), y_min};
painter.fill_rectangle(
painter.fill_rectangle( // TODO: the blue plot is broken in vertical bars, not from the dB PR
r0,
Color::blue());

Expand Down Expand Up @@ -149,8 +160,18 @@ void RSSI::paint(Painter& painter) {
const Rect r5{r.left(), r.bottom() - peak - 3, r.width(), 3};
painter.fill_rectangle(
r5,
Color::green());
Color::orange());
}

// dB - y
constexpr int db_min = -80;
constexpr int db_max = 10;
constexpr int db_delta = db_max - db_min;
const range_t<int> y_db_range{0, r.height() - 1};
const int16_t y_db = y_db_range.clip((db_ - db_min) * r.height() / db_delta);

const Rect r_db{r.left(), r.bottom() - y_db, r.width(), 3};
if (db_) painter.fill_rectangle(r_db, Color::green());
}
if (pitch_rssi_enabled) {
baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true);
Expand All @@ -159,7 +180,7 @@ void RSSI::paint(Painter& painter) {
const Rect r6{r.left(), r.top(), r.width(), r.height()};
painter.draw_rectangle(
r6,
Color::white());
Color::white()); // TODO this and all the following Color struct call should satisfy the new "theme" system ref
}
}

Expand Down Expand Up @@ -500,4 +521,9 @@ bool RSSI::on_touch(const TouchEvent event) {
return false;
}
}

void RSSI::set_db(int16_t db) {
db_ = db;
set_dirty();
gullradriel marked this conversation as resolved.
Show resolved Hide resolved
}
} /* namespace ui */
2 changes: 2 additions & 0 deletions firmware/application/ui/ui_rssi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class RSSI : public Widget {
void on_focus() override;
bool on_key(const KeyEvent key) override;
bool on_touch(const TouchEvent event) override;
void set_db(int16_t db);

private:
int8_t min_ = 0;
int8_t avg_ = 0;
int8_t max_ = 0;
int8_t peak_ = 0;
size_t peak_duration_ = 0;
int16_t db_ = 0;
bool instant_exec_{false};

bool pitch_rssi_enabled = false;
Expand Down
Loading