mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
add atof of my own
This commit is contained in:
parent
69c41aa57e
commit
4e55ca4f70
72
main.c
72
main.c
|
|
@ -8,6 +8,7 @@
|
||||||
#include <shell.h>
|
#include <shell.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
RTCDateTime timespec;
|
RTCDateTime timespec;
|
||||||
|
|
@ -52,7 +53,7 @@ static THD_FUNCTION(Thread1, arg)
|
||||||
|
|
||||||
chRegSetThreadName("blink");
|
chRegSetThreadName("blink");
|
||||||
|
|
||||||
palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
//palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -224,6 +225,18 @@ wait_dsp(int count)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
duplicate_buffer_to_dump(int16_t *p)
|
||||||
|
{
|
||||||
|
if (dump_selection == 1)
|
||||||
|
p = samp_buf;
|
||||||
|
else if (dump_selection == 2)
|
||||||
|
p = ref_buf;
|
||||||
|
else if (dump_selection == 3)
|
||||||
|
p = refiq_buf;
|
||||||
|
memcpy(dump_buffer, p, sizeof dump_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
|
void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
|
||||||
{
|
{
|
||||||
#if PORT_SUPPORTS_RT
|
#if PORT_SUPPORTS_RT
|
||||||
|
|
@ -233,19 +246,12 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
|
||||||
int16_t *p = &rx_buffer[offset];
|
int16_t *p = &rx_buffer[offset];
|
||||||
(void)i2sp;
|
(void)i2sp;
|
||||||
(void)n;
|
(void)n;
|
||||||
//palClearPad(GPIOC, GPIOC_LED);
|
|
||||||
|
|
||||||
dsp_process(p, n);
|
dsp_process(p, n);
|
||||||
|
|
||||||
if (wait_count > 0) {
|
if (wait_count > 0) {
|
||||||
if (dump_selection == 1)
|
|
||||||
p = samp_buf;
|
|
||||||
else if (dump_selection == 2)
|
|
||||||
p = ref_buf;
|
|
||||||
else if (dump_selection == 3)
|
|
||||||
p = refiq_buf;
|
|
||||||
if (wait_count == 1)
|
if (wait_count == 1)
|
||||||
memcpy(dump_buffer, p, sizeof dump_buffer);
|
duplicate_buffer_to_dump(p);
|
||||||
--wait_count;
|
--wait_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,7 +262,6 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n)
|
||||||
stat.last_counter_value = cnt_s;
|
stat.last_counter_value = cnt_s;
|
||||||
#endif
|
#endif
|
||||||
stat.callback_count++;
|
stat.callback_count++;
|
||||||
//palSetPad(GPIOC, GPIOC_LED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const I2SConfig i2sconfig = {
|
static const I2SConfig i2sconfig = {
|
||||||
|
|
@ -301,7 +306,6 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
dump_selection = atoi(argv[0]);
|
dump_selection = atoi(argv[0]);
|
||||||
|
|
||||||
//palClearPad(GPIOC, GPIOC_LED);
|
|
||||||
wait_dsp(3);
|
wait_dsp(3);
|
||||||
|
|
||||||
len = AUDIO_BUFFER_LEN;
|
len = AUDIO_BUFFER_LEN;
|
||||||
|
|
@ -313,7 +317,6 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
chprintf(chp, "\r\n");
|
chprintf(chp, "\r\n");
|
||||||
}
|
}
|
||||||
//palSetPad(GPIOC, GPIOC_LED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
@ -445,7 +448,7 @@ static void cmd_scan_lcd(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
set_frequencies(void)
|
update_frequencies(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int32_t span = (freq_stop - freq_start)/100;
|
int32_t span = (freq_stop - freq_start)/100;
|
||||||
|
|
@ -488,7 +491,7 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
sweep_points = x;
|
sweep_points = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_frequencies();
|
update_frequencies();
|
||||||
set_sweep(freq_start, freq_stop);
|
set_sweep(freq_start, freq_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -853,6 +856,43 @@ void set_trace_type(int t, int type)
|
||||||
force_set_markmap();
|
force_set_markmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float
|
||||||
|
my_atof(const char *p)
|
||||||
|
{
|
||||||
|
int neg = FALSE;
|
||||||
|
if (*p == '-')
|
||||||
|
neg = TRUE;
|
||||||
|
if (*p == '-' || *p == '+')
|
||||||
|
p++;
|
||||||
|
float x = atoi(p);
|
||||||
|
while (isdigit(*p))
|
||||||
|
p++;
|
||||||
|
if (*p == '.') {
|
||||||
|
float d = 1.0f;
|
||||||
|
p++;
|
||||||
|
while (isdigit(*p)) {
|
||||||
|
d /= 10;
|
||||||
|
x += d * (*p - '0');
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*p == 'e' || *p == 'E') {
|
||||||
|
p++;
|
||||||
|
int exp = atoi(p);
|
||||||
|
while (exp > 0) {
|
||||||
|
x *= 10;
|
||||||
|
exp--;
|
||||||
|
}
|
||||||
|
while (exp < 0) {
|
||||||
|
x /= 10;
|
||||||
|
exp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (neg)
|
||||||
|
x = -x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
|
|
@ -903,7 +943,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
} else if (strcmp(argv[1], "off") == 0) {
|
} else if (strcmp(argv[1], "off") == 0) {
|
||||||
set_trace_type(t, TRC_OFF);
|
set_trace_type(t, TRC_OFF);
|
||||||
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
||||||
trace[t].scale = atoi(argv[2]);
|
trace[t].scale = my_atof(argv[2]);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1156,7 +1196,7 @@ int main(void)
|
||||||
plot_init();
|
plot_init();
|
||||||
|
|
||||||
/* initial frequencies */
|
/* initial frequencies */
|
||||||
set_frequencies();
|
update_frequencies();
|
||||||
|
|
||||||
/* restore config and calibration data from flash memory */
|
/* restore config and calibration data from flash memory */
|
||||||
caldata_recall(0);
|
caldata_recall(0);
|
||||||
|
|
|
||||||
|
|
@ -232,6 +232,8 @@ void ui_init(void);
|
||||||
void ui_show(void);
|
void ui_show(void);
|
||||||
void ui_hide(void);
|
void ui_hide(void);
|
||||||
|
|
||||||
|
extern uint8_t operation_requested;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* misclinous
|
* misclinous
|
||||||
|
|
|
||||||
4
plot.c
4
plot.c
|
|
@ -487,7 +487,7 @@ trace_into_index(int x, int t, int i, float coeff[2])
|
||||||
v = 1 - logmag(coeff);
|
v = 1 - logmag(coeff);
|
||||||
break;
|
break;
|
||||||
case TRC_PHASE:
|
case TRC_PHASE:
|
||||||
v = 4 + phase(coeff);
|
v = 4 - phase(coeff);
|
||||||
break;
|
break;
|
||||||
case TRC_LINEAR:
|
case TRC_LINEAR:
|
||||||
v = 8 + linear(coeff);
|
v = 8 + linear(coeff);
|
||||||
|
|
@ -1122,6 +1122,8 @@ draw_cell_all(void)
|
||||||
if (is_mapmarked(m, n))
|
if (is_mapmarked(m, n))
|
||||||
draw_cell(m, n);
|
draw_cell(m, n);
|
||||||
//ui_process();
|
//ui_process();
|
||||||
|
//if (operation_requested)
|
||||||
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep current map for update
|
// keep current map for update
|
||||||
|
|
|
||||||
40
ui.c
40
ui.c
|
|
@ -37,9 +37,9 @@ struct {
|
||||||
#define EVT_DOWN 0x20
|
#define EVT_DOWN 0x20
|
||||||
#define EVT_REPEAT 0x40
|
#define EVT_REPEAT 0x40
|
||||||
|
|
||||||
#define BUTTON_DOWN_LONG_TICKS 1000
|
#define BUTTON_DOWN_LONG_TICKS 10000 /* 1sec */
|
||||||
#define BUTTON_DOUBLE_TICKS 500
|
#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */
|
||||||
#define BUTTON_DEBOUNCE_TICKS 2
|
#define BUTTON_DEBOUNCE_TICKS 10
|
||||||
|
|
||||||
/* lever switch assignment */
|
/* lever switch assignment */
|
||||||
#define BIT_UP1 3
|
#define BIT_UP1 3
|
||||||
|
|
@ -59,7 +59,6 @@ int ui_status = FALSE;
|
||||||
int selection = 1;
|
int selection = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int btn_check(void)
|
static int btn_check(void)
|
||||||
{
|
{
|
||||||
int cur_button = READ_PORT() & BUTTON_MASK;
|
int cur_button = READ_PORT() & BUTTON_MASK;
|
||||||
|
|
@ -242,6 +241,12 @@ menu_format_cb(int item)
|
||||||
ui_hide();
|
ui_hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
menu_format2_cb(int item)
|
||||||
|
{
|
||||||
|
menu_format_cb(item + 5);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
choose_active_marker(void)
|
choose_active_marker(void)
|
||||||
{
|
{
|
||||||
|
|
@ -299,13 +304,22 @@ const menuitem_t menu_trace[] = {
|
||||||
{ MT_NONE, NULL, NULL } // sentinel
|
{ MT_NONE, NULL, NULL } // sentinel
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const menuitem_t menu_format2[] = {
|
||||||
|
{ MT_CALLBACK, "LINEAR", menu_format2_cb },
|
||||||
|
{ MT_CALLBACK, "SWR", menu_format2_cb },
|
||||||
|
{ MT_CANCEL, "BACK", NULL },
|
||||||
|
{ MT_NONE, NULL, NULL } // sentinel
|
||||||
|
};
|
||||||
|
|
||||||
const menuitem_t menu_format[] = {
|
const menuitem_t menu_format[] = {
|
||||||
{ MT_CALLBACK, "LOGMAG", menu_format_cb },
|
{ MT_CALLBACK, "LOGMAG", menu_format_cb },
|
||||||
{ MT_CALLBACK, "PHASE", menu_format_cb },
|
{ MT_CALLBACK, "PHASE", menu_format_cb },
|
||||||
{ MT_CALLBACK, "SMITH", menu_format_cb },
|
{ MT_CALLBACK, "SMITH", menu_format_cb },
|
||||||
{ MT_CALLBACK, "ADMIT", menu_format_cb },
|
{ MT_CALLBACK, "ADMIT", menu_format_cb },
|
||||||
{ MT_CALLBACK, "DELAY", menu_format_cb },
|
{ MT_CALLBACK, "POLAR", menu_format_cb },
|
||||||
{ MT_CALLBACK, "SWR", menu_format_cb },
|
{ MT_SUBMENU, "NEXT", menu_format2 },
|
||||||
|
//{ MT_CALLBACK, "LINEAR", menu_format_cb },
|
||||||
|
//{ MT_CALLBACK, "SWR", menu_format_cb },
|
||||||
{ MT_CANCEL, "BACK", NULL },
|
{ MT_CANCEL, "BACK", NULL },
|
||||||
{ MT_NONE, NULL, NULL } // sentinel
|
{ MT_NONE, NULL, NULL } // sentinel
|
||||||
};
|
};
|
||||||
|
|
@ -524,19 +538,7 @@ static void extcb1(EXTDriver *extp, expchannel_t channel) {
|
||||||
(void)extp;
|
(void)extp;
|
||||||
(void)channel;
|
(void)channel;
|
||||||
operation_requested = TRUE;
|
operation_requested = TRUE;
|
||||||
|
//cur_button = READ_PORT() & BUTTON_MASK;
|
||||||
#if 0
|
|
||||||
if (channel == 1)
|
|
||||||
ui_status = TRUE;
|
|
||||||
else if (channel == 2)
|
|
||||||
ui_status = !ui_status;
|
|
||||||
else if (channel == 3)
|
|
||||||
ui_status = FALSE;
|
|
||||||
if (ui_status)
|
|
||||||
ui_show();
|
|
||||||
else
|
|
||||||
ui_hide();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const EXTConfig extcfg = {
|
static const EXTConfig extcfg = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue