@ -212,6 +212,7 @@ int btn_side(void)
static int btn_check ( void )
{
systime_t ticks ;
shell_run_pending ( true ) ; // capture while a screen waits for the jog button
# ifdef __WATCHDOG__
wdgReset ( & WDGD1 ) ;
# endif
@ -402,6 +403,7 @@ static void touch_init(void){
static int
touch_check ( void )
{
shell_run_pending ( true ) ; // capture while a screen waits for a touch
# ifdef TINYSA4
if ( setting . lock_display )
return EVT_TOUCH_NONE ;
@ -1566,7 +1568,7 @@ static const struct {
# ifdef __USE_RTC__
[ KM_RTC_DATE ] = { keypads_positive , " SET DATE \n YYMMDD " } , // Date
[ KM_RTC_TIME ] = { keypads_positive , " SET TIME \n HHMMSS " } , // Time
[ KM_INTERVAL ] = { keypads_positive , " SET INTERVAL\n HHMMSS" } , // Interval
[ KM_INTERVAL ] = { keypads_positive , " REPEAT\n HHMMSS" } , // Interval
# endif
[ KM_PRESET_NAME ] = { keypads_text , " NAME " } , // KM_PRESET_NAME
# endif
@ -1690,8 +1692,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sweep_acb)
( void ) item ;
if ( b ) {
if ( setting . level_sweep ! = 0 | | get_sweep_frequency ( ST_SPAN ) ! = 0 ) {
# ifdef TINYSA4
plot_printf ( b - > text , sizeof b - > text , " SW:%.3Q-%.3QHz %+ddB %.3Fs " ,
get_sweep_frequency ( ST_START ) , get_sweep_frequency ( ST_STOP ) ,
# else
plot_printf ( b - > text , sizeof b - > text , " SW:%3.2fMHz %+ddB %.3Fs " ,
get_sweep_frequency ( ST_SPAN ) / 1000000.0 ,
# endif
( int ) setting . level_sweep ,
setting . sweep_time_us / ( float ) ONE_SECOND_TIME ) ;
}
@ -2200,6 +2207,23 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb)
redraw_request | = REDRAW_CAL_STATUS ;
}
// After a preset load: a generator preset starts with the output off, a mode change shows the menu of the new mode
static void menu_preset_loaded ( int old_mode )
{
bool output = MODE_OUTPUT ( setting . mode ) ;
if ( output )
setting . mute = true ;
if ( setting . mode = = old_mode ) {
menu_move_back ( ! output ) ; // a generator returns to its form menu
return ;
}
menu_move_top ( ) ;
if ( output )
menu_push_submenu ( setting . mode = = M_GENLOW ? menu_lowoutputmode : menu_highoutputmode ) ;
else
ui_mode_normal ( ) ;
}
static UI_FUNCTION_ADV_CALLBACK ( menu_load_preset_acb )
{
( void ) item ;
@ -2216,11 +2240,12 @@ static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb)
plot_printf ( b - > text , sizeof ( b - > text ) , " EMPTY %d " , ( int ) data ) ;
return ;
}
int old_mode = setting . mode ;
if ( caldata_recall ( data ) = = - 1 ) {
if ( data = = 0 )
reset_settings ( setting . mode ) ; // Restore factory defaults
}
menu_ move_back( tru e) ;
menu_ preset_loaded( old_mod e) ;
}
static UI_FUNCTION_ADV_CALLBACK ( menu_store_preset_acb )
@ -4111,14 +4136,14 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_draw_line_acb){
}
# endif
# ifdef __HAM_BAND__
// data: 1 = HAM bands, 2 = band table (multi band off)
static UI_FUNCTION_ADV_CALLBACK ( menu_settings_ham_bands ) {
( void ) item ;
( void ) data ;
if ( b ) {
b - > icon = config . hambands ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK ;
b - > icon = config . hambands & data ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK ;
return ;
}
toggle_hambands ( ) ;
config . hambands ^ = data ;
redraw_request | = REDRAW_AREA ;
}
# endif
@ -4592,27 +4617,15 @@ __attribute__((noinline)) static void fw_update_ui(const char *fname) {
static UI_FUNCTION_ADV_CALLBACK ( menu_autoname_acb )
// Toggle the config._mode bit in data
static UI_FUNCTION_ADV_CALLBACK ( menu_config_mode_acb )
{
( void ) item ;
( void ) data ;
if ( b ) {
b - > icon = config . _mode & _MODE_AUTO_FILENAME ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK ;
b - > icon = config . _mode & data ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK ;
return ;
}
config . _mode ^ = _MODE_AUTO_FILENAME ;
config_save ( ) ;
}
static UI_FUNCTION_ADV_CALLBACK ( menu_mhz_csv_acb )
{
( void ) item ;
( void ) data ;
if ( b ) {
b - > icon = config . _mode & _MODE_MHZ_CSV ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK ;
return ;
}
config . _mode ^ = _MODE_MHZ_CSV ;
config . _mode ^ = data ;
config_save ( ) ;
}
@ -4758,6 +4771,7 @@ const menuitem_t menu_lowoutputmode[] = {
# ifdef TINYSA4
{ MT_FORM | MT_ADV_CALLBACK , 255 , " OUTPUT: %s " , menu_lowoutput_settings_acb } ,
# endif
{ MT_FORM | MT_SUBMENU , 0 , " PRESET " , menu_load_preset } ,
{ MT_FORM | MT_CANCEL , 0 , " MODE " , NULL } ,
{ MT_FORM | MT_NONE , 0 , NULL , NULL } // sentinel
} ;
@ -4775,6 +4789,7 @@ const menuitem_t menu_highoutputmode[] = {
# ifdef TINYSA4
{ MT_FORM | MT_SUBMENU , 255 , S_RARROW " Settings " , menu_settings3 } ,
# endif
{ MT_FORM | MT_SUBMENU , 0 , " PRESET " , menu_load_preset } ,
{ MT_FORM | MT_CANCEL , 0 , " MODE " , NULL } ,
{ MT_FORM | MT_NONE , 0 , NULL , NULL } // sentinel
} ;
@ -4846,6 +4861,7 @@ const menuitem_t menu_marker_search[] = {
{ MT_ADV_CALLBACK , 0 , " ENTER \n %s " , menu_enter_marker_acb } ,
{ MT_ADV_CALLBACK , M_TRACKING , " TRACKING " , menu_marker_modify_acb } ,
# ifdef TINYSA4
{ MT_ADV_CALLBACK , _MODE_MARKER_ORDER , " TRACKING \n L " S_RARROW " R " , menu_config_mode_acb } ,
{ MT_ADV_CALLBACK , 0 , " JOG JUMP \n MAX " , menu_jog_jump_acb } ,
{ MT_KEYPAD , KM_NOISE , " PEAK \n \b %s " , " 2..120 dB " } ,
# endif
@ -5254,7 +5270,8 @@ static const menuitem_t menu_settings[] =
{ MT_CALLBACK , FMT_BIN_FILE , " DUMP \n FIRMWARE " , menu_sdcard_cb } ,
# endif
# ifdef __HAM_BAND__
{ MT_ADV_CALLBACK , 0 , " HAM \n BANDS " , menu_settings_ham_bands } ,
{ MT_ADV_CALLBACK , 1 , " HAM \n BANDS " , menu_settings_ham_bands } ,
{ MT_ADV_CALLBACK , 2 , " SHOW \n BANDS " , menu_settings_ham_bands } ,
# endif
# ifdef __SD_CARD_LOAD__
{ MT_CALLBACK , 0 , " LOAD \n CONFIG.INI " , menu_load_config_cb } ,
@ -5428,7 +5445,7 @@ static const menuitem_t menu_config2[] =
{ MT_SUBMENU , 0 , " EXPERT \n CONFIG " , menu_settings } ,
# else
# ifdef __HAM_BAND__
{ MT_ADV_CALLBACK , 0 , " HAM \n BANDS " , menu_settings_ham_bands } ,
{ MT_ADV_CALLBACK , 1 , " HAM \n BANDS " , menu_settings_ham_bands } ,
# endif
{ MT_SUBMENU , 0 , " EXPERT \n CONFIG " , menu_settings2 } ,
# endif
@ -5610,12 +5627,13 @@ static const menuitem_t menu_stimulus[] = {
static const menuitem_t menu_storage_sd_icon [ ] = {
{ MT_ADV_CALLBACK , 0 , " SAVE \n CAPTURE " , menu_sd_icon_save_capture_acb } ,
{ MT_ADV_CALLBACK , 0 , " SAVE \n TRACES " , menu_sd_icon_save_traces_acb } ,
{ MT_KEYPAD , KM_INTERVAL , " REPEAT \n \b %s " , " 0 = single save " } ,
{ MT_NONE , 0 , NULL , menu_back }
} ;
static const menuitem_t menu_storage_more [ ] = {
{ MT_ADV_CALLBACK , 0 , " AUTO NAME " , menu_autonam e_acb } ,
{ MT_ADV_CALLBACK , 0 , " MHz \n CSV " , menu_mhz_csv _acb } ,
{ MT_ADV_CALLBACK , _MODE_AUTO_FILENAME , " AUTO NAME " , menu_config_mod e_acb } ,
{ MT_ADV_CALLBACK , _MODE_MHZ_CSV , " MHz \n CSV " , menu_config_mode _acb } ,
{ MT_SUBMENU , 0 , " SD CARD \n ICON " , menu_storage_sd_icon } ,
# ifdef __USE_USB_MSC__
{ MT_CALLBACK , 0 , " USB \n DISK " , menu_usb_disk_cb } ,
@ -5929,7 +5947,7 @@ static void fetch_numeric_target(uint8_t mode)
plot_printf ( uistat . text , sizeof uistat . text , out_format , uistat . freq_value ) ;
break ;
case KM_BAND_SPAN :
uistat . freq_value = abs ( ( long ) setting . bands [ active_band ] . end - ( long ) setting . bands [ active_band ] . start ) ;
uistat . freq_value = setting . bands [ active_band ] . end - setting . bands [ active_band ] . start ;
# ifdef TINYSA4
if ( uistat . freq_value > 990000000UL )
out_format = " %.6Q " ;
@ -6217,28 +6235,21 @@ set_numeric_value(void)
// BANDs_update();
break ;
case KM_BAND_CENTER :
case KM_BAND_SPAN :
{
freq_t span = abs ( ( long ) setting . bands [ active_band ] . end - ( long ) setting . bands [ active_band ] . start ) ;
freq_t center = uistat . freq_value - ( setting . frequency_offset - FREQUENCY_SHIFT ) ;
setting . bands [ active_band ] . start = center - span / 2 ;
setting . bands [ active_band ] . end = center + span / 2 ;
band_t * b = & setting . bands [ active_band ] ;
freq_t center = ( b - > end + b - > start ) / 2 ;
freq_t span = b - > end - b - > start ; // START and STOP keep start <= end
if ( keypad_mode = = KM_BAND_CENTER )
center = uistat . freq_value - ( setting . frequency_offset - FREQUENCY_SHIFT ) ;
else
span = uistat . freq_value ;
b - > start = center > span / 2 ? center - span / 2 : 0 ; // unsigned, a new band (0..0) with a span went "below 0 Hz"
b - > end = b - > start + span ;
update_frequencies ( ) ;
dirty = true ;
update_grid ( ) ;
}
// BANDs_update();
break ;
case KM_BAND_SPAN :
{
freq_t span = uistat . freq_value ;
freq_t center = ( setting . bands [ active_band ] . end + setting . bands [ active_band ] . start ) / 2 ;
setting . bands [ active_band ] . start = center - span / 2 ;
setting . bands [ active_band ] . end = center + span / 2 ;
update_frequencies ( ) ;
dirty = true ;
update_grid ( ) ;
// BANDs_update();
}
break ;
case KM_BAND_LEVEL :
setting . bands [ active_band ] . level = to_dBm ( uistat . value ) ;
@ -7427,6 +7438,11 @@ draw_menu_buttons(const menuitem_t *menu, uint32_t mask)
# else
ili9341_drawstring ( text , text_offs , y + ( button_height - linesFONT_GET_HEIGHT ) / 2 ) ;
# endif
if ( MT_MASK ( m - > type ) = = MT_SUBMENU ) { // Opens a submenu: small arrow in the top right corner
ili9341_set_background ( LCD_MENU_TEXT_COLOR ) ;
for ( int r = - 2 ; r < = 2 ; r + + )
ili9341_fill ( LCD_WIDTH - 6 , y + 4 + r , 3 - ( r < 0 ? - r : r ) , 1 ) ;
}
}
}
// Cleanup other buttons (less flicker)
@ -8351,7 +8367,7 @@ static void sa_save_file(uint8_t format) {
# endif
// Prepare filename and open for write
if ( config . _mode & _MODE_AUTO_FILENAME ) { // Auto name, use date / time
if ( ( config . _mode & _MODE_AUTO_FILENAME ) | | sd_repeat ) { // Auto name, use date / time
# if FF_USE_LFN >= 1
uint32_t tr = rtc_get_tr_bcd ( ) ; // TR read first
uint32_t dr = rtc_get_dr_bcd ( ) ; // DR read second
@ -8521,6 +8537,17 @@ void save_csv(uint8_t mask) {
menu_sdcard_cb ( 0 , FMT_CSV_FILE ) ;
}
bool sd_repeat ; // SD icon saves every setting.interval seconds
static systime_t sd_repeat_start ;
static void sd_icon_save ( void ) {
sd_repeat_start = chVTGetSystemTimeX ( ) ;
if ( config . sd_icon_save & SDIS_CAPTURE )
menu_sdcard_cb ( 0 , FMT_BMP_FILE ) ;
if ( config . sd_icon_save & SDIS_TRACES )
menu_save_traces_cb ( 0 , 0 ) ;
}
static bool
made_screenshot ( int touch_x , int touch_y ) {
if ( touch_y < SD_CARD_START | | touch_y > SD_CARD_START + 20 | | touch_x > OFFSETX )
@ -8528,10 +8555,12 @@ made_screenshot(int touch_x, int touch_y) {
ili9341_set_background ( LCD_BG_COLOR ) ;
ili9341_fill ( 4 , SD_CARD_START , 16 , 16 ) ;
touch_wait_release ( ) ;
if ( config . sd_icon_save & SDIS_CAPTURE )
menu_sdcard_cb ( 0 , FMT_BMP_FILE ) ;
if ( config . sd_icon_save & SDIS_TRACES )
menu_save_traces_cb ( 0 , 0 ) ;
if ( setting . interval ) { // Repeat set: the icon starts and stops saving every interval
sd_repeat = ! sd_repeat ;
redraw_request | = REDRAW_BATTERY ; // icon color
if ( ! sd_repeat ) return TRUE ;
}
sd_icon_save ( ) ;
return TRUE ;
}
# endif
@ -8691,36 +8720,14 @@ void ui_process_touch(void)
static uint16_t previous_button_state = 0 ;
# ifdef TINYSA4
uint64_t time_since_start = 0 ;
uint64_t interval_stop_time = 0 ;
systime_t old_ticks ;
void set_interval_stop_time ( void )
{
if ( setting . interval = = 0 ) {
interval_stop_time = 0 ;
} else {
interval_stop_time = time_since_start + CH_CFG_ST_FREQUENCY * ( uint64_t ) setting . interval ;
}
}
# endif
void
ui_process ( void )
{
# ifdef TINYSA4
systime_t ticks = chVTGetSystemTimeX ( ) ;
if ( ticks < old_ticks )
time_since_start + = 0x100000000 ;
old_ticks = ticks ;
time_since_start = ( time_since_start & 0xffffffff00000000 ) | ticks ;
if ( interval_stop_time ! = 0 & & interval_stop_time < time_since_start ) {
set_interval_stop_time ( ) ;
}
# ifdef __USE_SD_CARD__
// SD icon repeat, only from the normal screen: a capture would close an open menu
if ( sd_repeat & & setting . interval & & ui_mode = = UI_NORMAL & &
chVTGetSystemTimeX ( ) - sd_repeat_start > = ( systime_t ) setting . interval * CH_CFG_ST_FREQUENCY )
sd_icon_save ( ) ;
# endif
int button_state = READ_PORT ( ) & BUTTON_MASK ;