Add Remote App & UI updates. (#1451)

* Alpha order sub-menus
* WIP Getting Remote types outlined
* WIP building UI
* WIP adding RemoteButton control
* WIP Fix build
* WIP Basic editing support
* Border on the active button
* Make TxView2 sane
* Add easier RGB color creation from uint32
* Center some button icons
* WIP Remote - main UI
* WIP main UI mostly working, can send
* Add 'join' utility
* WIP save/load
* Pre-alloc buttons to prevent focus dangling
* Alpha order settings/debug pages
* Add UI for picking capture and set frequency
* WIP Getting really close now
* Fix path for init name
* Some fit & finish
This commit is contained in:
Kyle Reed
2023-09-18 14:22:46 -07:00
committed by GitHub
parent 537cf2e79b
commit fca373d936
27 changed files with 1205 additions and 312 deletions

View File

@@ -82,7 +82,8 @@ class AlphanumView : public TextEntryView {
{192, 214, screen_width / 5, 38},
{},
&bitmap_icon_shift,
Color::dark_grey()};
Color::dark_grey(),
/*vcenter*/ true};
Labels labels{
{{1 * 8, 33 * 8}, "Raw:", Color::light_grey()},

View File

@@ -32,8 +32,25 @@
using namespace portapack;
#define POWER_THRESHOLD_HIGH 47
#define POWER_THRESHOLD_MED 38
#define POWER_THRESHOLD_LOW 17
namespace ui {
/* Gets a style indicating total TX gain level. */
static const Style* get_style_for_gain(uint8_t tot_gain) {
if (tot_gain > POWER_THRESHOLD_HIGH) return &Styles::red;
if (tot_gain > POWER_THRESHOLD_MED)
return &Styles::orange;
if (tot_gain > POWER_THRESHOLD_LOW)
return &Styles::yellow;
return nullptr; // Uses default.
}
/* TransmitterView *******************************************************/
void TransmitterView::paint(Painter& painter) {
@@ -73,21 +90,13 @@ void TransmitterView::on_tx_amp_changed(bool rf_amp) {
}
void TransmitterView::update_gainlevel_styles() {
const Style* new_style_ptr = NULL;
int8_t tot_gain = transmitter_model.tx_gain() + (transmitter_model.rf_amp() ? 14 : 0);
auto style = get_style_for_gain(tot_gain);
if (tot_gain > POWER_THRESHOLD_HIGH) {
new_style_ptr = &style_power_high;
} else if (tot_gain > POWER_THRESHOLD_MED) {
new_style_ptr = &style_power_med;
} else if (tot_gain > POWER_THRESHOLD_LOW) {
new_style_ptr = &style_power_low;
}
field_gain.set_style(new_style_ptr);
text_gain.set_style(new_style_ptr);
field_amp.set_style(new_style_ptr);
text_amp.set_style(new_style_ptr);
field_gain.set_style(style);
text_gain.set_style(style);
field_amp.set_style(style);
text_amp.set_style(style);
}
void TransmitterView::set_transmitting(const bool transmitting) {
@@ -186,89 +195,66 @@ TransmitterView::TransmitterView(
}
TransmitterView::~TransmitterView() {
// TODO: Does this make sense? Seems wrong to have
// what's basically a widget control the radio.
audio::output::stop();
transmitter_model.disable();
baseband::shutdown();
}
/* TransmitterView2 *******************************************************/
/* Simpler transmitter view that only renders TX Gain and Amp.
* There are two modes, NORMAL_UI and SHORT_UI. SHORT_UI abbreviates control labels. */
void TransmitterView2::paint(Painter&) {
// All widgets paint themselves. Don't let base paint.
}
void TransmitterView2::on_tx_gain_changed(int32_t tx_gain) {
transmitter_model.set_tx_gain(tx_gain);
update_gainlevel_styles();
}
TransmitterView2::TransmitterView2(Point pos, bool short_ui) {
// There are two modes, short and !short
// Short: "G:XX A:YY"
// !Short: "Gain:XX Amp:YY"
Dim width = short_ui ? (9 * 8) : (14 * 8);
set_parent_rect({pos, {width, 16}});
add_children({
&text_labels,
&field_gain,
&field_amp,
});
// Set up controls depending UI mode.
text_labels.set(short_ui ? "G: A:" : "Gain: Amp:");
text_labels.set_parent_rect(
short_ui
? Rect{0 * 8, 0 * 16, 7 * 8, 1 * 16}
: Rect{0 * 8, 0 * 16, 12 * 8, 1 * 16});
field_gain.set_parent_rect(
short_ui
? Rect{2 * 8, 0 * 16, 2 * 8, 1 * 16}
: Rect{5 * 8, 0 * 16, 2 * 8, 1 * 16});
field_amp.set_parent_rect(
short_ui
? Rect{7 * 8, 0 * 16, 2 * 8, 1 * 16}
: Rect{12 * 8, 0 * 16, 2 * 8, 1 * 16});
field_gain.set_value(transmitter_model.tx_gain());
field_gain.on_change = [this](uint32_t tx_gain) {
transmitter_model.set_tx_gain(tx_gain);
update_gainlevel_styles();
};
field_amp.set_value(transmitter_model.rf_amp() ? 14 : 0);
field_amp.on_change = [this](uint32_t rf_amp) {
transmitter_model.set_rf_amp(rf_amp > 0);
update_gainlevel_styles();
};
void TransmitterView2::on_tx_amp_changed(bool rf_amp) {
transmitter_model.set_rf_amp(rf_amp);
update_gainlevel_styles();
}
void TransmitterView2::update_gainlevel_styles() {
const Style* new_style_ptr = NULL;
int8_t tot_gain = transmitter_model.tx_gain() + (transmitter_model.rf_amp() ? 14 : 0);
auto style = get_style_for_gain(tot_gain);
if (tot_gain > POWER_THRESHOLD_HIGH) {
new_style_ptr = &style_power_high;
} else if (tot_gain > POWER_THRESHOLD_MED) {
new_style_ptr = &style_power_med;
} else if (tot_gain > POWER_THRESHOLD_LOW) {
new_style_ptr = &style_power_low;
}
field_gain.set_style(new_style_ptr);
text_gain_amp.set_style(new_style_ptr);
field_amp.set_style(new_style_ptr);
field_gain_short_UI.set_style(new_style_ptr);
text_gain_amp_short_UI.set_style(new_style_ptr);
field_amp_short_UI.set_style(new_style_ptr);
}
void TransmitterView2::on_show() {
field_gain.set_value(transmitter_model.tx_gain());
field_amp.set_value(transmitter_model.rf_amp() ? 14 : 0);
field_gain_short_UI.set_value(transmitter_model.tx_gain());
field_amp_short_UI.set_value(transmitter_model.rf_amp() ? 14 : 0);
update_gainlevel_styles();
}
TransmitterView2::TransmitterView2(const Coord x, const Coord y, bool short_UI) {
set_parent_rect({x, y, 20 * 8, 1 * 8});
add_children({
&(short_UI ? text_gain_amp_short_UI : text_gain_amp),
&(short_UI ? field_gain_short_UI : field_gain),
&(short_UI ? field_amp_short_UI : field_amp),
});
if (short_UI) {
field_gain_short_UI.on_change = [this](uint32_t tx_gain) {
on_tx_gain_changed(tx_gain);
};
field_amp_short_UI.on_change = [this](uint32_t rf_amp) {
on_tx_amp_changed((bool)rf_amp);
};
} else {
field_gain.on_change = [this](uint32_t tx_gain) {
on_tx_gain_changed(tx_gain);
};
field_amp.on_change = [this](uint32_t rf_amp) {
on_tx_amp_changed((bool)rf_amp);
};
}
}
TransmitterView2::~TransmitterView2() {
audio::output::stop();
transmitter_model.disable();
baseband::shutdown();
text_labels.set_style(style);
field_gain.set_style(style);
field_amp.set_style(style);
}
} /* namespace ui */

View File

@@ -26,9 +26,9 @@
#include "ui.hpp"
#include "ui_navigation.hpp"
#include "ui_painter.hpp"
#include "ui_receiver.hpp"
#include "ui_styles.hpp"
#include "ui_widget.hpp"
#include "ui_receiver.hpp"
#include "rf_path.hpp"
@@ -37,10 +37,6 @@
#include <algorithm>
#include <functional>
#define POWER_THRESHOLD_HIGH 47
#define POWER_THRESHOLD_MED 38
#define POWER_THRESHOLD_LOW 17
namespace ui {
class TXGainField : public NumberField {
@@ -74,11 +70,8 @@ class TransmitterView : public View {
private:
const Style& style_start = Styles::green;
const Style style_stop = Styles::red;
const Style style_locked = Styles::dark_grey;
const Style style_power_low = Styles::yellow;
const Style style_power_med = Styles::orange;
const Style style_power_high = Styles::red;
const Style& style_stop = Styles::red;
const Style& style_locked = Styles::dark_grey;
bool lock_{false};
bool transmitting_{false};
@@ -134,60 +127,32 @@ class TransmitterView : public View {
void update_gainlevel_styles(void);
};
/* Simpler transmitter view that only renders TX Gain and Amp.
* When short_UI is set it abbreviates control labels. */
class TransmitterView2 : public View {
public:
TransmitterView2(const Coord x, const Coord y, bool short_UI);
~TransmitterView2();
void on_show() override;
void paint(Painter& painter) override;
TransmitterView2(Point pos, bool short_ui);
private:
const Style& style_power_low = Styles::yellow;
const Style& style_power_med = Styles::orange;
const Style& style_power_high = Styles::red;
Text text_gain_amp{
{0, 3 * 8, 5 * 8, 1 * 16},
"Gain: Amp:"};
Text text_labels{
{}, // Set in ctor.
{}};
NumberField field_gain{
{5 * 8, 3 * 8},
{}, // Set in ctor.
2,
{max2837::tx::gain_db_range.minimum, max2837::tx::gain_db_range.maximum},
max2837::tx::gain_db_step,
' '};
NumberField field_amp{
{12 * 8, 3 * 8},
{}, // Set in ctor.
2,
{0, 14},
14,
' '};
Text text_gain_amp_short_UI{
{0, (3 * 8), 5 * 8, 1 * 16},
"Gain A:"};
NumberField field_gain_short_UI{
{(4 * 8) + 2, 3 * 8},
2,
{max2837::tx::gain_db_range.minimum, max2837::tx::gain_db_range.maximum},
max2837::tx::gain_db_step,
' '};
NumberField field_amp_short_UI{
{(9 * 8) - 2, 3 * 8},
2,
{0, 14},
14,
' '};
void on_tx_gain_changed(int32_t tx_gain);
void on_tx_amp_changed(bool rf_amp);
void update_gainlevel_styles(void);
void update_gainlevel_styles();
};
} /* namespace ui */