mayhem-firmware/firmware/application/ui_setup.cpp

208 lines
4.8 KiB
C++
Raw Normal View History

2015-07-08 15:39:24 +00:00
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ui_setup.hpp"
2016-07-27 21:15:21 +00:00
#include "ui_touch_calibration.hpp"
#include "portapack_persistent_memory.hpp"
2015-07-08 15:39:24 +00:00
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
2016-01-23 19:32:10 +00:00
#include "portapack.hpp"
using portapack::receiver_model;
#include "cpld_update.hpp"
2015-07-08 15:39:24 +00:00
namespace ui {
SetDateTimeView::SetDateTimeView(
NavigationView& nav
) {
button_ok.on_select = [&nav, this](Button&){
const auto model = this->form_collect();
const rtc::RTC new_datetime {
model.year, model.month, model.day,
model.hour, model.minute, model.second
};
rtcSetTime(&RTCD1, &new_datetime);
nav.pop();
},
button_cancel.on_select = [&nav](Button&){
nav.pop();
},
add_children({
2015-07-08 15:39:24 +00:00
&text_title,
&field_year,
&text_slash1,
&field_month,
&text_slash2,
&field_day,
&field_hour,
&text_colon1,
&field_minute,
&text_colon2,
&field_second,
&text_format,
&button_ok,
&button_cancel,
});
2015-07-08 15:39:24 +00:00
rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime);
SetDateTimeModel model {
datetime.year(),
datetime.month(),
datetime.day(),
datetime.hour(),
datetime.minute(),
datetime.second()
};
form_init(model);
}
void SetDateTimeView::focus() {
button_cancel.focus();
}
void SetDateTimeView::form_init(const SetDateTimeModel& model) {
2015-07-08 15:39:24 +00:00
field_year.set_value(model.year);
field_month.set_value(model.month);
field_day.set_value(model.day);
field_hour.set_value(model.hour);
field_minute.set_value(model.minute);
field_second.set_value(model.second);
}
SetDateTimeModel SetDateTimeView::form_collect() {
return {
.year = static_cast<uint16_t>(field_year.value()),
.month = static_cast<uint8_t>(field_month.value()),
.day = static_cast<uint8_t>(field_day.value()),
.hour = static_cast<uint8_t>(field_hour.value()),
.minute = static_cast<uint8_t>(field_minute.value()),
.second = static_cast<uint8_t>(field_second.value())
};
}
2015-07-26 14:45:24 +00:00
SetFrequencyCorrectionView::SetFrequencyCorrectionView(
NavigationView& nav
) {
button_ok.on_select = [&nav, this](Button&){
const auto model = this->form_collect();
portapack::persistent_memory::set_correction_ppb(model.ppm * 1000);
2015-07-26 14:45:24 +00:00
nav.pop();
},
button_cancel.on_select = [&nav](Button&){
nav.pop();
},
add_children({
2015-07-26 14:45:24 +00:00
&text_title,
&field_ppm,
&text_ppm,
&button_ok,
&button_cancel,
});
2015-07-26 14:45:24 +00:00
SetFrequencyCorrectionModel model {
2015-08-15 22:40:55 +00:00
static_cast<int8_t>(portapack::persistent_memory::correction_ppb() / 1000)
2015-07-26 14:45:24 +00:00
};
form_init(model);
}
void SetFrequencyCorrectionView::focus() {
button_cancel.focus();
}
void SetFrequencyCorrectionView::form_init(const SetFrequencyCorrectionModel& model) {
2015-07-26 14:45:24 +00:00
field_ppm.set_value(model.ppm);
}
SetFrequencyCorrectionModel SetFrequencyCorrectionView::form_collect() {
return {
.ppm = static_cast<int8_t>(field_ppm.value()),
};
}
2016-01-23 19:32:10 +00:00
AntennaBiasSetupView::AntennaBiasSetupView(NavigationView& nav) {
add_children({
2016-01-23 19:32:10 +00:00
&text_title,
&text_description_1,
&text_description_2,
&text_description_3,
&text_description_4,
&options_bias,
&button_done,
});
2016-01-23 19:32:10 +00:00
options_bias.set_by_value(receiver_model.antenna_bias() ? 1 : 0);
options_bias.on_change = [this](size_t, OptionsField::value_t v) {
receiver_model.set_antenna_bias(v);
};
button_done.on_select = [&nav](Button&){ nav.pop(); };
}
void AntennaBiasSetupView::focus() {
button_done.focus();
}
2015-07-08 15:39:24 +00:00
AboutView::AboutView(NavigationView& nav) {
add_children({
2015-07-08 15:39:24 +00:00
&text_title,
&text_firmware,
// &text_cpld_hackrf,
// &text_cpld_hackrf_status,
2015-07-08 15:39:24 +00:00
&button_ok,
});
2015-07-08 15:39:24 +00:00
button_ok.on_select = [&nav](Button&){ nav.pop(); };
/*
if( hackrf::cpld::verify_eeprom() ) {
text_cpld_hackrf_status.set(" OK");
} else {
text_cpld_hackrf_status.set("BAD");
}
*/
2015-07-08 15:39:24 +00:00
}
void AboutView::focus() {
button_ok.focus();
}
SetupMenuView::SetupMenuView(NavigationView& nav) {
add_items({
{ "Date/Time", [&nav](){ nav.push<SetDateTimeView>(); } },
{ "Frequency Correction", [&nav](){ nav.push<SetFrequencyCorrectionView>(); } },
2016-01-23 19:32:10 +00:00
{ "Antenna Bias Voltage", [&nav](){ nav.push<AntennaBiasSetupView>(); } },
2016-07-27 21:15:21 +00:00
{ "Touch", [&nav](){ nav.push<TouchCalibrationView>(); } },
});
2015-07-08 15:39:24 +00:00
on_left = [&nav](){ nav.pop(); };
}
} /* namespace ui */