2016-01-05 05:47:46 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-05-11 06:45:03 -04:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2016-01-05 05:47:46 -05:00
|
|
|
*
|
|
|
|
* 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_sigfrx.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "evtimer.h"
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "event_m0.hpp"
|
2016-01-05 05:47:46 -05:00
|
|
|
#include "ff.h"
|
|
|
|
#include "hackrf_gpio.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "radio.hpp"
|
2016-02-04 04:27:53 -05:00
|
|
|
|
|
|
|
#include "string_format.hpp"
|
2016-01-05 05:47:46 -05:00
|
|
|
|
|
|
|
#include "hackrf_hal.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
using namespace portapack;
|
2016-01-05 05:47:46 -05:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void SIGFRXView::focus() {
|
2023-05-18 16:16:05 -04:00
|
|
|
button_exit.focus();
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SIGFRXView::~SIGFRXView() {
|
2023-05-18 16:16:05 -04:00
|
|
|
receiver_model.disable();
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIGFRXView::paint(Painter& painter) {
|
2023-05-18 16:16:05 -04:00
|
|
|
uint8_t i, xp;
|
|
|
|
|
|
|
|
// portapack::display.drawBMP({0, 302-160}, fox_bmp);
|
|
|
|
portapack::display.fill_rectangle({0, 16, 240, 160 - 16}, ui::Color::white());
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
xp = sigfrx_marks[i * 3];
|
|
|
|
painter.draw_string({(ui::Coord)sigfrx_marks[(i * 3) + 1], 144 - 20}, style_white, to_string_dec_uint(sigfrx_marks[(i * 3) + 2]));
|
|
|
|
portapack::display.draw_line({xp, 144 - 4}, {xp, 144}, ui::Color::black());
|
|
|
|
}
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIGFRXView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
2023-05-18 16:16:05 -04:00
|
|
|
portapack::display.fill_rectangle({0, 144, 240, 4}, ui::Color::white());
|
|
|
|
|
|
|
|
uint8_t xmax = 0, imax = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < 120; i++) {
|
|
|
|
if (spectrum.db[i] > xmax) {
|
|
|
|
xmax = spectrum.db[i];
|
|
|
|
imax = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 136; i < 256; i++) {
|
|
|
|
if (spectrum.db[i - 16] > xmax) {
|
|
|
|
xmax = spectrum.db[i - 16];
|
|
|
|
imax = i - 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((imax >= last_channel - 2) && (imax <= last_channel + 2)) {
|
|
|
|
if (detect_counter >= 5) {
|
|
|
|
// Latched !
|
|
|
|
} else {
|
|
|
|
detect_counter++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (detect_counter >= 5) text_channel.set("... ");
|
|
|
|
detect_counter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_channel = imax;
|
|
|
|
|
|
|
|
portapack::display.fill_rectangle({(ui::Coord)(imax - 2), 144, 4, 4}, ui::Color::red());
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIGFRXView::on_show() {
|
2023-05-18 16:16:05 -04:00
|
|
|
/*EventDispatcher::message_map().register_handler(Message::ID::ChannelSpectrum,
|
|
|
|
[this](const Message* const p) {
|
|
|
|
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
|
|
|
}
|
|
|
|
);*/
|
2016-02-04 04:27:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SIGFRXView::on_hide() {
|
2023-05-18 16:16:05 -04:00
|
|
|
// EventDispatcher::message_map().unregister_handler(Message::ID::ChannelSpectrum);
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SIGFRXView::SIGFRXView(
|
2023-05-18 16:16:05 -04:00
|
|
|
NavigationView& nav) {
|
|
|
|
receiver_model.set_baseband_configuration({
|
|
|
|
.mode = 255, // DEBUG
|
|
|
|
.sampling_rate = 3072000,
|
|
|
|
.decimation_factor = 4,
|
|
|
|
});
|
2023-06-11 14:47:13 -04:00
|
|
|
// TODO: use settings.
|
2023-05-18 16:16:05 -04:00
|
|
|
receiver_model.set_lna(0);
|
|
|
|
receiver_model.set_vga(0);
|
2023-06-14 03:57:20 -04:00
|
|
|
receiver_model.set_target_frequency(868110000);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
add_children({&text_type,
|
|
|
|
&text_channel,
|
|
|
|
&text_data,
|
|
|
|
&button_exit});
|
|
|
|
|
2023-06-07 11:33:32 -04:00
|
|
|
text_type.set_style(&Styles::bg_white);
|
|
|
|
text_channel.set_style(&Styles::bg_white);
|
|
|
|
text_data.set_style(&Styles::bg_white);
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
button_exit.on_select = [&nav](Button&) {
|
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
receiver_model.enable();
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|