117 lines
4.0 KiB
C++
117 lines
4.0 KiB
C++
#include "RadioSet.h"
|
|
#include "Str.h"
|
|
#include "LinkedList.h"
|
|
#include "Preset.h"
|
|
#include "Utils.h"
|
|
|
|
#include <cstdio>
|
|
#include <ctype.h>
|
|
#include <tt_lvgl_toolbar.h>
|
|
|
|
constexpr const char* TAG = "RadioSet";
|
|
|
|
/*
|
|
void scrollbar_highlight(lv_event_t * e) {
|
|
lv_obj_t * obj = lv_event_get_target(e);
|
|
}*/
|
|
|
|
|
|
void RadioSet::onShow(AppHandle appHandle, lv_obj_t* parent) {
|
|
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
|
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
|
|
|
lv_obj_t* toolbar = tt_lvgl_toolbar_create_for_app(parent, appHandle);
|
|
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
|
|
|
uiDropDownMenu = lv_dropdown_create(toolbar);
|
|
|
|
lv_dropdown_set_options(uiDropDownMenu, LV_SYMBOL_ENVELOPE " Terminal\n" LV_SYMBOL_SETTINGS " Settings");
|
|
lv_dropdown_set_text(uiDropDownMenu, "Menu");
|
|
lv_dropdown_set_symbol(uiDropDownMenu, LV_SYMBOL_DOWN);
|
|
lv_dropdown_set_selected_highlight(uiDropDownMenu, true);
|
|
lv_obj_set_style_border_color(uiDropDownMenu, lv_color_hex(0xFAFAFA), LV_PART_MAIN);
|
|
lv_obj_set_style_border_width(uiDropDownMenu, 1, LV_PART_MAIN);
|
|
lv_obj_align(uiDropDownMenu, LV_ALIGN_RIGHT_MID, 0, 0);
|
|
lv_obj_set_width(uiDropDownMenu, 120);
|
|
|
|
lv_obj_t* wrapper = lv_obj_create(parent);
|
|
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_flex_align(wrapper, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
lv_obj_set_flex_grow(wrapper, 1);
|
|
lv_obj_set_width(wrapper, LV_PCT(100));
|
|
lv_obj_set_height(wrapper, LV_PCT(100));
|
|
lv_obj_set_style_pad_all(wrapper, 0, LV_PART_MAIN);
|
|
lv_obj_set_style_pad_row(wrapper, 0, LV_PART_MAIN);
|
|
lv_obj_set_style_border_width(wrapper, 0, 0);
|
|
lv_obj_remove_flag(wrapper, LV_OBJ_FLAG_SCROLLABLE);
|
|
|
|
termView = new TermView(wrapper);
|
|
settingsView = new SettingsView(wrapper);
|
|
|
|
auto presetMtEu868LongFast = new Preset("MT EU868 LongFast", MODULATION_LORA);
|
|
presetMtEu868LongFast->addParameter(RADIO_FREQUENCY, 869.525);
|
|
presetMtEu868LongFast->addParameter(RADIO_POWER, 22.0);
|
|
presetMtEu868LongFast->addParameter(RADIO_BOOSTEDGAIN, true);
|
|
presetMtEu868LongFast->addParameter(RADIO_BANDWIDTH, 250.0);
|
|
presetMtEu868LongFast->addParameter(RADIO_SPREADFACTOR, 11);
|
|
presetMtEu868LongFast->addParameter(RADIO_CODINGRATE, 5);
|
|
presetMtEu868LongFast->addParameter(RADIO_SYNCWORD, 0x2B);
|
|
presetMtEu868LongFast->addParameter(RADIO_PREAMBLES, 16);
|
|
|
|
settingsView->addPreset(presetMtEu868LongFast);
|
|
settingsView->updatePresets();
|
|
|
|
for (auto iter = settingsView->radios.begin(); iter != settingsView->radios.end(); iter++) {
|
|
termView->addRadio(*iter);
|
|
}
|
|
|
|
showView(View::Terminal);
|
|
|
|
lv_obj_add_event_cb(uiDropDownMenu, [](lv_event_t * e) {
|
|
RadioSet* self = (RadioSet*)lv_event_get_user_data(e);
|
|
lv_obj_t* input = lv_event_get_target_obj(e);
|
|
switch (lv_dropdown_get_selected(input)) {
|
|
case 0:
|
|
self->showView(View::Terminal);
|
|
break;
|
|
case 1:
|
|
self->showView(View::Settings);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}, LV_EVENT_VALUE_CHANGED, this);
|
|
}
|
|
|
|
|
|
RadioSet::~RadioSet() {
|
|
if (termView) {
|
|
delete termView;
|
|
}
|
|
if (settingsView) {
|
|
delete settingsView;
|
|
}
|
|
}
|
|
|
|
void RadioSet::showView(View view) {
|
|
termView->setVisible(false);
|
|
settingsView->setVisible(false);
|
|
switch (view) {
|
|
case View::Terminal:
|
|
termView->setVisible(true);
|
|
break;
|
|
case View::Settings:
|
|
settingsView->setVisible(true);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
// This function is called with any "pure virtual" method, i.e. it should never happen
|
|
// TODO: I was wrong about it being related to the STL, it is a core feature that needs
|
|
// to be bridged with the tt_init.cpp symbol table
|
|
extern "C" void __cxa_pure_virtual() { crash("Entered the Virtual Zone..."); }
|