2017-03-14 07:24:04 +00: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_mictx.hpp"
# include "baseband_api.hpp"
# include "audio.hpp"
2022-03-05 21:39:53 +01:00
# include "wm8731.hpp"
using wolfson : : wm8731 : : WM8731 ;
2017-11-09 20:02:34 +00:00
# include "tonesets.hpp"
2018-02-01 11:17:51 +00:00
# include "portapack_hal.hpp"
2022-08-26 18:34:30 +02:00
# include "cpld_update.hpp"
2017-03-14 07:24:04 +00:00
# include "string_format.hpp"
# include "irq_controls.hpp"
# include <cstring>
2017-11-09 20:02:34 +00:00
using namespace tonekey ;
2017-03-14 07:24:04 +00:00
using namespace portapack ;
2022-03-05 21:39:53 +01:00
WM8731 audio_codec_wm8731 { i2c0 , 0x1a } ;
2017-03-14 07:24:04 +00:00
namespace ui {
void MicTXView : : focus ( ) {
2020-08-23 17:41:31 +08:00
switch ( focused_ui ) {
case 0 :
field_frequency . focus ( ) ;
break ;
case 1 :
field_rxfrequency . focus ( ) ;
break ;
default :
2020-08-24 01:53:34 +08:00
field_va . focus ( ) ;
2020-08-23 17:41:31 +08:00
break ;
}
2017-03-14 07:24:04 +00:00
}
void MicTXView : : update_vumeter ( ) {
vumeter . set_value ( audio_level ) ;
}
2017-11-09 20:02:34 +00:00
void MicTXView : : on_tx_progress ( const bool done ) {
// Roger beep played, stop transmitting
if ( done )
set_tx ( false ) ;
}
void MicTXView : : configure_baseband ( ) {
2018-05-15 23:35:30 +01:00
baseband : : set_audiotx_config (
2017-11-09 20:02:34 +00:00
sampling_rate / 20 , // Update vu-meter at 20Hz
transmitting ? transmitter_model . channel_bandwidth ( ) : 0 ,
2018-02-01 11:17:51 +00:00
mic_gain ,
2022-09-28 22:42:33 +02:00
shift_bits_s16 , // to be used in dsp_modulate
2021-03-21 20:11:40 -05:00
TONES_F2D ( tone_key_frequency ( tone_key_index ) , sampling_rate ) ,
enable_am ,
enable_dsb ,
enable_usb ,
enable_lsb
2017-11-09 20:02:34 +00:00
) ;
2021-03-21 20:11:40 -05:00
2017-03-14 07:24:04 +00:00
}
void MicTXView : : set_tx ( bool enable ) {
if ( enable ) {
2020-08-07 00:19:37 -03:00
if ( rx_enabled ) //If audio RX is enabled
rxaudio ( false ) ; //Then turn off audio RX
2017-11-09 20:02:34 +00:00
transmitting = true ;
configure_baseband ( ) ;
2020-08-23 17:41:31 +08:00
transmitter_model . set_tuning_frequency ( tx_frequency ) ;
2020-08-22 14:57:55 +08:00
transmitter_model . set_tx_gain ( tx_gain ) ;
transmitter_model . set_rf_amp ( rf_amp ) ;
2018-02-01 11:17:51 +00:00
transmitter_model . enable ( ) ;
portapack : : pin_i2s0_rx_sda . mode ( 3 ) ; // This is already done in audio::init but gets changed by the CPLD overlay reprogramming
2017-03-14 07:24:04 +00:00
} else {
if ( transmitting & & rogerbeep_enabled ) {
2020-08-07 00:19:37 -03:00
baseband : : request_beep ( ) ; //Transmit the roger beep
transmitting = false ; //And flag the end of the transmission so ...
} else { // (if roger beep was enabled, this will be executed after the beep ends transmitting.
2017-11-09 20:02:34 +00:00
transmitting = false ;
configure_baseband ( ) ;
2018-02-01 11:17:51 +00:00
transmitter_model . disable ( ) ;
2020-08-07 00:19:37 -03:00
if ( rx_enabled ) //If audio RX is enabled and we've been transmitting
rxaudio ( true ) ; //Turn back on audio RX
2017-03-14 07:24:04 +00:00
}
}
}
void MicTXView : : do_timing ( ) {
if ( va_enabled ) {
if ( ! transmitting ) {
// Attack
if ( audio_level > = va_level ) {
if ( ( attack_timer > > 8 ) > = attack_ms ) {
decay_timer = 0 ;
attack_timer = 0 ;
set_tx ( true ) ;
} else {
2017-11-09 20:02:34 +00:00
attack_timer + = lcd_frame_duration ;
2017-03-14 07:24:04 +00:00
}
} else {
attack_timer = 0 ;
}
} else {
// Decay
if ( audio_level < va_level ) {
if ( ( decay_timer > > 8 ) > = decay_ms ) {
decay_timer = 0 ;
attack_timer = 0 ;
set_tx ( false ) ;
} else {
2017-11-09 20:02:34 +00:00
decay_timer + = lcd_frame_duration ;
2017-03-14 07:24:04 +00:00
}
} else {
decay_timer = 0 ;
}
}
} else {
2017-11-09 20:02:34 +00:00
// Check for PTT release
2017-03-14 07:24:04 +00:00
const auto switches_state = get_switches_state ( ) ;
2020-08-24 01:53:34 +08:00
if ( ! switches_state [ 4 ] & & transmitting & & ! button_touch ) // Select button
2017-03-14 07:24:04 +00:00
set_tx ( false ) ;
}
}
2020-08-23 17:41:31 +08:00
/* Hmmmm. Maybe useless now.
2017-03-14 07:24:04 +00:00
void MicTXView : : on_tuning_frequency_changed ( rf : : Frequency f ) {
transmitter_model . set_tuning_frequency ( f ) ;
2020-08-07 00:19:37 -03:00
//if ( rx_enabled )
receiver_model . set_tuning_frequency ( f ) ; //Update freq also for RX
}
2020-08-23 17:41:31 +08:00
*/
2020-08-07 00:19:37 -03:00
void MicTXView : : rxaudio ( bool is_on ) {
if ( is_on ) {
2020-08-07 16:33:17 -03:00
audio : : input : : stop ( ) ;
2020-08-07 00:19:37 -03:00
baseband : : shutdown ( ) ;
2021-03-21 20:11:40 -05:00
2022-10-29 16:02:08 +02:00
if ( enable_am | | enable_usb | | enable_lsb | | enable_dsb ) { // "NFM/FM",0 ," WFM ",1 , " AM ",2, " USB ", 3, " LSB ",4, " DSB-SC", 5
2021-03-21 20:11:40 -05:00
baseband : : run_image ( portapack : : spi_flash : : image_tag_am_audio ) ;
2022-10-29 16:02:08 +02:00
receiver_model . set_modulation ( ReceiverModel : : Mode : : AMAudio ) ; // that AM demodulation engine is common to all Amplitude mod : AM/USB/LSB/DSB (2,3,4,5)
if ( options_mode . selected_index ( ) < 5 ) // We will be called here with 2,3,4,5 . We treat here demod. filter 2,3,4; (excluding DSB-C case (5) it is treated more down).
2022-11-19 18:17:54 +01:00
receiver_model . set_am_configuration ( options_mode . selected_index ( ) - 1 ) ; // selecting proper filter(2,3,4). 2-1=1=>6k-AM(1) , 3-1=2=>+3k-USB(2), 4-1=3=>-3K-LSB(3),
2021-03-21 20:11:40 -05:00
}
2022-10-16 19:01:05 +02:00
else { // We are in NFM/FM or WFM (NFM BW:8k5 or 11k / FM BW 16k / WFM BW:200k)
2021-03-21 20:11:40 -05:00
2023-05-11 22:45:32 +02:00
if ( enable_wfm ) { // WFM , BW 200Khz aprox , or the two new addional BW filters (180k, 40k)
2022-10-16 19:01:05 +02:00
baseband : : run_image ( portapack : : spi_flash : : image_tag_wfm_audio ) ;
receiver_model . set_modulation ( ReceiverModel : : Mode : : WidebandFMAudio ) ;
2023-05-11 22:45:32 +02:00
// receiver_model.set_wfm_configuration(n); // it is called above , depending user's selection (200k, 180k,40k).
2022-10-16 19:01:05 +02:00
} else { // NFM BW:8k5 or 11k / FM BW 16k
baseband : : run_image ( portapack : : spi_flash : : image_tag_nfm_audio ) ;
receiver_model . set_modulation ( ReceiverModel : : Mode : : NarrowbandFMAudio ) ; //
2023-05-11 22:45:32 +02:00
// receiver_model.set_nbfm_configuration(n); is called above , depending user's selection (8k5, 11k, 16k).
2022-10-16 19:01:05 +02:00
}
}
2020-08-07 16:33:17 -03:00
receiver_model . set_sampling_rate ( 3072000 ) ;
receiver_model . set_baseband_bandwidth ( 1750000 ) ;
2020-08-23 17:41:31 +08:00
// receiver_model.set_tuning_frequency(field_frequency.value()); //probably this too can be commented out.
2023-04-04 17:26:45 +02:00
if ( bool_same_F_tx_rx_enabled ) // when stop TX ,define to which freq RX we return
receiver_model . set_tuning_frequency ( tx_frequency ) ; // Update freq also for RX = TX
else
receiver_model . set_tuning_frequency ( rx_frequency ) ; // Now with seperate freq controls!
2020-08-22 14:57:55 +08:00
receiver_model . set_lna ( rx_lna ) ;
receiver_model . set_vga ( rx_vga ) ;
receiver_model . set_rf_amp ( rx_amp ) ;
2020-08-07 16:33:17 -03:00
receiver_model . enable ( ) ;
2022-08-26 18:34:30 +02:00
hackrf : : cpld : : load_sram_no_verify ( ) ; // to have a good RX without any ghost inside Mic App
2020-08-07 16:33:17 -03:00
audio : : output : : start ( ) ;
2020-08-07 00:19:37 -03:00
} else { //These incredibly convoluted steps are required for the vumeter to reappear when stopping RX.
2021-03-21 20:11:40 -05:00
receiver_model . set_modulation ( ReceiverModel : : Mode : : NarrowbandFMAudio ) ; //This fixes something with AM RX...
2020-08-07 00:19:37 -03:00
receiver_model . disable ( ) ;
baseband : : shutdown ( ) ;
2021-03-21 20:11:40 -05:00
2020-08-07 00:19:37 -03:00
baseband : : run_image ( portapack : : spi_flash : : image_tag_mic_tx ) ;
2021-03-21 20:11:40 -05:00
audio : : output : : stop ( ) ;
2022-10-02 00:51:12 +02:00
audio : : input : : start ( ak4951_alc_and_wm8731_boost_GUI ) ; // When detected AK4951 => set up ALC mode; when detected WM8731 => set up mic_boost ON/OFF.
2020-08-07 00:19:37 -03:00
portapack : : pin_i2s0_rx_sda . mode ( 3 ) ;
configure_baseband ( ) ;
}
}
void MicTXView : : on_headphone_volume_changed ( int32_t v ) {
//if (rx_enabled) {
const auto new_volume = volume_t : : decibel ( v - 99 ) + audio : : headphone : : volume_range ( ) . max ;
receiver_model . set_headphone_volume ( new_volume ) ;
//}
2017-03-14 07:24:04 +00:00
}
2020-08-22 14:57:55 +08:00
void MicTXView : : set_ptt_visibility ( bool v ) {
2020-08-24 01:53:34 +08:00
tx_button . hidden ( ! v ) ;
2020-08-22 14:57:55 +08:00
}
2017-03-14 07:24:04 +00:00
MicTXView : : MicTXView (
NavigationView & nav
)
{
2018-02-01 11:17:51 +00:00
portapack : : pin_i2s0_rx_sda . mode ( 3 ) ; // This is already done in audio::init but gets changed by the CPLD overlay reprogramming
2017-11-09 22:25:37 +00:00
baseband : : run_image ( portapack : : spi_flash : : image_tag_mic_tx ) ;
2022-05-28 22:29:10 +02:00
if ( audio : : debug : : codec_name ( ) = = " WM8731 " ) {
2022-03-05 21:39:53 +01:00
add_children ( {
& labels_WM8731 , // we have audio codec WM8731, same MIC menu as original.
& vumeter ,
& options_gain , // MIC GAIN float factor on the GUI.
2022-09-28 22:42:33 +02:00
& options_wm8731_boost_mode ,
2022-03-05 21:39:53 +01:00
// &check_va,
& field_va ,
& field_va_level ,
& field_va_attack ,
& field_va_decay ,
& field_bw ,
& field_rfgain ,
& field_rfamp ,
& options_mode ,
& field_frequency ,
& options_tone_key ,
& check_rogerbeep ,
2023-04-04 17:26:45 +02:00
& check_common_freq_tx_rx , // added to handle common or separate freq- TX/RX
2022-03-05 21:39:53 +01:00
& check_rxactive ,
& field_volume ,
& field_rxbw ,
& field_squelch ,
& field_rxfrequency ,
& field_rxlna ,
& field_rxvga ,
& field_rxamp ,
& tx_button
} ) ;
} else {
2017-03-14 07:24:04 +00:00
add_children ( {
2022-03-05 21:39:53 +01:00
& labels_AK4951 , // we have audio codec AK4951, enable Automatic Level Control
2017-03-14 07:24:04 +00:00
& vumeter ,
& options_gain ,
2022-03-05 21:39:53 +01:00
& options_ak4951_alc_mode ,
2020-08-22 14:57:55 +08:00
// &check_va,
& field_va ,
2017-03-14 07:24:04 +00:00
& field_va_level ,
& field_va_attack ,
& field_va_decay ,
& field_bw ,
2020-08-21 23:18:53 +08:00
& field_rfgain ,
& field_rfamp ,
2021-03-21 20:11:40 -05:00
& options_mode ,
2017-03-14 07:24:04 +00:00
& field_frequency ,
2017-11-09 20:02:34 +00:00
& options_tone_key ,
2017-03-14 07:24:04 +00:00
& check_rogerbeep ,
2023-04-04 17:26:45 +02:00
& check_common_freq_tx_rx , // added to handle common or separate freq- TX/RX
2020-08-07 00:19:37 -03:00
& check_rxactive ,
& field_volume ,
2021-03-21 20:11:40 -05:00
& field_rxbw ,
2020-08-07 00:19:37 -03:00
& field_squelch ,
2020-08-23 17:41:31 +08:00
& field_rxfrequency ,
2020-08-22 14:57:55 +08:00
& field_rxlna ,
& field_rxvga ,
& field_rxamp ,
2020-08-24 01:53:34 +08:00
& tx_button
2017-03-14 07:24:04 +00:00
} ) ;
2022-03-05 21:39:53 +01:00
}
2020-08-07 00:19:37 -03:00
2017-11-09 20:02:34 +00:00
tone_keys_populate ( options_tone_key ) ;
options_tone_key . on_change = [ this ] ( size_t i , int32_t ) {
tone_key_index = i ;
} ;
options_tone_key . set_selected_index ( 0 ) ;
2017-03-14 07:24:04 +00:00
options_gain . on_change = [ this ] ( size_t , int32_t v ) {
2018-02-01 11:17:51 +00:00
mic_gain = v / 10.0 ;
2017-11-09 20:02:34 +00:00
configure_baseband ( ) ;
2017-03-14 07:24:04 +00:00
} ;
2022-10-02 00:51:12 +02:00
options_gain . set_selected_index ( 1 ) ; // x1.0 preselected default.
2022-09-28 22:42:33 +02:00
2022-10-02 00:51:12 +02:00
if ( audio : : debug : : codec_name ( ) = = " WM8731 " ) {
2022-09-28 22:42:33 +02:00
options_wm8731_boost_mode . on_change = [ this ] ( size_t , int8_t v ) {
2022-10-02 00:51:12 +02:00
switch ( v ) {
case 0 : // +12 dB’ s respect reference level orig fw 1.5.x fw FM : when +20dB's boost ON) and shift bits (>>8),
shift_bits_s16 = 6 ; // now mic-boost on (+20dBs) and shift bits (>>6), +20+12=32 dB’ s (orig fw +20 dBs+ 0dBs)=> +12dB's respect ref.
break ;
case 1 : // +06 dB’ s reference level , (when +20dB's boost ON)
shift_bits_s16 = 7 ; // now mic-boost on (+20dBs) and shift bits (>>7), +20+06=26 dB’ s (orig fw +20 dBs+ 0dBs) => +06dB's respect ref.
break ;
case 2 :
2022-09-28 22:42:33 +02:00
shift_bits_s16 = 4 ; // +04 dB’ s respect ref level , (when +20dB's boost OFF)
break ; // now mic-boost off (+00dBs) shift bits (4) (+0+24dB's)=24 dBs => +04dB's respect ref.
2022-10-02 00:51:12 +02:00
case 3 :
2022-09-28 22:42:33 +02:00
shift_bits_s16 = 5 ; // -02 dB’ s respect ref level , (when +20dB's boost OFF)
break ; // now mic-boost off (+00dBs) shift bits (5) (+0+18dB's)=18 dBs => -02dB's respect ref.
2022-10-02 00:51:12 +02:00
case 4 :
2022-09-28 22:42:33 +02:00
shift_bits_s16 = 6 ; // -08 dB’ s respect ref level , (when +20dB's boost OFF)
break ; // now mic-boost off (+00dBs) shift bits (6) (+0+12dB's)=12 dBs => -08dB's respect ref.
}
2022-10-02 00:51:12 +02:00
ak4951_alc_and_wm8731_boost_GUI = v ; // 0,..4 WM8731_boost dB's options, (combination boost on/off , and effective gain in captured data >>x)
audio : : input : : start ( ak4951_alc_and_wm8731_boost_GUI ) ; // Detected (WM8731) , set up the proper wm_boost on/off , 0..4 (0,1) boost_on , (2,3,4) boost_0ff
configure_baseband ( ) ; // to update in real timme,sending msg , var-parameters >>shift_bits FM msg ,to audio_tx from M0 to M4 Proc -
2022-09-28 22:42:33 +02:00
} ;
2022-10-02 00:51:12 +02:00
options_wm8731_boost_mode . set_selected_index ( 3 ) ; // preset GUI index 3 as default WM -> -02 dB's .
2022-09-28 22:42:33 +02:00
} else {
2022-10-02 00:51:12 +02:00
shift_bits_s16 = 8 ; // Initialized default fixed >>8_FM for FM tx mod , shift audio data for AK4951 ,using top 8 bits s16 data (>>8)
2022-09-28 22:42:33 +02:00
options_ak4951_alc_mode . on_change = [ this ] ( size_t , int8_t v ) {
2022-10-02 00:51:12 +02:00
ak4951_alc_and_wm8731_boost_GUI = v ; // 0,..11, AK4951 Mic -Automatic volume Level Control options,
audio : : input : : start ( ak4951_alc_and_wm8731_boost_GUI ) ; // Detected (AK4951) ==> Set up proper ALC mode from 0..11 options
configure_baseband ( ) ; // sending fixed >>8_FM , var-parameters msg , to audiotx from this M0 to M4 process.
2022-09-28 22:42:33 +02:00
} ;
}
2017-03-14 07:24:04 +00:00
2022-09-28 22:42:33 +02:00
// options_ak4951_alc_mode.set_selected_index(0);
2022-03-05 21:39:53 +01:00
2020-08-23 17:41:31 +08:00
tx_frequency = transmitter_model . tuning_frequency ( ) ;
2017-03-14 07:24:04 +00:00
field_frequency . set_value ( transmitter_model . tuning_frequency ( ) ) ;
field_frequency . set_step ( receiver_model . frequency_step ( ) ) ;
field_frequency . on_change = [ this ] ( rf : : Frequency f ) {
2020-08-23 17:41:31 +08:00
tx_frequency = f ;
2023-04-04 17:26:45 +02:00
if ( ! rx_enabled ) { // not activated receiver. just update freq TX
2020-08-23 17:41:31 +08:00
transmitter_model . set_tuning_frequency ( f ) ;
2023-04-04 17:26:45 +02:00
} else { // activated receiver.
if ( bool_same_F_tx_rx_enabled ) // user selected common freq- TX = RX
receiver_model . set_tuning_frequency ( f ) ; //Update common freq also for RX
}
2017-03-14 07:24:04 +00:00
} ;
field_frequency . on_edit = [ this , & nav ] ( ) {
2020-08-24 01:53:34 +08:00
focused_ui = 0 ;
2017-03-14 07:24:04 +00:00
// TODO: Provide separate modal method/scheme?
2020-08-23 17:41:31 +08:00
auto new_view = nav . push < FrequencyKeypadView > ( tx_frequency ) ;
2017-03-14 07:24:04 +00:00
new_view - > on_changed = [ this ] ( rf : : Frequency f ) {
2020-08-23 17:41:31 +08:00
tx_frequency = f ;
2023-04-04 17:26:45 +02:00
if ( ! rx_enabled ) {
2020-08-23 17:41:31 +08:00
transmitter_model . set_tuning_frequency ( f ) ;
2023-04-04 17:26:45 +02:00
} else {
if ( bool_same_F_tx_rx_enabled )
receiver_model . set_tuning_frequency ( f ) ; //Update freq also for RX
}
2017-03-14 07:24:04 +00:00
this - > field_frequency . set_value ( f ) ;
2020-08-07 00:19:37 -03:00
set_dirty ( ) ;
2017-03-14 07:24:04 +00:00
} ;
} ;
field_bw . on_change = [ this ] ( uint32_t v ) {
2017-08-12 19:28:57 +01:00
transmitter_model . set_channel_bandwidth ( v * 1000 ) ;
2017-03-14 07:24:04 +00:00
} ;
2022-10-16 19:01:05 +02:00
field_bw . set_value ( 10 ) ; // pre-default first time, TX deviation FM for NFM / FM
2017-03-14 07:24:04 +00:00
2020-08-22 14:57:55 +08:00
tx_gain = transmitter_model . tx_gain ( ) ;
2020-08-21 23:18:53 +08:00
field_rfgain . on_change = [ this ] ( int32_t v ) {
2020-08-22 14:57:55 +08:00
tx_gain = v ;
2020-08-21 23:18:53 +08:00
} ;
2020-08-22 14:57:55 +08:00
field_rfgain . set_value ( tx_gain ) ;
rf_amp = transmitter_model . rf_amp ( ) ;
2020-08-21 23:18:53 +08:00
field_rfamp . on_change = [ this ] ( int32_t v ) {
2020-08-22 14:57:55 +08:00
rf_amp = ( bool ) v ;
2020-08-21 23:18:53 +08:00
} ;
2020-08-22 14:57:55 +08:00
field_rfamp . set_value ( rf_amp ? 14 : 0 ) ;
2020-08-21 23:18:53 +08:00
2022-10-29 16:02:08 +02:00
options_mode . on_change = [ this ] ( size_t , int32_t v ) { //{ "NFM/FM", 0 }, { " WFM ", 1 },{ "AM", 2 },{ "USB", 3 },{ "LSB", 4 },{ "DSB", 5 }
2022-10-16 19:01:05 +02:00
enable_am = false ;
2021-03-21 20:11:40 -05:00
enable_usb = false ;
enable_lsb = false ;
enable_dsb = false ;
2022-10-16 19:01:05 +02:00
enable_wfm = false ;
using option_t = std : : pair < std : : string , int32_t > ;
using options_t = std : : vector < option_t > ;
options_t rxbw ; // Aux structure to change dynamically field_rxbw contents,
2021-03-21 20:11:40 -05:00
switch ( v ) {
2022-10-16 19:01:05 +02:00
case 0 : //{ "FM", 0 }
enable_am = false ;
2021-03-21 20:11:40 -05:00
enable_usb = false ;
enable_lsb = false ;
enable_dsb = false ;
2022-10-16 19:01:05 +02:00
field_bw . set_value ( 10 ) ; // pre-default deviation FM for WFM
// field_bw.set_value(transmitter_model.channel_bandwidth() / 1000);
2021-03-21 20:11:40 -05:00
//if (rx_enabled)
2022-05-07 01:43:14 +02:00
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
options_tone_key . hidden ( 0 ) ; // we are in FM mode , we should have active the Key-tones & CTCSS option.
2022-10-16 19:01:05 +02:00
2022-10-29 16:02:08 +02:00
rxbw . emplace_back ( " NFM1:8k5 " , 0 ) ; // restore the original dynamic field_rxbw value.
rxbw . emplace_back ( " NFM2:11k " , 1 ) ;
rxbw . emplace_back ( " FM :16k " , 2 ) ;
2022-10-16 19:01:05 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
2022-05-07 01:43:14 +02:00
field_rxbw . hidden ( 0 ) ; // we are in FM mode, we need to allow the user set up of the RX NFM BW selection (8K5, 11K, 16K)
2022-10-16 19:01:05 +02:00
field_bw . hidden ( 0 ) ; // we are in FM mode, we need to allow FM deviation parameter , in non FM mode.
2021-03-21 20:11:40 -05:00
break ;
2022-10-16 19:01:05 +02:00
case 1 : //{ "WFM", 1 }
enable_am = false ;
enable_usb = false ;
enable_lsb = false ;
enable_dsb = false ;
enable_wfm = true ;
field_bw . set_value ( 75 ) ; // pre-default deviation FM for WFM
// field_bw.set_value(transmitter_model.channel_bandwidth() / 1000);
//if (rx_enabled)
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
options_tone_key . hidden ( 0 ) ; // we are in WFM mode , we should have active the Key-tones & CTCSS option.
2023-05-11 22:45:32 +02:00
rxbw . emplace_back ( " 200k-WFM " , 0 ) ; // We allow the user selection of the 3 x WFM BW filters, (0) WFM-200K, (1) WFM-180K , (2) WFM-40K .
rxbw . emplace_back ( " 180k-WFM " , 1 ) ;
rxbw . emplace_back ( " 40k-WFM " , 2 ) ;
2022-10-16 19:01:05 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
2023-05-11 22:45:32 +02:00
field_rxbw . hidden ( 0 ) ; // we are in WFM mode, we need to show to the user the selected BW WFM filter .
2022-10-16 19:01:05 +02:00
field_bw . hidden ( 0 ) ; // we are in WFM mode, we need to allow WFM deviation parameter , in non FM mode.
break ;
case 2 : //{ "AM", 2 }
2021-03-21 20:11:40 -05:00
enable_am = true ;
2022-05-07 01:43:14 +02:00
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
options_tone_key . set_selected_index ( 0 ) ; // we are NOT in FM mode , we reset the possible previous key-tones &CTCSS selection.
set_dirty ( ) ; // Refresh display
options_tone_key . hidden ( 1 ) ; // we hide that Key-tones & CTCSS input selecction, (no meaning in AM/DSB/SSB).
2022-10-29 16:02:08 +02:00
2023-05-11 22:45:32 +02:00
rxbw . emplace_back ( " DSB1-9k " , 0 ) ; // we offer in AM DSB two audio BW 9k / 6k .
2022-11-19 18:17:54 +01:00
rxbw . emplace_back ( " DSB2-6k " , 1 ) ;
2022-10-29 16:02:08 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
field_rxbw . hidden ( 0 ) ; // we show fixed RX AM BW 6Khz
field_bw . hidden ( 1 ) ; // we hide the FM TX deviation parameter , in non FM mode.
2022-10-16 19:01:05 +02:00
check_rogerbeep . hidden ( 0 ) ; // make visible again the "rogerbeep" selection.
2021-03-21 20:11:40 -05:00
break ;
2022-10-16 19:01:05 +02:00
case 3 : //{ "USB", 3 }
2021-03-21 20:11:40 -05:00
enable_usb = true ;
2022-05-07 01:43:14 +02:00
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
check_rogerbeep . set_value ( false ) ; // reset the possible activation of roger beep, because it is not compatible with SSB , by now.
check_rogerbeep . hidden ( 1 ) ; // hide that roger beep selection.
2022-10-29 16:02:08 +02:00
2023-05-11 22:45:32 +02:00
rxbw . emplace_back ( " USB+3k " , 0 ) ; // locked a fixed option , to display it .
2022-10-29 16:02:08 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
2022-05-07 01:43:14 +02:00
set_dirty ( ) ; // Refresh display
2021-03-21 20:11:40 -05:00
break ;
2022-10-16 19:01:05 +02:00
case 4 : //{ "LSB", 4 }
2021-03-21 20:11:40 -05:00
enable_lsb = true ;
2022-05-07 01:43:14 +02:00
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
check_rogerbeep . set_value ( false ) ; // reset the possible activation of roger beep, because it is not compatible with SSB , by now.
check_rogerbeep . hidden ( 1 ) ; // hide that roger beep selection.
2022-10-29 16:02:08 +02:00
2023-05-11 22:45:32 +02:00
rxbw . emplace_back ( " LSB-3k " , 0 ) ; // locked a fixed option , to display it .
2022-10-29 16:02:08 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
2022-05-07 01:43:14 +02:00
set_dirty ( ) ; // Refresh display
2021-03-21 20:11:40 -05:00
break ;
2022-10-29 16:02:08 +02:00
case 5 : //{ "DSB-SC", 5 }
2021-03-21 20:11:40 -05:00
enable_dsb = true ;
2022-05-07 01:43:14 +02:00
rxaudio ( rx_enabled ) ; //Update now if we have RX audio on
check_rogerbeep . hidden ( 0 ) ; // make visible again the "rogerbeep" selection.
2022-10-29 16:02:08 +02:00
2022-11-19 18:17:54 +01:00
rxbw . emplace_back ( " SSB1:USB+3k " , 0 ) ; // added dynamically two options (index 0,1) to that DSB-C case to the field_rxbw value.
rxbw . emplace_back ( " SSB2:LSB-3k " , 1 ) ;
2022-10-29 16:02:08 +02:00
field_rxbw . set_options ( rxbw ) ; // store that aux GUI option to the field_rxbw.
2021-03-21 20:11:40 -05:00
break ;
}
//configure_baseband();
} ;
2020-08-22 14:57:55 +08:00
/*
2017-03-14 07:24:04 +00:00
check_va . on_select = [ this ] ( Checkbox & , bool v ) {
va_enabled = v ;
2020-08-07 00:19:37 -03:00
text_ptt . hidden ( v ) ; //hide / show PTT text
check_rxactive . hidden ( v ) ; //hide / show the RX AUDIO
set_dirty ( ) ; //Refresh display
2017-03-14 07:24:04 +00:00
} ;
2020-08-22 14:57:55 +08:00
*/
field_va . set_selected_index ( 1 ) ;
field_va . on_change = [ this ] ( size_t , int32_t v ) {
switch ( v ) {
case 0 :
va_enabled = 0 ;
this - > set_ptt_visibility ( 0 ) ;
check_rxactive . hidden ( 0 ) ;
ptt_enabled = 0 ;
break ;
case 1 :
va_enabled = 0 ;
this - > set_ptt_visibility ( 1 ) ;
check_rxactive . hidden ( 0 ) ;
ptt_enabled = 1 ;
break ;
case 2 :
if ( ! rx_enabled ) {
va_enabled = 1 ;
this - > set_ptt_visibility ( 0 ) ;
check_rxactive . hidden ( 1 ) ;
ptt_enabled = 0 ;
} else {
field_va . set_selected_index ( 1 ) ;
}
break ;
}
set_dirty ( ) ;
} ;
2017-03-14 07:24:04 +00:00
2020-08-22 14:57:55 +08:00
2017-03-14 07:24:04 +00:00
check_rogerbeep . on_select = [ this ] ( Checkbox & , bool v ) {
rogerbeep_enabled = v ;
} ;
2020-08-07 00:19:37 -03:00
2023-04-04 17:26:45 +02:00
check_common_freq_tx_rx . on_select = [ this ] ( Checkbox & , bool v ) {
bool_same_F_tx_rx_enabled = v ;
field_rxfrequency . hidden ( v ) ; //Hide or show separated freq RX field . (When no hide user can enter down indep. freq for RX)
set_dirty ( ) ; //Refresh GUI interface
receiver_model . set_tuning_frequency ( v ? tx_frequency : rx_frequency ) ; // To go to the proper tuned freq. when toggling it
} ;
2017-03-14 07:24:04 +00:00
field_va_level . on_change = [ this ] ( int32_t v ) {
va_level = v ;
vumeter . set_mark ( v ) ;
} ;
field_va_level . set_value ( 40 ) ;
field_va_attack . on_change = [ this ] ( int32_t v ) {
attack_ms = v ;
} ;
field_va_attack . set_value ( 500 ) ;
field_va_decay . on_change = [ this ] ( int32_t v ) {
decay_ms = v ;
} ;
2017-11-09 20:02:34 +00:00
field_va_decay . set_value ( 1000 ) ;
2020-08-07 00:19:37 -03:00
check_rxactive . on_select = [ this ] ( Checkbox & , bool v ) {
2020-08-21 23:18:53 +08:00
// vumeter.set_value(0); //Start with a clean vumeter
2020-08-07 00:19:37 -03:00
rx_enabled = v ;
2020-08-22 14:57:55 +08:00
// check_va.hidden(v); //Hide or show voice activation
2020-08-07 00:19:37 -03:00
rxaudio ( v ) ; //Activate-Deactivate audio rx accordingly
set_dirty ( ) ; //Refresh interface
} ;
field_volume . set_value ( ( receiver_model . headphone_volume ( ) - audio : : headphone : : volume_range ( ) . max ) . decibel ( ) + 99 ) ;
field_volume . on_change = [ this ] ( int32_t v ) { this - > on_headphone_volume_changed ( v ) ; } ;
2022-10-29 16:02:08 +02:00
field_rxbw . on_change = [ this ] ( size_t , int32_t v ) {
if ( ! ( enable_am | | enable_usb | | enable_lsb | | enable_dsb | | enable_wfm ) ) {
// In Previous fw versions, that nbfm_configuration(n) was done in any mode (FM/AM/SSB/DSB)...strictly speaking only need it in (NFM/FM)
receiver_model . set_nbfm_configuration ( v ) ; // we are in NFM/FM case, we need to select proper NFM/FM RX channel filter , NFM BW 8K5(0), NFM BW 11K(1) , FM BW 16K (2)
}
2022-11-19 18:17:54 +01:00
else { // we are not in NFM/FM mode .(we could be in any of the rest : AM /USB/LSB/DSB-SC)
if ( enable_am ) { // we are in AM TX mode , we will allow both independent RX audio BW : AM 9K (9K00AE3 / AM 6K (6K00AE3). (In AM option v can be 0 (9k) , 1 (6k)
2023-05-11 22:45:32 +02:00
receiver_model . set_am_configuration ( v ) ; // we are in AM TX mode , we need to select proper AM full path config AM-9K filter. 0+0 =>AM-9K(0), 0+1=1 =>AM-6K(1),
2022-11-19 18:17:54 +01:00
}
if ( enable_dsb ) { // we are in DSB-SC in TX mode , we will allow both independent RX SSB demodulation (USB / LSB side band). in that submenu, v is 0 (SSB1 USB) or 1 (SSB2 LSB)
receiver_model . set_am_configuration ( v + 2 ) ; // we are in DSB-SC TX mode , we need to select proper SSB filter. 0+2 =>usb(2), 1+2=3 =>lsb(3),
2022-10-29 16:02:08 +02:00
}
2023-05-11 22:45:32 +02:00
if ( enable_wfm ) {
receiver_model . set_wfm_configuration ( v ) ; // we are in WFM case, we need to select proper WFB RX BW filter , WFM BW 200K(0), WFM BW 180K(1) , WFM BW 40K(2)
}
2022-10-29 16:02:08 +02:00
}
} ;
2021-03-21 20:11:40 -05:00
2020-08-07 00:19:37 -03:00
field_squelch . on_change = [ this ] ( int32_t v ) {
receiver_model . set_squelch_level ( 100 - v ) ;
} ;
field_squelch . set_value ( 0 ) ;
2020-08-07 16:33:17 -03:00
receiver_model . set_squelch_level ( 0 ) ;
2020-08-07 00:19:37 -03:00
2020-08-23 17:41:31 +08:00
rx_frequency = receiver_model . tuning_frequency ( ) ;
field_rxfrequency . set_value ( rx_frequency ) ;
field_rxfrequency . set_step ( receiver_model . frequency_step ( ) ) ;
2023-04-04 17:26:45 +02:00
field_rxfrequency . on_change = [ this ] ( rf : : Frequency f ) { // available when field rxfrequency not hidden => user selected separated freq RX/TX-
2020-08-23 17:41:31 +08:00
rx_frequency = f ;
if ( rx_enabled )
receiver_model . set_tuning_frequency ( f ) ;
} ;
2023-04-04 17:26:45 +02:00
field_rxfrequency . on_edit = [ this , & nav ] ( ) { // available when field rxfrequency not hidden => user selected separated freq RX/TX-
2020-08-24 01:53:34 +08:00
focused_ui = 1 ;
2020-08-23 17:41:31 +08:00
// TODO: Provide separate modal method/scheme?
auto new_view = nav . push < FrequencyKeypadView > ( rx_frequency ) ;
new_view - > on_changed = [ this ] ( rf : : Frequency f ) {
rx_frequency = f ;
if ( rx_enabled )
receiver_model . set_tuning_frequency ( f ) ;
this - > field_rxfrequency . set_value ( f ) ;
set_dirty ( ) ;
} ;
} ;
2020-08-22 14:57:55 +08:00
rx_lna = receiver_model . lna ( ) ;
field_rxlna . on_change = [ this ] ( int32_t v ) {
rx_lna = v ;
2020-08-24 11:02:42 +08:00
if ( rx_enabled )
receiver_model . set_lna ( v ) ;
2020-08-22 14:57:55 +08:00
} ;
field_rxlna . set_value ( rx_lna ) ;
rx_vga = receiver_model . vga ( ) ;
field_rxvga . on_change = [ this ] ( int32_t v ) {
rx_vga = v ;
2020-08-24 11:02:42 +08:00
if ( rx_enabled )
receiver_model . set_vga ( v ) ;
2020-08-22 14:57:55 +08:00
} ;
field_rxvga . set_value ( rx_vga ) ;
rx_amp = receiver_model . rf_amp ( ) ;
field_rxamp . on_change = [ this ] ( int32_t v ) {
2020-08-23 17:41:31 +08:00
rx_amp = v ;
2020-08-24 11:02:42 +08:00
if ( rx_enabled )
receiver_model . set_rf_amp ( rx_amp ) ;
2020-08-22 14:57:55 +08:00
} ;
2020-08-23 17:41:31 +08:00
field_rxamp . set_value ( rx_amp ) ;
2020-08-22 14:57:55 +08:00
2020-08-24 11:02:42 +08:00
tx_button . on_select = [ this ] ( Button & ) {
2020-08-24 01:53:34 +08:00
if ( ptt_enabled & & ! transmitting ) {
set_tx ( true ) ;
}
} ;
2020-08-24 11:02:42 +08:00
tx_button . on_touch_release = [ this ] ( Button & ) {
2020-08-24 01:53:34 +08:00
if ( button_touch ) {
button_touch = false ;
set_tx ( false ) ;
}
} ;
2020-08-24 11:02:42 +08:00
tx_button . on_touch_press = [ this ] ( Button & ) {
2020-08-24 11:09:10 +08:00
if ( ! transmitting ) {
button_touch = true ;
}
2020-08-24 01:53:34 +08:00
} ;
2017-11-09 20:02:34 +00:00
transmitter_model . set_sampling_rate ( sampling_rate ) ;
2017-03-14 07:24:04 +00:00
transmitter_model . set_baseband_bandwidth ( 1750000 ) ;
set_tx ( false ) ;
2022-09-28 22:42:33 +02:00
audio : : set_rate ( audio : : Rate : : Hz_24000 ) ;
2022-10-02 00:51:12 +02:00
audio : : input : : start ( ak4951_alc_and_wm8731_boost_GUI ) ; // When detected AK4951 => set up ALC mode; when detected WM8731 => set up mic_boost ON/OFF.
2017-03-14 07:24:04 +00:00
}
MicTXView : : ~ MicTXView ( ) {
2018-02-01 11:17:51 +00:00
audio : : input : : stop ( ) ;
2020-08-23 17:41:31 +08:00
transmitter_model . set_tuning_frequency ( tx_frequency ) ; // Save Tx frequency instead of Rx. Or maybe we need some "System Wide" changes to seperate Tx and Rx frequency.
2017-03-14 07:24:04 +00:00
transmitter_model . disable ( ) ;
2020-08-07 00:19:37 -03:00
if ( rx_enabled ) //Also turn off audio rx if enabled
rxaudio ( false ) ;
2022-08-27 17:47:24 +02:00
hackrf : : cpld : : load_sram_no_verify ( ) ; // to leave all RX ok, without ghost signal problem at the exit .
baseband : : shutdown ( ) ; // better this function at the end, not load_sram() that sometimes produces hang up.
2017-03-14 07:24:04 +00:00
}
}