2016-09-23 11:34:50 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
|
|
|
*
|
|
|
|
* 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_nuoptix.hpp"
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "portapack.hpp"
|
2016-12-09 12:21:47 -05:00
|
|
|
#include "lfsr_random.hpp"
|
2016-09-23 11:34:50 -04:00
|
|
|
#include "string_format.hpp"
|
|
|
|
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void NuoptixView::focus() {
|
2017-01-30 08:10:30 -05:00
|
|
|
number_timecode.focus();
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
NuoptixView::~NuoptixView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
2016-09-23 11:34:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NuoptixView::transmit(bool setup) {
|
2016-12-09 12:21:47 -05:00
|
|
|
uint8_t mod, tone_code;
|
2016-09-23 11:34:50 -04:00
|
|
|
uint8_t c;
|
2016-12-09 12:21:47 -05:00
|
|
|
uint8_t dtmf_message[6];
|
2017-01-10 13:40:33 -05:00
|
|
|
rtc::RTC datetime;
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2016-09-23 14:17:29 -04:00
|
|
|
if (!tx_mode) {
|
2016-09-23 11:34:50 -04:00
|
|
|
transmitter_model.disable();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-23 14:17:29 -04:00
|
|
|
if (tx_mode == IMPROVISE)
|
2016-12-09 12:21:47 -05:00
|
|
|
timecode = lfsr_iterate(timecode) % 1999; // Could be 9999 but that would be one long audio track !
|
2016-09-23 14:17:29 -04:00
|
|
|
|
2016-09-23 11:34:50 -04:00
|
|
|
if (setup) {
|
2017-02-07 17:12:20 -05:00
|
|
|
progressbar.set_max(6 * 2);
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2016-12-26 11:51:30 -05:00
|
|
|
if (tx_mode == IMPROVISE) {
|
|
|
|
// Seed from RTC
|
|
|
|
rtcGetTime(&RTCD1, &datetime);
|
|
|
|
timecode = datetime.day() + datetime.second();
|
|
|
|
} else {
|
2016-09-23 14:17:29 -04:00
|
|
|
timecode = number_timecode.value();
|
2016-12-26 11:51:30 -05:00
|
|
|
}
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
transmitter_model.set_sampling_rate(1536000U);
|
2016-09-23 11:34:50 -04:00
|
|
|
transmitter_model.set_rf_amp(true);
|
|
|
|
transmitter_model.set_lna(40);
|
|
|
|
transmitter_model.set_vga(40);
|
|
|
|
transmitter_model.set_baseband_bandwidth(1750000);
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
dtmf_message[0] = '*'; // "Pre-tone for restart" method #1
|
|
|
|
dtmf_message[1] = 'A'; // "Restart" method #1
|
2016-09-23 11:34:50 -04:00
|
|
|
} else {
|
2016-12-09 12:21:47 -05:00
|
|
|
dtmf_message[0] = '#';
|
|
|
|
dtmf_message[1] = (timecode / 1000) % 10;
|
2016-09-23 11:34:50 -04:00
|
|
|
chThdSleepMilliseconds(92); // 141-49ms
|
|
|
|
number_timecode.set_value(timecode);
|
|
|
|
}
|
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
progressbar.set_value(0);
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
dtmf_message[2] = (timecode / 100) % 10;
|
|
|
|
dtmf_message[3] = (timecode / 10) % 10;
|
|
|
|
dtmf_message[4] = timecode % 10;
|
2016-09-23 11:34:50 -04:00
|
|
|
|
|
|
|
mod = 0;
|
|
|
|
for (c = 1; c < 5; c++)
|
2016-12-09 12:21:47 -05:00
|
|
|
if (dtmf_message[c] <= 9)
|
|
|
|
mod += dtmf_message[c];
|
2016-09-23 11:34:50 -04:00
|
|
|
|
|
|
|
mod = 10 - (mod % 10);
|
|
|
|
if (mod == 10) mod = 0; // Is this right ?
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2016-09-23 11:34:50 -04:00
|
|
|
text_mod.set("Mod: " + to_string_dec_uint(mod));
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
dtmf_message[5] = mod;
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
for (c = 0; c < 6; c++) {
|
|
|
|
tone_code = dtmf_message[c];
|
|
|
|
|
|
|
|
if (tone_code == 'A')
|
|
|
|
tone_code = 10;
|
|
|
|
else if (tone_code == 'B')
|
|
|
|
tone_code = 11;
|
|
|
|
else if (tone_code == 'C')
|
|
|
|
tone_code = 12;
|
|
|
|
else if (tone_code == 'D')
|
|
|
|
tone_code = 13;
|
|
|
|
else if (tone_code == '#')
|
|
|
|
tone_code = 14;
|
|
|
|
else if (tone_code == '*')
|
|
|
|
tone_code = 15;
|
|
|
|
|
|
|
|
shared_memory.bb_data.tones_data.message[c * 2] = tone_code;
|
|
|
|
shared_memory.bb_data.tones_data.message[c * 2 + 1] = 0xFF; // Silence
|
|
|
|
}
|
2016-09-23 11:34:50 -04:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
for (c = 0; c < 16; c++) {
|
2017-04-11 03:42:31 -04:00
|
|
|
baseband::set_tone(c * 2, dtmf_deltas[c][0], NUOPTIX_TONE_LENGTH);
|
|
|
|
baseband::set_tone(c * 2 + 1, dtmf_deltas[c][1], NUOPTIX_TONE_LENGTH);
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
shared_memory.bb_data.tones_data.silence = NUOPTIX_TONE_LENGTH; // 49ms tone, 49ms space
|
|
|
|
|
|
|
|
audio::set_rate(audio::Rate::Hz_24000);
|
2017-04-11 03:42:31 -04:00
|
|
|
baseband::set_tones_config(transmitter_model.bandwidth(), 0, 6 * 2, true, true);
|
2016-09-23 11:34:50 -04:00
|
|
|
|
|
|
|
timecode++;
|
|
|
|
}
|
|
|
|
|
|
|
|
NuoptixView::NuoptixView(
|
|
|
|
NavigationView& nav
|
|
|
|
)
|
|
|
|
{
|
2016-12-09 12:21:47 -05:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_tones);
|
2017-01-30 08:10:30 -05:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2016-09-23 11:34:50 -04:00
|
|
|
&number_timecode,
|
|
|
|
&text_timecode,
|
|
|
|
&text_mod,
|
2017-02-07 17:12:20 -05:00
|
|
|
&progressbar,
|
|
|
|
&tx_view
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2016-09-23 11:34:50 -04:00
|
|
|
|
|
|
|
number_timecode.set_value(1);
|
|
|
|
|
2017-01-30 08:10:30 -05:00
|
|
|
tx_view.on_edit_frequency = [this, &nav]() {
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
2016-09-23 11:34:50 -04:00
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
2017-01-30 08:10:30 -05:00
|
|
|
receiver_model.set_tuning_frequency(f);
|
2016-09-23 11:34:50 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-30 08:10:30 -05:00
|
|
|
tx_view.on_start = [this]() {
|
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
tx_mode = NORMAL;
|
|
|
|
transmit(true);
|
2016-09-23 14:17:29 -04:00
|
|
|
};
|
|
|
|
|
2017-01-30 08:10:30 -05:00
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
tx_mode = IDLE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*button_impro.on_select = [this](Button&){
|
2016-09-23 14:17:29 -04:00
|
|
|
if (tx_mode == IMPROVISE) {
|
|
|
|
tx_mode = IDLE;
|
|
|
|
button_impro.set_text("IMPROVISE");
|
|
|
|
} else if (tx_mode == IDLE) {
|
|
|
|
tx_mode = IMPROVISE;
|
|
|
|
button_impro.set_text("STOP");
|
2016-09-23 11:34:50 -04:00
|
|
|
transmit(true);
|
|
|
|
}
|
2017-01-30 08:10:30 -05:00
|
|
|
};*/
|
2016-09-23 11:34:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|