Skip to content

Commit

Permalink
Add digit separator option
Browse files Browse the repository at this point in the history
Fix button work
Allow disable shell output
  • Loading branch information
DiSlord committed May 30, 2021
1 parent cbe63af commit 323f379
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
12 changes: 6 additions & 6 deletions chprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*/

#include "hal.h"
#include "nanovna.h"
#include "chprintf.h"
//#include "memstreams.h"
#include <math.h>

// Enable [flags], support:
Expand All @@ -52,8 +52,8 @@ static const uint32_t pow10[FLOAT_PRECISION+1] = {
// 1 1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24
static const char bigPrefix[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 0};
// Prefixes for values less then 1.0
// 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24
static const char smallPrefix[] = { 'm', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0};
// 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24
static const char smallPrefix[] = { 'm', S_MICRO[0], 'n', 'p', 'f', 'a', 'z', 'y', 0};

#pragma pack(pop)

Expand Down Expand Up @@ -172,12 +172,12 @@ static char *ftoa(char *p, float num, int precision) {
if (k>=multi){k-=multi;l++;}
p = long_to_string_with_divisor(p, l, 10, 0);
if (precision) {
*p++ = '.';
*p++ = DIGIT_SEPARATOR;
p=long_to_string_with_divisor(p, k, 10, precision);
#ifndef CHPRINTF_FORCE_TRAILING_ZEROS
// remove zeros at end
while (p[-1]=='0') p--;
if (p[-1]=='.') p--;
if (p[-1]==DIGIT_SEPARATOR) p--;
#endif
}
return p;
Expand Down Expand Up @@ -211,7 +211,7 @@ static char *ftoaS(char *p, float num, int16_t precision) {
// remove zeros at end
if (precision){
while (p[-1]=='0') p--;
if (p[-1]=='.') p--;
if (p[-1]==DIGIT_SEPARATOR) p--;
}
if (prefix)
*p++ = prefix;
Expand Down
11 changes: 8 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static float kaiser_data[FFT_SIZE];
#endif

#undef VERSION
#define VERSION "1.0.62"
#define VERSION "1.0.63"

// Version text, displayed in Config->Version menu, also send by info command
const char *info_about[]={
Expand Down Expand Up @@ -473,6 +473,7 @@ transform_domain(uint16_t ch_mask)
// Shell commands output
int shell_printf(const char *fmt, ...)
{
if (shell_stream == NULL) return 0;
va_list ap;
int formatted_bytes;
va_start(ap, fmt);
Expand Down Expand Up @@ -922,6 +923,7 @@ config_t config = {
._serial_speed = SERIAL_DEFAULT_BITRATE,
._xtal_freq = XTALFREQ,
._lever_mode = LM_MARKER,
._digit_separator = '.',
};

properties_t current_props;
Expand Down Expand Up @@ -2992,7 +2994,7 @@ static void shell_init_connection(void){

#else
// Only USB console, shell_stream always on USB
#define PREPARE_STREAM
#define PREPARE_STREAM shell_stream = (BaseSequentialStream *)&SDU1;

// Check connection as Active, if no suspend input
static bool shell_check_connect(void){
Expand Down Expand Up @@ -3020,7 +3022,7 @@ static void shell_init_connection(void){
/*
* Set I/O stream SDU1 for shell
*/
shell_stream = (BaseSequentialStream *)&SDU1;
PREPARE_STREAM;
}
#endif

Expand Down Expand Up @@ -3129,6 +3131,8 @@ void sd_card_load_config(void){
if (f_open(fs_file, "config.ini", FA_OPEN_EXISTING | FA_READ) != FR_OK)
return;

// Disable shell output
shell_stream = NULL;
char *buf = (char *)spi_buffer;
UINT size = 0;

Expand Down Expand Up @@ -3157,6 +3161,7 @@ void sd_card_load_config(void){
}
}
f_close(fs_file);
PREPARE_STREAM;
return;
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
//#define USE_FFT_WINDOW_BUFFER
// Enable data smooth option
#define __USE_SMOOTH__
// Enable optional change digit separator for locales (dot or comma, need for correct work some external software)
#define __DIGIT_SEPARATOR__
// Enable DSP instruction (support only by Cortex M4 and higher)
#ifdef ARM_MATH_CM4
#define __USE_DSP__
Expand Down Expand Up @@ -702,6 +704,7 @@ typedef struct config {
uint32_t _serial_speed;
uint32_t _xtal_freq;
uint8_t _lever_mode;
uint8_t _digit_separator;
uint32_t checksum;
} config_t;

Expand Down Expand Up @@ -1068,6 +1071,12 @@ extern uint16_t lastsaveid;
#define VNA_mode config._vna_mode
#define lever_mode config._lever_mode

#ifdef __DIGIT_SEPARATOR__
#define DIGIT_SEPARATOR config._digit_separator
#else
#define DIGIT_SEPARATOR '.'
#endif

int caldata_save(uint32_t id);
int caldata_recall(uint32_t id);
const properties_t *caldata_reference(void);
Expand Down
21 changes: 18 additions & 3 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,18 @@ static UI_FUNCTION_CALLBACK(menu_sdcard_cb)
ui_mode_normal();
}

#ifdef __DIGIT_SEPARATOR__
static UI_FUNCTION_ADV_CALLBACK(menu_separator_acb)
{
(void)data;
if (b){
b->p1.text = DIGIT_SEPARATOR == '.' ? " DOT '.'" : " COMMA ','";
return;
}
DIGIT_SEPARATOR = DIGIT_SEPARATOR == '.' ? ',' : '.';
}
#endif

static const menuitem_t menu_sdcard[] = {
{ MT_CALLBACK, SAVE_S1P_FILE, "SAVE S1P", menu_sdcard_cb },
{ MT_CALLBACK, SAVE_S2P_FILE, "SAVE S2P", menu_sdcard_cb },
Expand Down Expand Up @@ -1533,8 +1545,11 @@ const menuitem_t menu_device[] = {
{ MT_ADV_CALLBACK, KM_THRESHOLD, "THRESHOLD\n%.10q", menu_keyboard_acb },
{ MT_ADV_CALLBACK, KM_XTAL, "TCXO\n%.9q", menu_keyboard_acb },
{ MT_ADV_CALLBACK, KM_VBAT, "VBAT OFFSET\n %umV", menu_keyboard_acb },
#ifdef __DIGIT_SEPARATOR__
{ MT_ADV_CALLBACK, 0, "SEPARATOR\n%s", menu_separator_acb },
#endif
#ifdef __SD_CARD_LOAD__
{ MT_CALLBACK, MENU_CONFIG_LOAD, "LOAD\nCONFIG", menu_config_cb },
{ MT_CALLBACK, MENU_CONFIG_LOAD, "LOAD\nCONFIG.INI", menu_config_cb },
#endif
{ MT_CALLBACK, MENU_CONFIG_RESET, "CLEAR\nCONFIG", menu_config_cb },
{ MT_CANCEL, 0, S_LARROW" BACK", NULL },
Expand Down Expand Up @@ -1886,7 +1901,7 @@ draw_numeric_input(const char *buf)
lcd_set_background(bg);
if (c < 0 && focused) c = 0;
// Add space before char
int16_t space = xsim&1 ? 2 + 10 : 2;
uint16_t space = xsim&1 ? 2 + 10 : 2;
xsim>>=1;
lcd_fill(x, y, space, NUM_FONT_GET_HEIGHT);
x+=space;
Expand Down Expand Up @@ -2473,7 +2488,6 @@ lever_frequency(uint16_t status, int mode)
}
if (freq > STOP_MAX || freq < START_MIN) return;
set_sweep_frequency(mode, freq);
while (btn_wait_release() != 0);
}

#define STEPRATIO 0.2
Expand Down Expand Up @@ -2696,6 +2710,7 @@ normal_apply_touch(int touch_x, int touch_y){
static void
ui_process_lever(void)
{
last_button = 0;
uint16_t status = btn_check();
if (status == 0) return;
switch (ui_mode) {
Expand Down

0 comments on commit 323f379

Please sign in to comment.