@ -42,7 +42,7 @@ int area_height = HEIGHT+1;
* CELL_X [ 5 : 9 ] position in the cell
* CELL_X [ 5 : 9 ] position in the cell
* CELL_Y [ 0 : 4 ]
* CELL_Y [ 0 : 4 ]
*/
*/
uint32_t trace_index [ TRACES_MAX ] [ 101 ] ;
uint32_t trace_index [ TRACES_MAX ] [ POINTS_COUNT ] ;
# define INDEX(x, y, n) \
# define INDEX(x, y, n) \
( ( ( ( x ) & 0x03e0UL ) < < 22 ) | ( ( ( y ) & 0x03e0UL ) < < 17 ) | ( ( ( n ) & 0x0fffUL ) < < 10 ) \
( ( ( ( x ) & 0x03e0UL ) < < 22 ) | ( ( ( y ) & 0x03e0UL ) < < 17 ) | ( ( ( n ) & 0x0fffUL ) < < 10 ) \
@ -66,10 +66,10 @@ int floatToInt(float v){
void update_grid ( void )
void update_grid ( void )
{
{
int32_t gdigit = 100000000 ;
u int32_t gdigit = 100000000 ;
int32_t fstart , fspan ;
u int32_t fstart , fspan ;
int32_t grid ;
u int32_t grid ;
if ( frequency0 < frequency1 ) {
if ( frequency0 < = frequency1 ) {
fstart = frequency0 ;
fstart = frequency0 ;
fspan = frequency1 - frequency0 ;
fspan = frequency1 - frequency0 ;
} else {
} else {
@ -498,7 +498,7 @@ cartesian_scale(float re, float im, int *xp, int *yp, float scale)
}
}
float
float
groupdelay_from_array ( int i , float array [ 101 ] [ 2 ] )
groupdelay_from_array ( int i , float array [ POINTS_COUNT ] [ 2 ] )
{
{
/*
/*
if ( i = = 0 ) {
if ( i = = 0 ) {
@ -513,13 +513,13 @@ groupdelay_from_array(int i, float array[101][2])
}
}
*/
*/
int bottom = ( i = = 0 ) ? 0 : i - 1 ;
int bottom = ( i = = 0 ) ? 0 : i - 1 ;
int top = ( i = = 1 00 ) ? 1 00 : i + 1 ;
int top = ( i = = POINTS_COUNT - 1 ) ? POINTS_COUNT - 1 : i + 1 ;
float deltaf = frequencies [ top ] - frequencies [ bottom ] ;
float deltaf = frequencies [ top ] - frequencies [ bottom ] ;
return groupdelay ( array [ bottom ] , array [ top ] , deltaf ) ;
return groupdelay ( array [ bottom ] , array [ top ] , deltaf ) ;
}
}
uint32_t
uint32_t
trace_into_index ( int x , int t , int i , float array [ 101 ] [ 2 ] )
trace_into_index ( int x , int t , int i , float array [ POINTS_COUNT ] [ 2 ] )
{
{
int y = 0 ;
int y = 0 ;
float v = 0 ;
float v = 0 ;
@ -626,7 +626,6 @@ string_value_with_prefix(char *buf, int len, float val, char unit)
return n ;
return n ;
}
}
# define PI2 6.283184
# define PI2 6.283184
static void
static void
@ -704,7 +703,7 @@ gamma2reactance(char *buf, int len, const float coeff[2])
}
}
static void
static void
trace_get_value_string ( int t , char * buf , int len , float array [ 101 ] [ 2 ] , int i )
trace_get_value_string ( int t , char * buf , int len , float array [ POINTS_COUNT ] [ 2 ] , int i )
{
{
float * coeff = array [ i ] ;
float * coeff = array [ i ] ;
float v ;
float v ;
@ -758,7 +757,7 @@ trace_get_value_string(int t, char *buf, int len, float array[101][2], int i)
}
}
static void
static void
trace_get_value_string_delta ( int t , char * buf , int len , float array [ 101 ] [ 2 ] , int index , int index_ref )
trace_get_value_string_delta ( int t , char * buf , int len , float array [ POINTS_COUNT ] [ 2 ] , int index , int index_ref )
{
{
float * coeff = array [ index ] ;
float * coeff = array [ index ] ;
float * coeff_ref = array [ index_ref ] ;
float * coeff_ref = array [ index_ref ] ;
@ -928,11 +927,11 @@ mark_cells_from_index(void)
}
}
}
}
void plot_into_index ( float measured [ 2 ] [ 101 ] [ 2 ] )
void plot_into_index ( float measured [ 2 ] [ POINTS_COUNT ] [ 2 ] )
{
{
int i , t ;
int i , t ;
for ( i = 0 ; i < sweep_points ; i + + ) {
for ( i = 0 ; i < sweep_points ; i + + ) {
int x = i * ( WIDTH - 1 ) / ( sweep_points - 1 ) ;
int x = ( i * ( WIDTH - 1 ) + sweep_points / 2 ) / ( sweep_points - 1 ) ;
for ( t = 0 ; t < TRACES_MAX ; t + + ) {
for ( t = 0 ; t < TRACES_MAX ; t + + ) {
if ( ! trace [ t ] . enabled )
if ( ! trace [ t ] . enabled )
continue ;
continue ;
@ -1026,7 +1025,7 @@ cell_drawline(int w, int h, int x0, int y0, int x1, int y1, int c)
}
}
int
int
search_index_range ( int x , int y , uint32_t index [ 101 ] , int * i0 , int * i1 )
search_index_range ( int x , int y , uint32_t index [ POINTS_COUNT ] , int * i0 , int * i1 )
{
{
int i , j ;
int i , j ;
int head = 0 ;
int head = 0 ;
@ -1056,14 +1055,14 @@ search_index_range(int x, int y, uint32_t index[101], int *i0, int *i1)
j - - ;
j - - ;
* i0 = j ;
* i0 = j ;
j = i ;
j = i ;
while ( j < 1 00 & & x = = CELL_X0 ( index [ j + 1 ] ) & & y = = CELL_Y0 ( index [ j + 1 ] ) )
while ( j < POINTS_COUNT - 1 & & x = = CELL_X0 ( index [ j + 1 ] ) & & y = = CELL_Y0 ( index [ j + 1 ] ) )
j + + ;
j + + ;
* i1 = j ;
* i1 = j ;
return TRUE ;
return TRUE ;
}
}
static int
static int
search_index_range_x ( int x , uint32_t index [ 101 ] , int * i0 , int * i1 )
search_index_range_x ( int x , uint32_t index [ POINTS_COUNT ] , int * i0 , int * i1 )
{
{
int i , j ;
int i , j ;
int head = 0 ;
int head = 0 ;
@ -1093,7 +1092,7 @@ search_index_range_x(int x, uint32_t index[101], int *i0, int *i1)
j - - ;
j - - ;
* i0 = j ;
* i0 = j ;
j = i ;
j = i ;
while ( j < 1 00 & & x = = CELL_X0 ( index [ j + 1 ] ) )
while ( j < POINTS_COUNT - 1 & & x = = CELL_X0 ( index [ j + 1 ] ) )
j + + ;
j + + ;
* i1 = j ;
* i1 = j ;
return TRUE ;
return TRUE ;
@ -1238,7 +1237,7 @@ marker_search(void)
return - 1 ;
return - 1 ;
int value = CELL_Y ( trace_index [ uistat . current_trace ] [ 0 ] ) ;
int value = CELL_Y ( trace_index [ uistat . current_trace ] [ 0 ] ) ;
for ( i = 0 ; i < 101 ; i + + ) {
for ( i = 0 ; i < POINTS_COUNT ; i + + ) {
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
if ( ( * compare ) ( value , CELL_Y ( index ) ) ) {
if ( ( * compare ) ( value , CELL_Y ( index ) ) ) {
value = CELL_Y ( index ) ;
value = CELL_Y ( index ) ;
@ -1296,14 +1295,14 @@ marker_search_right(int from)
return - 1 ;
return - 1 ;
int value = CELL_Y ( trace_index [ uistat . current_trace ] [ from ] ) ;
int value = CELL_Y ( trace_index [ uistat . current_trace ] [ from ] ) ;
for ( i = from + 1 ; i < 101 ; i + + ) {
for ( i = from + 1 ; i < POINTS_COUNT ; i + + ) {
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
if ( ( * compare ) ( value , CELL_Y ( index ) ) )
if ( ( * compare ) ( value , CELL_Y ( index ) ) )
break ;
break ;
value = CELL_Y ( index ) ;
value = CELL_Y ( index ) ;
}
}
for ( ; i < 101 ; i + + ) {
for ( ; i < POINTS_COUNT ; i + + ) {
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
uint32_t index = trace_index [ uistat . current_trace ] [ i ] ;
if ( ( * compare ) ( CELL_Y ( index ) , value ) ) {
if ( ( * compare ) ( CELL_Y ( index ) , value ) ) {
break ;
break ;
@ -1482,7 +1481,7 @@ draw_cell(int m, int n)
if ( search_index_range_x ( x0 , trace_index [ t ] , & i0 , & i1 ) ) {
if ( search_index_range_x ( x0 , trace_index [ t ] , & i0 , & i1 ) ) {
if ( i0 > 0 )
if ( i0 > 0 )
i0 - - ;
i0 - - ;
if ( i1 < 101 - 1 )
if ( i1 < POINTS_COUNT - 1 )
i1 + + ;
i1 + + ;
for ( i = i0 ; i < i1 ; i + + ) {
for ( i = i0 ; i < i1 ; i + + ) {
int x1 = CELL_X ( trace_index [ t ] [ i ] ) ;
int x1 = CELL_X ( trace_index [ t ] [ i ] ) ;
@ -1665,10 +1664,10 @@ cell_draw_marker_info(int m, int n, int w, int h)
if ( mk = = active_marker )
if ( mk = = active_marker )
cell_drawstring ( w , h , S_SARROW , xpos , ypos ) ;
cell_drawstring ( w , h , S_SARROW , xpos , ypos ) ;
xpos + = 5 ;
xpos + = 5 ;
chsnprintf ( buf , sizeof buf , " M K %d" , mk ) ;
chsnprintf ( buf , sizeof buf , " M %d" , mk + 1 ) ;
cell_drawstring ( w , h , buf , xpos , ypos ) ;
cell_drawstring ( w , h , buf , xpos , ypos ) ;
xpos + = 1 9 ;
xpos + = 1 3 ;
//trace_get_info(t, buf, sizeof buf);
//trace_get_info(t, buf, sizeof buf);
int32_t freq = frequencies [ markers [ mk ] . index ] ;
int32_t freq = frequencies [ markers [ mk ] . index ] ;
if ( uistat . marker_delta & & mk ! = active_marker ) {
if ( uistat . marker_delta & & mk ! = active_marker ) {
@ -1691,7 +1690,7 @@ cell_draw_marker_info(int m, int n, int w, int h)
// draw marker delta
// draw marker delta
if ( ! uistat . marker_delta & & previous_marker > = 0 & & active_marker ! = previous_marker & & markers [ previous_marker ] . enabled ) {
if ( ! uistat . marker_delta & & previous_marker > = 0 & & active_marker ! = previous_marker & & markers [ previous_marker ] . enabled ) {
int idx0 = markers [ previous_marker ] . index ;
int idx0 = markers [ previous_marker ] . index ;
int xpos = 1 92 ;
int xpos = 1 85 ;
int ypos = 1 + ( j / 2 ) * 8 ;
int ypos = 1 + ( j / 2 ) * 8 ;
xpos - = m * CELLWIDTH - CELLOFFSETX ;
xpos - = m * CELLWIDTH - CELLOFFSETX ;
ypos - = n * CELLHEIGHT ;
ypos - = n * CELLHEIGHT ;
@ -1701,7 +1700,8 @@ cell_draw_marker_info(int m, int n, int w, int h)
cell_drawstring ( w , h , buf , xpos , ypos ) ;
cell_drawstring ( w , h , buf , xpos , ypos ) ;
xpos + = 19 ;
xpos + = 19 ;
if ( ( domain_mode & DOMAIN_MODE ) = = DOMAIN_FREQ ) {
if ( ( domain_mode & DOMAIN_MODE ) = = DOMAIN_FREQ ) {
frequency_string ( buf , sizeof buf , frequencies [ idx ] - frequencies [ idx0 ] , " " ) ;
uint32_t delta = frequencies [ idx ] > frequencies [ idx0 ] ? frequencies [ idx ] - frequencies [ idx0 ] : frequencies [ idx0 ] - frequencies [ idx ] ;
frequency_string ( buf , sizeof buf , delta , " " ) ;
} else {
} else {
//chsnprintf(buf, sizeof buf, "%d ns %.1f m", (uint16_t)(time_of_index(idx) * 1e9 - time_of_index(idx0) * 1e9),
//chsnprintf(buf, sizeof buf, "%d ns %.1f m", (uint16_t)(time_of_index(idx) * 1e9 - time_of_index(idx0) * 1e9),
// distance_of_index(idx) - distance_of_index(idx0));
// distance_of_index(idx) - distance_of_index(idx0));
@ -1742,10 +1742,11 @@ cell_draw_marker_info(int m, int n, int w, int h)
}
}
// draw marker frequency
// draw marker frequency
int xpos = 1 92 ;
int xpos = 1 85 ;
int ypos = 1 + ( j / 2 ) * 8 ;
int ypos = 1 + ( j / 2 ) * 8 ;
xpos - = m * CELLWIDTH - CELLOFFSETX ;
xpos - = m * CELLWIDTH - CELLOFFSETX ;
ypos - = n * CELLHEIGHT ;
ypos - = n * CELLHEIGHT ;
setForegroundColor ( DEFAULT_FG_COLOR ) ;
// strcpy(buf, "1:");
// strcpy(buf, "1:");
// buf[0] += active_marker;
// buf[0] += active_marker;
// xpos += 5;
// xpos += 5;
@ -1755,7 +1756,7 @@ cell_draw_marker_info(int m, int n, int w, int h)
if ( uistat . lever_mode = = LM_MARKER )
if ( uistat . lever_mode = = LM_MARKER )
cell_drawstring ( w , h , S_SARROW , xpos , ypos ) ;
cell_drawstring ( w , h , S_SARROW , xpos , ypos ) ;
xpos + = 5 ;
xpos + = 5 ;
chsnprintf ( buf , sizeof buf , " 1:%d" , active_marker ) ;
chsnprintf ( buf , sizeof buf , " M%d:" , active_marker + 1 ) ;
cell_drawstring ( w , h , buf , xpos , ypos ) ;
cell_drawstring ( w , h , buf , xpos , ypos ) ;
xpos + = 19 ;
xpos + = 19 ;
@ -1854,8 +1855,8 @@ draw_frequencies(void)
}
}
} else {
} else {
chsnprintf ( buf1 , sizeof buf 1, " START 0s " ) ;
chsnprintf ( buf1 + 1 , sizeof ( buf1 ) - 1, " START 0s " ) ;
chsnprintf ( buf2 , sizeof buf2 , " %s%d ns" , " STOP " , ( uint16_t ) ( time_of_index ( 10 1) * 1e9 ) ) ;
chsnprintf ( buf2 , sizeof buf2 , " %s%d ns (%.2fm) " , " STOP " , ( uint16_t ) ( time_of_index ( POINTS_COUNT - 1) * 1e9 ) , distance_of_index ( POINTS_COUNT - 1 ) ) ;
}
}
setForegroundColor ( DEFAULT_FG_COLOR ) ;
setForegroundColor ( DEFAULT_FG_COLOR ) ;
setBackgroundColor ( DEFAULT_BG_COLOR ) ;
setBackgroundColor ( DEFAULT_BG_COLOR ) ;
@ -1919,7 +1920,7 @@ draw_battery_status(void)
{
{
uint8_t string_buf [ 25 ] ;
uint8_t string_buf [ 25 ] ;
// Set battery color
// Set battery color
setForegroundColor ( vbat < BATTERY_WARNING_LEVEL ? RGBHEX ( 0xff0000 ) : RGBHEX ( 0x1fe300 ) ) ;
setForegroundColor ( vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR ) ;
setBackgroundColor ( DEFAULT_BG_COLOR ) ;
setBackgroundColor ( DEFAULT_BG_COLOR ) ;
// chsnprintf(string_buf, sizeof string_buf, "V:%d", vbat);
// chsnprintf(string_buf, sizeof string_buf, "V:%d", vbat);
// ili9341_drawstringV(string_buf, 1, 60);
// ili9341_drawstringV(string_buf, 1, 60);