2023-06-14 03:57:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 Kyle Reed
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RADIO_STATE_H__
|
|
|
|
#define __RADIO_STATE_H__
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "receiver_model.hpp"
|
|
|
|
#include "transmitter_model.hpp"
|
|
|
|
|
2023-07-04 19:26:26 -04:00
|
|
|
/* Reinitialized model with defaults so each app can start
|
|
|
|
* with a clean, default model instance. We tried lazily
|
|
|
|
* setting these using the set_configuration_without_update
|
|
|
|
* function, but there are still various UI components
|
|
|
|
* (e.g. Waterfall) that need the radio set in order to load.
|
2023-06-14 03:57:20 -04:00
|
|
|
* NB: This member must be added before SettingsManager. */
|
|
|
|
template <typename TModel, TModel* model>
|
|
|
|
class RadioState {
|
|
|
|
public:
|
2023-07-04 19:26:26 -04:00
|
|
|
RadioState() {
|
|
|
|
model->initialize();
|
2023-06-14 03:57:20 -04:00
|
|
|
}
|
|
|
|
|
2023-07-04 19:26:26 -04:00
|
|
|
RadioState(uint32_t new_bandwidth, uint32_t new_sampling_rate) {
|
|
|
|
model->initialize();
|
2023-06-19 01:48:29 -04:00
|
|
|
model->set_sampling_rate(new_sampling_rate);
|
|
|
|
model->set_baseband_bandwidth(new_bandwidth);
|
2023-06-14 03:57:20 -04:00
|
|
|
}
|
|
|
|
|
2023-07-04 19:26:26 -04:00
|
|
|
// NB: only enabled for RX model.
|
|
|
|
template <
|
|
|
|
typename U = TModel,
|
|
|
|
typename Mode = std::enable_if_t<sizeof(typename U::Mode), typename U::Mode> >
|
|
|
|
RadioState(Mode new_mode) {
|
|
|
|
model->initialize();
|
|
|
|
model->settings().mode = new_mode;
|
2023-06-14 03:57:20 -04:00
|
|
|
}
|
|
|
|
|
2023-07-04 19:26:26 -04:00
|
|
|
// NB: only enabled for RX model.
|
|
|
|
template <
|
|
|
|
typename U = TModel,
|
|
|
|
typename Mode = std::enable_if_t<sizeof(typename U::Mode), typename U::Mode> >
|
|
|
|
RadioState(
|
|
|
|
uint32_t new_bandwidth,
|
|
|
|
uint32_t new_sampling_rate,
|
|
|
|
Mode new_mode) {
|
|
|
|
model->initialize();
|
|
|
|
model->set_sampling_rate(new_sampling_rate);
|
|
|
|
model->set_baseband_bandwidth(new_bandwidth);
|
|
|
|
model->settings().mode = new_mode;
|
|
|
|
}
|
2023-06-14 03:57:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
using RxRadioState = RadioState<ReceiverModel, &portapack::receiver_model>;
|
|
|
|
using TxRadioState = RadioState<TransmitterModel, &portapack::transmitter_model>;
|
|
|
|
|
2023-06-17 10:54:52 -04:00
|
|
|
#endif // __RADIO_STATE_H__
|