More correct create frequencies table on big span (not use float operations), also produce more compact code

Use double value input from keyboard (not lost Hz on input)

TODO possible better use int operations for parse key input buffer
pull/118/head
DiSlord 7 years ago
parent c35f259d50
commit 51fd91adf2

@ -335,7 +335,7 @@ uint32_t my_atoui(const char *p){
return value;
}
float
double
my_atof(const char *p)
{
int neg = FALSE;
@ -343,11 +343,11 @@ my_atof(const char *p)
neg = TRUE;
if (*p == '-' || *p == '+')
p++;
float x = my_atoi(p);
double x = my_atoi(p);
while (_isdigit((int)*p))
p++;
if (*p == '.') {
float d = 1.0f;
double d = 1.0f;
p++;
while (_isdigit((int)*p)) {
d /= 10;
@ -815,11 +815,19 @@ update_marker_index(void)
void
set_frequencies(uint32_t start, uint32_t stop, uint16_t points)
{
int i;
float span = stop - start;
for (i = 0; i < points; i++) {
float offset = i * span / (float)(points - 1);
frequencies[i] = start + (uint32_t)offset;
uint32_t i;
uint32_t step = (points - 1);
uint32_t span = stop - start;
uint32_t delta = span / step;
uint32_t error = span - delta * step;
uint32_t f = start, df = step/2;
for (i = 0; i <= step; i++, f+=delta) {
frequencies[i] = f;
df+=error;
if (df >=step) {
f++;
df-=step;
}
}
// disable at out of sweep range
for (; i < sweep_points; i++)

@ -78,7 +78,7 @@ enum {
void set_sweep_frequency(int type, uint32_t frequency);
uint32_t get_sweep_frequency(int type);
float my_atof(const char *p);
double my_atof(const char *p);
void toggle_sweep(void);

@ -106,7 +106,7 @@ int awd_count;
#define KP_DONE 1
#define KP_CANCEL 2
char kp_buf[11];
char kp_buf[NUMINPUT_LEN+1];
int8_t kp_index = 0;
void ui_mode_normal(void);
@ -1791,7 +1791,7 @@ keypad_click(int key)
{
int c = keypads[key].c;
if ((c >= KP_X1 && c <= KP_G) || c == KP_N || c == KP_P) {
float scale = 1;
int32_t scale = 1;
if (c >= KP_X1 && c <= KP_G) {
int n = c - KP_X1;
while (n-- > 0)
@ -1800,7 +1800,7 @@ keypad_click(int key)
scale *= 1000;
}
/* numeric input done */
float value = my_atof(kp_buf) * scale;
double value = my_atof(kp_buf) * scale;
switch (keypad_mode) {
case KM_START:
set_sweep_frequency(ST_START, value);

Loading…
Cancel
Save

Powered by TurnKey Linux.