Merge branch 'DiSlord_test_branch'

pull/4/head v0.2
erikkaashoek 6 years ago
commit e861cb7b0b

@ -286,10 +286,8 @@ static const uint8_t ili9341_init_seq[] = {
ILI9341_POWERB, 3, 0x00, 0xC1, 0x30,
// Power on sequence control
ILI9341_POWER_SEQ, 4, 0x64, 0x03, 0x12, 0x81,
//ILI9341_POWER_SEQ, 4, 0x55, 0x01, 0x23, 0x01,
// Driver timing control A
ILI9341_DTCA, 3, 0x85, 0x00, 0x78,
//ILI9341_DTCA, 3, 0x84, 0x11, 0x7a,
// Power control A
ILI9341_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
// Pump ratio control
@ -301,11 +299,9 @@ static const uint8_t ili9341_init_seq[] = {
// POWER_CONTROL_2
ILI9341_POWER_CONTROL_2, 1, 0x10,
// VCOM_CONTROL_1
// ILI9341_VCOM_CONTROL_1, 2, 0x35, 0x3E,
ILI9341_VCOM_CONTROL_1, 2, 0x3e, 0x28,
// VCOM_CONTROL_2
ILI9341_VCOM_CONTROL_2, 1, 0xBE,
// ILI9341_VCOM_CONTROL_2, 1, 0x86,
// MEMORY_ACCESS_CONTROL
//ILI9341_MEMORY_ACCESS_CONTROL, 1, 0x48, // portlait
ILI9341_MEMORY_ACCESS_CONTROL, 1, DISPLAY_ROTATION_0, // landscape
@ -318,9 +314,9 @@ static const uint8_t ili9341_init_seq[] = {
// gamma set for curve 01/2/04/08
ILI9341_GAMMA_SET, 1, 0x01,
// positive gamma correction
ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
// negativ gamma correction
ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
// Column Address Set
//ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// Page Address Set
@ -331,10 +327,6 @@ ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07,
ILI9341_DISPLAY_FUNCTION_CONTROL, 3, 0x08, 0x82, 0x27,
// Interface Control (set WEMODE=0)
ILI9341_INTERFACE_CONTROL, 3, 0x00, 0x00, 0x00,
// control display
//ILI9341_WRITE_CTRL_DISPLAY, 1, 0x0c,
// diaplay brightness
//ILI9341_WRITE_BRIGHTNESS, 1, 0xff,
// sleep out
ILI9341_SLEEP_OUT, 0,
// display on

@ -993,7 +993,7 @@ VNA_SHELL_FUNCTION(cmd_scan)
}
if (argc >= 3) {
points = my_atoi(argv[2]);
if (points <= 0 || points > POINTS_COUNT) {
if (points <= 0 || points > sweep_points) {
shell_printf("sweep points exceeds range "define_to_STR(POINTS_COUNT)"\r\n");
return;
}

@ -863,7 +863,7 @@ static void trace_get_value_string(
if (FREQ_IS_CW()) {
float t = ii*(setting.actual_sweep_time)*1000.0/290.0;
#if 1
plot_printf(&buf2[1], sizeof(buf2) -1, "%.3FS" , t/1000000.0);
plot_printf(&buf2[1], sizeof(buf2) -1, "%.3Fs" , t/1000000.0);
#else
if (t>1000000.0){
plot_printf(&buf2[1], sizeof(buf2) -1, "%4f" , t/1000000.0);
@ -884,22 +884,17 @@ static void trace_get_value_string(
}
#endif
} else {
uint32_t resolution = get_sweep_frequency(ST_SPAN)/290;
#if 0
if (resolution <= 2000)
#if 1
uint32_t resolution = get_sweep_frequency(ST_SPAN);
if (resolution <= 2000*290)
plot_printf(&buf2[1], sizeof(buf2) -1, "%3.3f" , (dfreq + 500) / 1000000.0);
else if (resolution <= 20000)
else if (resolution <= 20000*290)
plot_printf(&buf2[1], sizeof(buf2) -1, "%3.2f" , (dfreq + 5000) / 1000000.0);
else
plot_printf(&buf2[1], sizeof(buf2) -1, "%3.1f" , (dfreq + 50000) / 1000000.0);
}
#else
int digits = 1;
if (resolution <= 2000)
digits = 3;
else if (resolution <= 20000)
digits = 2;
plot_printf(&buf2[1], sizeof(buf2) -1, "%3.*f" , digits, (dfreq + 50000) / 1000000.0);
plot_printf(&buf2[1], sizeof(buf2) -1, "%.8qHz" , dfreq);
}
#endif
// frequency_string(&buf2[1], sizeof(buf2) -1, dfreq);
@ -1906,7 +1901,7 @@ cell_draw_marker_info(int x0, int y0)
#endif
static void cell_draw_marker_info(int x0, int y0)
{
char buf[25];
char buf[32];
int t;
int ref_marker = 0;
int j = 0;
@ -1991,16 +1986,15 @@ static void cell_draw_marker_info(int x0, int y0)
if (markers[i].mtype & M_NOISE)
buf[k++] = 'N';
buf[k++] = ' ';
buf[k++] = 0;
// buf[k++] = 0;
ili9341_set_background(DEFAULT_BG_COLOR);
ili9341_set_foreground(marker_color(markers[i].mtype));
// if (setting.unit)
// cell_drawstring(buf, xpos, ypos);
// else
// cell_drawstring_7x13(buf, xpos, ypos);
int offs = strlen(buf);
trace_get_value_string(
t, &buf[offs], (sizeof buf) - offs,
t, &buf[k], (sizeof buf) - k,
idx, measured[trace[t].channel], frequencies, sweep_points, ridx, markers[i].mtype);
if (/* strlen(buf)*7> WIDTH/2 && */active > 1)
cell_drawstring(buf, xpos, ypos);
@ -2068,11 +2062,7 @@ draw_frequencies(void)
if (t < setting.sweep_time)
t = setting.sweep_time;
setting.actual_sweep_time = t;
; // in mS
if (t>=1000)
plot_printf(buf2, sizeof(buf2), " TIME %.2fS",t/1000.0);
else
plot_printf(buf2, sizeof(buf2), " TIME %.2fmS", t);
plot_printf(buf2, sizeof(buf2), " TIME %.3Fs",t/1000.0);
} else if (FREQ_IS_STARTSTOP()) {
plot_printf(buf1, sizeof(buf1), " START %qHz", get_sweep_frequency(ST_START));
@ -2096,7 +2086,7 @@ draw_frequencies(void)
buf2[0] = S_SARROW[0];
int p2 = FREQUENCIES_XPOS2;
if (FREQ_IS_CW()) {
p2 = LCD_WIDTH - 7*strlen(buf2);
p2 = LCD_WIDTH - FONT_MAX_WIDTH*strlen(buf2);
}
ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS);
ili9341_drawstring(buf2, p2, FREQUENCIES_YPOS);
@ -2131,9 +2121,10 @@ draw_cal_status(void)
ili9341_drawstring(&calibration_text[i].text, x, y);
}
#endif
// Draw battery level
#define BATTERY_TOP_LEVEL 4100
#define BATTERY_BOTTOM_LEVEL 3100
#define BATTERY_BOTTOM_LEVEL 3200
#define BATTERY_WARNING_LEVEL 3300
static void draw_battery_status(void)
@ -2145,24 +2136,28 @@ static void draw_battery_status(void)
// Set battery color
ili9341_set_foreground(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR);
ili9341_set_background(DEFAULT_BG_COLOR);
// plot_printf(string_buf, sizeof string_buf, "V:%d", vbat);
// ili9341_drawstringV(string_buf, 1, 60);
// Prepare battery bitmap image
// Battery top
int x = 0;
string_buf[x++] = 0b00000000;
string_buf[x++] = 0b00111100;
string_buf[x++] = 0b00111100;
string_buf[x++] = 0b00100100;
string_buf[x++] = 0b11111111;
// string_buf[x++] = 0b10000001;
// Fill battery status
for (int power=BATTERY_TOP_LEVEL; power > BATTERY_BOTTOM_LEVEL; power-=100)
for (int power=BATTERY_TOP_LEVEL; power > BATTERY_BOTTOM_LEVEL; ){
if ((x&3) == 0) {string_buf[x++] = 0b10000001; continue;}
string_buf[x++] = (power > vbat) ? 0b10000001 : // Empty line
0b11111111; // Full line
0b10111101; // Full line
power-=100;
}
// Battery bottom
// string_buf[x++] = 0b10000001;
string_buf[x++] = 0b10000001;
string_buf[x++] = 0b11111111;
// Draw battery
blit8BitWidthBitmap(1, 200, 8, x, string_buf);
blit8BitWidthBitmap(7, LCD_HEIGHT-50, 8, x, string_buf);
plot_printf((char*)string_buf, sizeof string_buf, "%.2fv", vbat/1000.0);
ili9341_drawstring((char*)string_buf, 1, LCD_HEIGHT-50+x+3);
}
void

@ -1949,8 +1949,9 @@ static const char * const scale_vtext[]= {"50000", "20000", "10000", "5000", "20
void draw_cal_status(void)
{
#define BLEN 10
char buf[BLEN];
#define BLEN 7
char buf[BLEN+1];
buf[6]=0;
#define YSTEP 8
int x = 0;
int y = OFFSETY;
@ -1960,8 +1961,6 @@ void draw_cal_status(void)
rounding = true;
const char * const unit = unit_string[setting.unit];
#define XSTEP 40
ili9341_fill(0, 0, OFFSETX, LCD_HEIGHT-1, 0x0000);
if (MODE_OUTPUT(setting.mode)) { // No cal status during output
return;
@ -1975,10 +1974,10 @@ void draw_cal_status(void)
float yMax = setting.reflevel;
// Top level
if (rounding)
plot_printf(buf, BLEN, "%4d", (int)yMax);
plot_printf(buf, BLEN, "%+4d", (int)yMax);
else
plot_printf(buf, BLEN, "%.3F", (yMax/setting.unit_scale));
// buf[5]=0;
plot_printf(buf, BLEN, "%+.3F", (yMax/setting.unit_scale));
if (level_is_calibrated()) {
if (setting.auto_reflevel)
color = DEFAULT_FG_COLOR;
@ -2030,10 +2029,9 @@ void draw_cal_status(void)
color = BRIGHT_COLOR_GREEN;
ili9341_set_foreground(color);
y += YSTEP + YSTEP/2 ;
ili9341_drawstring("Attn:", x, y);
ili9341_drawstring("Atten:", x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%.2FdB", get_attenuation());
buf[6]=0;
ili9341_drawstring(buf, x, y);
// }
@ -2045,7 +2043,6 @@ void draw_cal_status(void)
y += YSTEP;
plot_printf(buf, BLEN, "%s",averageText[setting.average]);
buf[6]=0;
ili9341_drawstring(buf, x, y);
}
// Spur
@ -2073,7 +2070,6 @@ void draw_cal_status(void)
y += YSTEP;
plot_printf(buf, BLEN, "%.1FkHz", actual_rbw);
// buf[6]=0;
ili9341_drawstring(buf, x, y);
#if 0
@ -2107,16 +2103,7 @@ void draw_cal_status(void)
if (t < setting.sweep_time)
t = setting.sweep_time;
setting.actual_sweep_time = t;
if (t>=10000.0)
plot_printf(buf, BLEN, "%5d",(int)(t/1000));
else if (t>=1000)
plot_printf(buf, BLEN, "%5f",t/1000.0);
else {
plot_printf(buf, BLEN, "%4dm",(int)t);
buf[4] = 'm';
}
buf[5]='S';
buf[6]=0;
plot_printf(buf, BLEN, "%.3Fs", t/1000.0);
ili9341_drawstring(buf, x, y);
// Cal output
@ -2139,7 +2126,6 @@ void draw_cal_status(void)
y += YSTEP;
plot_printf(buf, BLEN, "%.1fdB",setting.offset);
buf[6]=0;
ili9341_drawstring(buf, x, y);
}
@ -2171,7 +2157,6 @@ void draw_cal_status(void)
else
plot_printf(buf, BLEN, "%.4F", value(setting.trigger_level));
// plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)/setting.unit_scale);
buf[6]=0;
ili9341_drawstring(buf, x, y);
}
@ -2182,16 +2167,13 @@ void draw_cal_status(void)
color = BRIGHT_COLOR_RED;
ili9341_set_foreground(color);
y += YSTEP + YSTEP/2 ;
if (MODE_LOW(setting.mode))
ili9341_drawstring_7x13("LOW", x, y);
else
ili9341_drawstring_7x13("HIGH", x, y);
ili9341_drawstring_7x13(MODE_LOW(setting.mode) ? "LOW" : "HIGH", x, y);
// Compact status string
// ili9341_set_background(DEFAULT_FG_COLOR);
ili9341_set_foreground(DEFAULT_FG_COLOR);
y += YSTEP + YSTEP/2 ;
strncpy(buf," ",BLEN);
strncpy(buf," ",BLEN-1);
if (setting.auto_attenuation)
buf[0] = 'a';
else
@ -2220,8 +2202,7 @@ void draw_cal_status(void)
// Version
y += YSTEP + YSTEP/2 ;
strncpy(buf,&VERSION[8],6);
buf[6]=0;
strncpy(buf,&VERSION[8], BLEN-1);
ili9341_drawstring(buf, x, y);
// ili9341_set_background(DEFAULT_BG_COLOR);
@ -2319,8 +2300,6 @@ static void test_acquire(int i)
redraw_request |= REDRAW_CELLS | REDRAW_FREQUENCY;
}
extern void cell_drawstring_5x7(int w, int h, char *str, int x, int y, uint16_t fg);
extern void cell_drawstring_7x13(int w, int h, char *str, int x, int y, uint16_t fg);
void cell_drawstring(char *str, int x, int y);
static char self_test_status_buf[35];

@ -327,7 +327,7 @@ void SI4432_Fill(int s, int start)
if (t < 0)
t = 0;
int ti = t * 1000 / 290.0; // Now in uS per point if (t < 30000)
for (int i=start; i<POINTS_COUNT; ) {
for (int i=start; i<sweep_points; ) {
SPI2_CLK_LOW;
palClearPad(GPIOC, sel);
shiftOut( 0x26 );
@ -356,7 +356,7 @@ float SI4432_RSSI(uint32_t i, int s)
#ifdef __FAST_SWEEP__
if (buf_read) {
float dBm = ((float)((unsigned char)age[buf_index++]))/2 + SI4432_RSSI_correction;
if (buf_index ==POINTS_COUNT) {
if (buf_index == sweep_points) {
buf_read = false;
}
return dBm;

104
ui.c

@ -42,9 +42,9 @@ uistat_t uistat = {
#define EVT_DOWN 0x20
#define EVT_REPEAT 0x40
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
#define BUTTON_DOUBLE_TICKS 2500 /* 500ms */
#define BUTTON_REPEAT_TICKS 625 /* 125ms */
#define BUTTON_DOWN_LONG_TICKS 5000 /* 500ms */
#define BUTTON_DOUBLE_TICKS 2500 /* 250ms */
#define BUTTON_REPEAT_TICKS 400 /* 40ms */
#define BUTTON_DEBOUNCE_TICKS 200
/* lever switch assignment */
@ -62,7 +62,6 @@ uistat_t uistat = {
static uint16_t last_button = 0b0000;
static uint32_t last_button_down_ticks;
static uint32_t last_button_repeat_ticks;
static int8_t inhibit_until_release = FALSE;
volatile uint8_t operation_requested = OP_NONE;
@ -135,73 +134,62 @@ static void menu_push_submenu(const menuitem_t *submenu);
static int btn_check(void)
{
int cur_button = READ_PORT() & BUTTON_MASK;
int changed = last_button ^ cur_button;
int status = 0;
uint32_t ticks = chVTGetSystemTime();
if (changed & (1<<BIT_PUSH)) {
if ((cur_button & (1<<BIT_PUSH))
&& ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
// button released
status |= EVT_BUTTON_SINGLE_CLICK;
if (inhibit_until_release) {
status = 0;
inhibit_until_release = FALSE;
}
}
}
if (changed & (1<<BIT_UP1)) {
if ((cur_button & (1<<BIT_UP1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_UP;
}
}
if (changed & (1<<BIT_DOWN1)) {
if ((cur_button & (1<<BIT_DOWN1))
&& (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS)) {
status |= EVT_DOWN;
}
}
last_button_down_ticks = ticks;
last_button = cur_button;
return status;
systime_t ticks;
// Debounce input
while(TRUE){
ticks = chVTGetSystemTimeX();
if(ticks - last_button_down_ticks > BUTTON_DEBOUNCE_TICKS)
break;
chThdSleepMilliseconds(10);
}
int status = 0;
uint16_t cur_button = READ_PORT() & BUTTON_MASK;
// Detect only changed and pressed buttons
uint16_t button_set = (last_button ^ cur_button) & cur_button;
last_button_down_ticks = ticks;
last_button = cur_button;
if (button_set & (1<<BIT_PUSH))
status |= EVT_BUTTON_SINGLE_CLICK;
if (button_set & (1<<BIT_UP1))
status |= EVT_UP;
if (button_set & (1<<BIT_DOWN1))
status |= EVT_DOWN;
return status;
}
static int btn_wait_release(void)
{
while (TRUE) {
int cur_button = READ_PORT() & BUTTON_MASK;
int changed = last_button ^ cur_button;
uint32_t ticks = chVTGetSystemTime();
int status = 0;
if (!inhibit_until_release) {
if ((cur_button & (1<<BIT_PUSH))
&& ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
inhibit_until_release = TRUE;
return EVT_BUTTON_DOWN_LONG;
}
if ((changed & (1<<BIT_PUSH))
&& ticks < last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
return EVT_BUTTON_SINGLE_CLICK;
}
}
if (changed) {
systime_t ticks = chVTGetSystemTimeX();
systime_t dt = ticks - last_button_down_ticks;
// Debounce input
// if (dt < BUTTON_DEBOUNCE_TICKS){
// chThdSleepMilliseconds(10);
// continue;
// }
chThdSleepMilliseconds(1);
uint16_t cur_button = READ_PORT() & BUTTON_MASK;
uint16_t changed = last_button ^ cur_button;
if (dt >= BUTTON_DOWN_LONG_TICKS && (cur_button & (1<<BIT_PUSH)))
return EVT_BUTTON_DOWN_LONG;
else if (changed & (1<<BIT_PUSH)) // release
return EVT_BUTTON_SINGLE_CLICK;
if (changed) {
// finished
last_button = cur_button;
last_button_down_ticks = ticks;
inhibit_until_release = FALSE;
return 0;
}
if (ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS
&& ticks >= last_button_repeat_ticks + BUTTON_REPEAT_TICKS) {
if (dt > BUTTON_DOWN_LONG_TICKS &&
ticks > last_button_repeat_ticks) {
int status = 0;
if (cur_button & (1<<BIT_DOWN1))
status |= EVT_DOWN | EVT_REPEAT;
if (cur_button & (1<<BIT_UP1))
status |= EVT_UP | EVT_REPEAT;
last_button_repeat_ticks = ticks;
last_button_repeat_ticks = ticks + BUTTON_REPEAT_TICKS;
return status;
}
}
@ -1926,8 +1914,8 @@ lever_move_marker(int status)
}
if ((status & EVT_UP) && markers[active_marker].index < sweep_points-1) {
markers[active_marker].index += step;
if (markers[active_marker].index > POINTS_COUNT-1)
markers[active_marker].index = POINTS_COUNT-1 ;
if (markers[active_marker].index > sweep_points-1)
markers[active_marker].index = sweep_points-1 ;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.