add keypad for freq and scale, add save menu

This commit is contained in:
TT 2016-12-04 16:19:31 +09:00
parent 3323e116a3
commit a50517bf3f
6 changed files with 566 additions and 184 deletions

View file

@ -113,6 +113,8 @@ caldata_recall(int id)
if (id < 0 || id >= SAVEAREA_MAX) if (id < 0 || id >= SAVEAREA_MAX)
return -1; return -1;
// point to saved area on the flash memory
src = (config_t*)saveareas[id]; src = (config_t*)saveareas[id];
if (src->magic != CONFIG_MAGIC) if (src->magic != CONFIG_MAGIC)

View file

@ -287,7 +287,7 @@ ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
} }
void void
ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg) ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg)
{ {
while (*str) { while (*str) {
ili9341_drawchar_5x7(*str, x, y, fg, bg); ili9341_drawchar_5x7(*str, x, y, fg, bg);
@ -334,14 +334,6 @@ ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg)
} }
typedef struct {
uint16_t width;
uint16_t height;
uint16_t scaley;
uint16_t slide;
const uint32_t *bitmap;
} font_t;
const font_t NF20x24 = { 20, 24, 1, 24, (const uint32_t *)numfont20x24 }; const font_t NF20x24 = { 20, 24, 1, 24, (const uint32_t *)numfont20x24 };
//const font_t NF32x24 = { 32, 24, 1, 24, (const uint32_t *)numfont32x24 }; //const font_t NF32x24 = { 32, 24, 1, 24, (const uint32_t *)numfont32x24 };
//const font_t NF32x48 = { 32, 48, 2, 24, (const uint32_t *)numfont32x24 }; //const font_t NF32x48 = { 32, 48, 2, 24, (const uint32_t *)numfont32x24 };
@ -349,14 +341,9 @@ const font_t NF20x24 = { 20, 24, 1, 24, (const uint32_t *)numfont20x24 };
void void
ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg) ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg)
{ {
int ex = x + font->width-1;
int ey = y + font->height-1;
uint8_t xx[4] = { x >> 8, x, ex >> 8, ex };
uint8_t yy[4] = { y >> 8, y, ey >> 8, ey };
uint16_t *buf = spi_buffer; uint16_t *buf = spi_buffer;
uint32_t bits; uint32_t bits;
const uint32_t *bitmap = &font->bitmap[font->slide * ch]; const uint32_t *bitmap = &font->bitmap[font->slide * ch];
int len;
int c, r, j; int c, r, j;
for (c = 0; c < font->slide; c++) { for (c = 0; c < font->slide; c++) {
@ -368,13 +355,7 @@ ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint
} }
} }
} }
send_command(0x2A, 4, xx); ili9341_bulk(x, y, font->width, font->height);
send_command(0x2B, 4, yy);
send_command(0x2C, 0, NULL);
len = buf - spi_buffer;
buf = spi_buffer;
while (len-- > 0)
ssp_senddata16(*buf++);
} }

50
main.c
View file

@ -454,6 +454,34 @@ update_frequencies(void)
int32_t span = (freq_stop - freq_start)/100; int32_t span = (freq_stop - freq_start)/100;
for (i = 0; i < sweep_points; i++) for (i = 0; i < sweep_points; i++)
frequencies[i] = freq_start + span * i / (sweep_points - 1) * 100; frequencies[i] = freq_start + span * i / (sweep_points - 1) * 100;
// set grid layout
set_sweep(freq_start, freq_stop);
}
void
set_sweep_frequency(int type, int frequency)
{
switch (type) {
case ST_START:
if (freq_start != frequency) {
ensure_edit_config();
freq_start = frequency;
update_frequencies();
}
break;
case ST_STOP:
if (freq_start != frequency) {
ensure_edit_config();
freq_stop = frequency;
update_frequencies();
}
break;
case ST_CENTER:
break;
case ST_SPAN:
break;
}
} }
static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[]) static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
@ -482,6 +510,7 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
} }
freq_stop = x; freq_stop = x;
} }
#if 0
if (argc >= 3) { if (argc >= 3) {
int32_t x = atoi(argv[2]); int32_t x = atoi(argv[2]);
if (x < 1 || x > 1601) { if (x < 1 || x > 1601) {
@ -490,9 +519,9 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
} }
sweep_points = x; sweep_points = x;
} }
#endif
update_frequencies(); update_frequencies();
set_sweep(freq_start, freq_stop);
} }
@ -813,7 +842,7 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
pause_sweep(); pause_sweep();
if (caldata_recall(id) == 0) { if (caldata_recall(id) == 0) {
// success // success
set_sweep(freq_start, freq_stop); update_frequencies();
draw_cal_status(); draw_cal_status();
} }
@ -864,7 +893,15 @@ void set_trace_channel(int t, int channel)
} }
} }
static float void set_trace_scale(int t, float scale)
{
if (trace[t].scale != scale) {
trace[t].scale = scale;
force_set_markmap();
}
}
float
my_atof(const char *p) my_atof(const char *p)
{ {
int neg = FALSE; int neg = FALSE;
@ -1203,13 +1240,12 @@ int main(void)
*/ */
plot_init(); plot_init();
/* initial 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);
set_sweep(freq_start, freq_stop); /* initial frequencies */
update_frequencies();
redraw(); redraw();
/* /*

View file

@ -58,6 +58,16 @@ int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strengt
/* /*
* ili9341.c * ili9341.c
*/ */
typedef struct {
uint16_t width;
uint16_t height;
uint16_t scaley;
uint16_t slide;
const uint32_t *bitmap;
} font_t;
extern const font_t NF20x24;
extern uint16_t spi_buffer[1024]; extern uint16_t spi_buffer[1024];
void ili9341_init(void); void ili9341_init(void);
@ -65,7 +75,9 @@ void ili9341_test(int mode);
void ili9341_bulk(int x, int y, int w, int h); void ili9341_bulk(int x, int y, int w, int h);
void ili9341_fill(int x, int y, int w, int h, int color); void ili9341_fill(int x, int y, int w, int h, int color);
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg); void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg); void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
/* /*
* plot.c * plot.c
@ -124,6 +136,7 @@ typedef struct {
void set_trace_type(int t, int type); void set_trace_type(int t, int type);
void set_trace_channel(int t, int channel); void set_trace_channel(int t, int channel);
void set_trace_scale(int t, float scale);
// marker // marker
@ -183,6 +196,13 @@ extern float measured[2][101][2];
void cal_collect(int type); void cal_collect(int type);
void cal_done(void); void cal_done(void);
enum {
ST_START, ST_STOP, ST_CENTER, ST_SPAN
};
void set_sweep_frequency(int type, int frequency);
float my_atof(const char *p);
/* /*
* flash.c * flash.c
@ -212,11 +232,11 @@ extern int16_t lastsaveid;
extern config_t *active; extern config_t *active;
extern config_t current_config; extern config_t current_config;
#define freq_start active->_freq_start #define freq_start current_config._freq_start
#define freq_stop active->_freq_stop #define freq_stop current_config._freq_stop
#define sweep_points active->_sweep_points #define sweep_points current_config._sweep_points
#define cal_status current_config._cal_status #define cal_status current_config._cal_status
#define frequencies active->_frequencies #define frequencies current_config._frequencies
#define cal_data active->_cal_data #define cal_data active->_cal_data
#define trace current_config._trace #define trace current_config._trace

View file

@ -89,15 +89,15 @@ const uint32_t numfont20x24[][24] = {
0b00000000000011111110000000000000, 0b00000000000011111110000000000000,
0b00000000001111111100000000000000, 0b00000000001111111100000000000000,
0b00000001111111111000000000000000, 0b00000000111111111000000000000000,
0b00000111111111100000000000000000, 0b00000011111111100000000000000000,
0b00011111111100000000000000000000, 0b00001111111110000000000000000000,
0b00111111110000000000000000000000, 0b00011111111000000000000000000000,
0b00111111100000000000000000000000,
0b01111111000000000000000000000000, 0b01111111000000000000000000000000,
0b11111100000000000000000000000000,
0b11111000000000000000000000000000, 0b11111110000000000000000000000000,
0b11111000000000000000000000000000, 0b11111100000000000000000000000000,
0b11111111111111111110000000000000, 0b11111111111111111110000000000000,
0b11111111111111111110000000000000, 0b11111111111111111110000000000000,
0b11111111111111111110000000000000, 0b11111111111111111110000000000000,
@ -125,7 +125,7 @@ const uint32_t numfont20x24[][24] = {
0b11111000000000111110000000000000, 0b11111000000000111110000000000000,
0b11111000000000111110000000000000, 0b11111000000000111110000000000000,
0b11111100000001111110000000000000, 0b11111110000001111110000000000000,
0b01111111111111111100000000000000, 0b01111111111111111100000000000000,
0b00111111111111111000000000000000, 0b00111111111111111000000000000000,
0b00001111111111110000000000000000, 0b00001111111111110000000000000000,
@ -181,7 +181,7 @@ const uint32_t numfont20x24[][24] = {
0b11111000000000111110000000000000, 0b11111000000000111110000000000000,
0b11111000000001111110000000000000, 0b11111000000001111110000000000000,
0b11111100000111111110000000000000, 0b11111110000111111110000000000000,
0b01111111111111111100000000000000, 0b01111111111111111100000000000000,
0b00111111111111111000000000000000, 0b00111111111111111000000000000000,
0b00001111111111110000000000000000, 0b00001111111111110000000000000000,
@ -320,12 +320,12 @@ const uint32_t numfont20x24[][24] = {
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
0b00000001110000000000000000000000, 0b00000001110000000000000000000000,
0b00000011111000000000000000000000, 0b00000011111000000000000000000000,
0b00000011111000000000000000000000, 0b00000011111000000000000000000000,
0b00000001110000000000100000000000, 0b00000001110000000000000000000000,
0b00000000000000000000100000000000,
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
0b00000000000000000000000000000000 0b00000000000000000000000000000000
}, },
@ -357,6 +357,146 @@ const uint32_t numfont20x24[][24] = {
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
0b00000000000000000000000000000000 0b00000000000000000000000000000000
}, },
{ // x1
0b00000000000000000000100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000,
0b00000000000000011110000000000000,
0b00000000000000111110000000000000,
0b00000000000001111110000000000000,
0b00000000000011111110000000000000,
0b00000000000011111110000000000000,
0b00000000000000111110000000000000,
0b00000000000000111110000000000000,
0b00110000011000111110000000000000,
0b11111000111100111110000000000000,
0b01111101111000111110000000000000,
0b00011111110000111110000000000000,
0b00001111100000111110000000000000,
0b00001111100000111110000000000000,
0b00011111110000111110000000000000,
0b00111101111000111110000000000000,
0b01111000111100111110000000000000,
0b00110000011000111110100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000
},
{ // k
0b01111100000000000000100000000000,
0b01111100000000000000000000000000,
0b01111100000000000000000000000000,
0b01111100000000000000000000000000,
0b01111100000000000000000000000000,
0b01111100000000000000000000000000,
0b01111100000111111000000000000000,
0b01111100001111110000000000000000,
0b01111100011111100000000000000000,
0b01111100111111000000000000000000,
0b01111101111110000000000000000000,
0b01111111111100000000000000000000,
0b01111111111000000000000000000000,
0b01111111110000000000000000000000,
0b01111111110000000000000000000000,
0b01111111111000000000000000000000,
0b01111111111100000000000000000000,
0b01111101111110000000000000000000,
0b01111100111111000000000000000000,
0b01111100011111100000000000000000,
0b01111100001111110000000000000000,
0b01111100000111111000100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000
},
{ // M
0b11111000000000111110100000000000,
0b11111000000000111110000000000000,
0b11111100000001111110000000000000,
0b11111100000001111110000000000000,
0b11111110000011111110000000000000,
0b11111110000011111110000000000000,
0b11111111000111111110000000000000,
0b11111111000111111110000000000000,
0b11111111101111111110000000000000,
0b11111111101111111110000000000000,
0b11111111111111111110000000000000,
0b11111111111111111110000000000000,
0b11111111111111111110000000000000,
0b11111111111111111110000000000000,
0b11111011111110111110000000000000,
0b11111011111110111110000000000000,
0b11111001111100111110000000000000,
0b11111001111100111110000000000000,
0b11111000111000111110000000000000,
0b11111000111000111110000000000000,
0b11111000000000111110000000000000,
0b11111000000000111110100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000
},
{ // G
0b00000111111111000000100000000000,
0b00011111111111110000000000000000,
0b00111111111111111000000000000000,
0b01111111111111111100000000000000,
0b01111110000011111100000000000000,
0b11111100000001111110000000000000,
0b11111000000000111110000000000000,
0b11111000000000111110000000000000,
0b11111000000000000000000000000000,
0b11111000000000000000000000000000,
0b11111000000000000000000000000000,
0b11111000000000000000000000000000,
0b11111000000111111110000000000000,
0b11111000000111111110000000000000,
0b11111000000111111110000000000000,
0b11111000000111111110000000000000,
0b11111100000001111110000000000000,
0b01111110000011111110000000000000,
0b01111111111111111110000000000000,
0b00111111111111111110000000000000,
0b00011111111111111110000000000000,
0b00000111111110111110100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000
},
{ // BS
0b00000000000000000000100000000000,
0b00000000001000000000000000000000,
0b00000000011000000000000000000000,
0b00000000111000000000000000000000,
0b00000001111000000000000000000000,
0b00000011111000000000000000000000,
0b00000111111111111110000000000000,
0b00001111111111111110000000000000,
0b00011111111111111110000000000000,
0b00111111111111111110000000000000,
0b01111111111111111110000000000000,
0b11111111111111111110000000000000,
0b01111111111111111110000000000000,
0b00111111111111111110000000000000,
0b00011111111111111110000000000000,
0b00001111111111111110000000000000,
0b00000111111111111110000000000000,
0b00000011111000000000000000000000,
0b00000001111000000000000000000000,
0b00000000111000000000000000000000,
0b00000000011000000000000000000000,
0b00000000001000000000100000000000,
0b00000000000000000000000000000000,
0b00000000000000000000000000000000,
},
{ // infinity = \003 { // infinity = \003
0b00000000000000000000100000000000, 0b00000000000000000000100000000000,
0b00000000000000000000000000000000, 0b00000000000000000000000000000000,

443
ui.c
View file

@ -39,7 +39,7 @@ struct {
#define BUTTON_DOWN_LONG_TICKS 10000 /* 1sec */ #define BUTTON_DOWN_LONG_TICKS 10000 /* 1sec */
#define BUTTON_DOUBLE_TICKS 5000 /* 500ms */ #define BUTTON_DOUBLE_TICKS 5000 /* 500ms */
#define BUTTON_DEBOUNCE_TICKS 10 #define BUTTON_DEBOUNCE_TICKS 200
/* lever switch assignment */ /* lever switch assignment */
#define BIT_UP1 3 #define BIT_UP1 3
@ -51,12 +51,25 @@ struct {
static uint16_t last_button = 0b0000; static uint16_t last_button = 0b0000;
static uint32_t last_button_down_ticks; static uint32_t last_button_down_ticks;
static uint8_t inhibit_until_release = FALSE;
static uint8_t last_button_event;
uint8_t operation_requested = FALSE; uint8_t operation_requested = FALSE;
int ui_status = FALSE; enum {
int selection = 1; UI_NORMAL, UI_MENU, UI_KEYPAD
};
enum {
KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_SCALE
};
uint8_t ui_mode = UI_NORMAL;
uint8_t keypad_mode;
uint8_t selection = 0;
void ui_mode_normal(void);
void ui_mode_menu(void);
void ui_mode_keypad(int _keypad_mode);
void draw_menu(void);
void erase_menu_buttons(void);
static int btn_check(void) static int btn_check(void)
@ -66,26 +79,11 @@ static int btn_check(void)
int status = 0; int status = 0;
uint32_t ticks = chVTGetSystemTime(); uint32_t ticks = chVTGetSystemTime();
if (changed & (1<<BIT_PUSH)) { if (changed & (1<<BIT_PUSH)) {
if (ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) { if (cur_button & (1<<BIT_PUSH) && ticks >= last_button_down_ticks + BUTTON_DEBOUNCE_TICKS) {
if (cur_button & (1<<BIT_PUSH)) {
// button pushed // button pushed
status |= EVT_BUTTON_SINGLE_CLICK; status |= EVT_BUTTON_SINGLE_CLICK;
}
last_button_down_ticks = ticks; last_button_down_ticks = ticks;
} else {
// button released
if (inhibit_until_release) {
status = 0;
inhibit_until_release = FALSE;
}
}
}
} else {
// button unchanged
if (cur_button & (1<<BIT_PUSH)
&& ticks >= last_button_down_ticks + BUTTON_DOWN_LONG_TICKS) {
status |= EVT_BUTTON_DOWN_LONG;
inhibit_until_release = TRUE;
}
} }
if (cur_button & (1<<BIT_UP1)) { if (cur_button & (1<<BIT_UP1)) {
@ -140,28 +138,6 @@ static int btn_wait_release(void)
} }
} }
void
ui_digit(void)
{
int count = 0;
while (TRUE) {
int status = btn_check();
if (status & EVT_BUTTON_SINGLE_CLICK)
break;
if (status & EVT_UP && uistat.digit < 7)
uistat.digit++;
if (status & EVT_DOWN && uistat.digit > 0)
uistat.digit--;
if (count++ % 4 < 2) {
//i2clcd_cmd(0x0e); // enable show-cursor flag
//i2clcd_pos(7 - uistat.digit, 1);
} else {
//i2clcd_cmd(0x0c); // disable show-cursor flag
}
chThdSleepMilliseconds(100);
}
}
// type of menu item // type of menu item
enum { enum {
@ -206,6 +182,7 @@ menu_cal_cb(int item)
static void static void
menu_caldone_cb(int item) menu_caldone_cb(int item)
{ {
(void)item;
cal_done(); cal_done();
draw_cal_status(); draw_cal_status();
menu_move_back(); menu_move_back();
@ -217,13 +194,22 @@ menu_recall_cb(int item)
if (item < 0 || item >= 5) if (item < 0 || item >= 5)
return; return;
if (caldata_recall(item) == 0) { if (caldata_recall(item) == 0) {
ui_status = FALSE; ui_mode_normal();
ui_hide();
set_sweep(freq_start, freq_stop); set_sweep(freq_start, freq_stop);
draw_cal_status(); draw_cal_status();
} }
} }
static void
menu_save_cb(int item)
{
if (item < 0 || item >= 5)
return;
if (caldata_save(item) == 0) {
ui_mode_normal();
}
}
static void static void
menu_trace_cb(int item) menu_trace_cb(int item)
{ {
@ -237,16 +223,14 @@ static void
menu_format_cb(int item) menu_format_cb(int item)
{ {
set_trace_type(uistat.current_trace, item); set_trace_type(uistat.current_trace, item);
ui_status = FALSE; ui_mode_normal();
ui_hide();
} }
static void static void
menu_format2_cb(int item) menu_format2_cb(int item)
{ {
menu_format_cb(item + 5); menu_format_cb(item + 5);
ui_status = FALSE; ui_mode_normal();
ui_hide();
} }
static void static void
@ -255,8 +239,7 @@ menu_channel_cb(int item)
if (item < 0 || item >= 2) if (item < 0 || item >= 2)
return; return;
set_trace_channel(uistat.current_trace, item); set_trace_channel(uistat.current_trace, item);
ui_status = FALSE; ui_mode_normal();
ui_hide();
} }
static void static void
@ -271,6 +254,30 @@ choose_active_marker(void)
active_marker = -1; active_marker = -1;
} }
void ui_process_keypad(void);
static void
menu_scale_cb(int item)
{
(void)item;
ui_mode_keypad(KM_SCALE);
ui_process_keypad();
}
static void
menu_stimulus_cb(int item)
{
switch (item) {
case 0:
case 1:
case 2:
case 3:
ui_mode_keypad(item);
ui_process_keypad();
break;
}
}
static void static void
menu_marker_cb(int item) menu_marker_cb(int item)
{ {
@ -286,8 +293,7 @@ menu_marker_cb(int item)
} }
if (active_marker >= 0) if (active_marker >= 0)
redraw_marker(active_marker, TRUE); redraw_marker(active_marker, TRUE);
ui_status = FALSE; ui_mode_normal();
ui_hide();
} }
typedef struct { typedef struct {
@ -337,8 +343,8 @@ const menuitem_t menu_format[] = {
}; };
const menuitem_t menu_channel[] = { const menuitem_t menu_channel[] = {
{ MT_CALLBACK, "0", menu_channel_cb }, { MT_CALLBACK, "CH0", menu_channel_cb },
{ MT_CALLBACK, "1", menu_channel_cb }, { MT_CALLBACK, "CH1", menu_channel_cb },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -346,12 +352,21 @@ const menuitem_t menu_channel[] = {
const menuitem_t menu_display[] = { const menuitem_t menu_display[] = {
{ MT_SUBMENU, "TRACE", menu_trace }, { MT_SUBMENU, "TRACE", menu_trace },
{ MT_SUBMENU, "FORMAT", menu_format }, { MT_SUBMENU, "FORMAT", menu_format },
{ MT_SUBMENU, "SCALE", menu_format }, { MT_CALLBACK, "SCALE", menu_scale_cb },
{ MT_SUBMENU, "CHANNEL", menu_channel }, { MT_SUBMENU, "CHANNEL", menu_channel },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
const menuitem_t menu_stimulus[] = {
{ MT_CALLBACK, "START", menu_stimulus_cb },
{ MT_CALLBACK, "STOP", menu_stimulus_cb },
{ MT_CALLBACK, "CENTER", menu_stimulus_cb },
{ MT_CALLBACK, "SPAN", menu_stimulus_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_marker[] = { const menuitem_t menu_marker[] = {
{ MT_CALLBACK, "1", menu_marker_cb }, { MT_CALLBACK, "1", menu_marker_cb },
{ MT_CALLBACK, "2", menu_marker_cb }, { MT_CALLBACK, "2", menu_marker_cb },
@ -371,11 +386,23 @@ const menuitem_t menu_recall[] = {
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
const menuitem_t menu_save[] = {
{ MT_CALLBACK, "0", menu_save_cb },
{ MT_CALLBACK, "1", menu_save_cb },
{ MT_CALLBACK, "2", menu_save_cb },
{ MT_CALLBACK, "3", menu_save_cb },
{ MT_CALLBACK, "4", menu_save_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_top[] = { const menuitem_t menu_top[] = {
{ MT_SUBMENU, "CAL", menu_cal },
{ MT_SUBMENU, "DISPLAY", menu_display }, { MT_SUBMENU, "DISPLAY", menu_display },
{ MT_SUBMENU, "MARKER", menu_marker }, { MT_SUBMENU, "MARKER", menu_marker },
{ MT_SUBMENU, "STIMULUS", menu_stimulus },
{ MT_SUBMENU, "CAL", menu_cal },
{ MT_SUBMENU, "RECALL", menu_recall }, { MT_SUBMENU, "RECALL", menu_recall },
{ MT_SUBMENU, "SAVE", menu_save },
{ MT_CLOSE, "CLOSE", NULL }, { MT_CLOSE, "CLOSE", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -403,7 +430,18 @@ static void menu_move_back(void)
return; return;
menu_current_level--; menu_current_level--;
ensure_selection(); ensure_selection();
erase_buttons(); erase_menu_buttons();
draw_menu();
}
static void menu_push_submenu(const menuitem_t *submenu)
{
if (menu_current_level < MENU_STACK_DEPTH_MAX-1)
menu_current_level++;
menu_stack[menu_current_level] = submenu;
ensure_selection();
erase_menu_buttons();
draw_menu();
} }
static void menu_move_top(void) static void menu_move_top(void)
@ -412,20 +450,20 @@ static void menu_move_top(void)
return; return;
menu_current_level = 0; menu_current_level = 0;
ensure_selection(); ensure_selection();
erase_buttons(); erase_menu_buttons();
draw_menu();
} }
void menu_invoke(int selection) void menu_invoke(int item)
{ {
const menuitem_t *menu = menu_stack[menu_current_level]; const menuitem_t *menu = menu_stack[menu_current_level];
menu = &menu[selection]; menu = &menu[item];
switch (menu->type) { switch (menu->type) {
case MT_NONE: case MT_NONE:
case MT_BLANK: case MT_BLANK:
case MT_CLOSE: case MT_CLOSE:
ui_status = FALSE; ui_mode_normal();
ui_hide();
break; break;
case MT_CANCEL: case MT_CANCEL:
@ -436,21 +474,93 @@ void menu_invoke(int selection)
menuaction_cb_t cb = (menuaction_cb_t)menu->reference; menuaction_cb_t cb = (menuaction_cb_t)menu->reference;
if (cb == NULL) if (cb == NULL)
return; return;
(*cb)(selection); (*cb)(item);
break; break;
} }
case MT_SUBMENU: case MT_SUBMENU:
if (menu_current_level >= 3) menu_push_submenu((const menuitem_t*)menu->reference);
break;
menu_current_level++;
menu_stack[menu_current_level] = (const menuitem_t*)menu->reference;
erase_buttons();
selection = 0;
break; break;
} }
} }
#define KP_X(x) (48*(x) + 2 + (320-64-192))
#define KP_Y(y) (48*(y) + 2)
#define KP_PERIOD 10
#define KP_MINUS 11
#define KP_X1 12
#define KP_K 13
#define KP_M 14
#define KP_G 15
#define KP_BS 16
#define KP_INF 17
#define KP_DB 18
const struct {
uint16_t x, y;
uint8_t c;
} keypads[] = {
{ KP_X(1), KP_Y(3), KP_PERIOD },
{ KP_X(0), KP_Y(3), 0 },
{ KP_X(0), KP_Y(2), 1 },
{ KP_X(1), KP_Y(2), 2 },
{ KP_X(2), KP_Y(2), 3 },
{ KP_X(0), KP_Y(1), 4 },
{ KP_X(1), KP_Y(1), 5 },
{ KP_X(2), KP_Y(1), 6 },
{ KP_X(0), KP_Y(0), 7 },
{ KP_X(1), KP_Y(0), 8 },
{ KP_X(2), KP_Y(0), 9 },
//{ KP_X(3), KP_Y(0), KP_G },
{ KP_X(3), KP_Y(1), KP_M },
//{ KP_X(3), KP_Y(2), KP_K },
{ KP_X(3), KP_Y(3), KP_X1 },
{ KP_X(2), KP_Y(3), KP_BS },
{ 0, 0, 0 }
};
void
draw_keypad(void)
{
int i = 0;
while (keypads[i].x) {
uint16_t bg = 0xffff;
if (i == selection)
bg = 0x7777;
ili9341_fill(keypads[i].x, keypads[i].y, 44, 44, bg);
ili9341_drawfont(keypads[i].c, &NF20x24, keypads[i].x+12, keypads[i].y+10, 0x0000, bg);
i++;
}
}
const char *keypad_mode_label[] = {
"START", "STOP", "CENTER", "SPAN", "SCALE"
};
void
draw_numeric_input(const char *buf)
{
int i = 0;
ili9341_fill(0, 208, 320, 32, 0xffff);
ili9341_drawstring_5x7(keypad_mode_label[keypad_mode], 10, 220, 0x0000, 0xffff);
while (buf[i] && i < 10) {
int c;
if (buf[i] == '.')
c = KP_PERIOD;
else if (buf[i] == '-')
c = KP_MINUS;
else if (buf[i] >= '0' && buf[i] <= '9')
c = buf[i] - '0';
else {
i++;
continue;
}
ili9341_drawfont(c, &NF20x24, i * 20 + 64, 208+4, 0x0000, 0xffff);
i++;
}
}
void void
draw_menu_buttons(const menuitem_t *menu) draw_menu_buttons(const menuitem_t *menu)
@ -463,90 +573,75 @@ draw_menu_buttons(const menuitem_t *menu)
continue; continue;
int y = 32*i; int y = 32*i;
uint16_t bg = 0xffff; uint16_t bg = 0xffff;
if (i == selection) // focus only in MENU mode but not in KEYPAD mode
if (ui_mode == UI_MENU && i == selection)
bg = 0x7777; bg = 0x7777;
ili9341_fill(320-60, y, 60, 30, bg); ili9341_fill(320-60, y, 60, 30, bg);
ili9341_drawstring_5x7(menu[i].label, 320-54, y+12, 0x0000, bg); ili9341_drawstring_5x7(menu[i].label, 320-54, y+12, 0x0000, bg);
} }
} }
const char *menu_items[] = {
"OPEN", "SHORT", "LOAD", "ISOLN", "THRU", NULL, "DONE"
};
void void
draw_buttons(void) draw_menu(void)
{ {
#if 1
draw_menu_buttons(menu_stack[menu_current_level]); draw_menu_buttons(menu_stack[menu_current_level]);
#else
int i = 0;
for (i = 0; i < 7; i++) {
int y = 32*i;
uint16_t bg = 0xffff;
if (i == selection)
bg = 0x7777;
if (menu_items[i] != NULL) {
ili9341_fill(320-60, y, 60, 30, bg);
ili9341_drawstring_5x7(menu_items[i], 320-54, y+12, 0x0000, bg);
}
}
#endif
} }
void void
erase_buttons(void) erase_menu_buttons(void)
{ {
uint16_t bg = 0; uint16_t bg = 0;
ili9341_fill(320-60, 0, 60, 32*7, bg); ili9341_fill(320-60, 0, 60, 32*7, bg);
} }
void void
ui_show(void) ui_mode_menu(void)
{ {
if (ui_mode == UI_MENU)
return;
ui_mode = UI_MENU;
area_width = WIDTH - (64-14-4); area_width = WIDTH - (64-14-4);
area_height = HEIGHT; area_height = HEIGHT;
draw_buttons(); ensure_selection();
draw_menu();
} }
void void
ui_hide(void) ui_mode_keypad(int _keypad_mode)
{ {
if (ui_mode == UI_KEYPAD)
return;
ui_mode = UI_KEYPAD;
area_width = WIDTH - (64-14-4);
area_height = HEIGHT;
draw_menu();
draw_keypad();
keypad_mode = _keypad_mode;
draw_numeric_input("");
}
void
ui_mode_normal(void)
{
if (ui_mode == UI_NORMAL)
return;
ui_mode = UI_NORMAL;
area_width = WIDTH; area_width = WIDTH;
area_height = HEIGHT; area_height = HEIGHT;
erase_buttons(); erase_menu_buttons();
force_draw_cells(); force_draw_cells();
} }
void void
ui_process(void) ui_process_normal(void)
{ {
if (!operation_requested)
return;
int status = btn_check(); int status = btn_check();
int n;
if (status != 0) { if (status != 0) {
if (status & EVT_BUTTON_SINGLE_CLICK) { if (status & EVT_BUTTON_SINGLE_CLICK) {
if (ui_status) { ui_mode_menu();
menu_invoke(selection);
} else {
ui_status = TRUE;
}
if (ui_status)
ui_show();
} else {
if (ui_status) {
if (status & EVT_UP
&& menu_stack[menu_current_level][selection+1].type != MT_NONE) {
selection++;
draw_buttons();
}
if (status & EVT_DOWN
&& selection > 0) {
selection--;
draw_buttons();
}
} else { } else {
do { do {
if (active_marker >= 0 && markers[active_marker].enabled) { if (active_marker >= 0 && markers[active_marker].enabled) {
@ -566,6 +661,114 @@ ui_process(void)
} }
} }
} }
void
ui_process_menu(void)
{
int status = btn_check();
if (status != 0) {
if (status & EVT_BUTTON_SINGLE_CLICK) {
menu_invoke(selection);
} else {
if (status & EVT_UP
&& menu_stack[menu_current_level][selection+1].type != MT_NONE) {
selection++;
draw_menu();
}
if (status & EVT_DOWN
&& selection > 0) {
selection--;
draw_menu();
}
}
}
}
void
ui_process_keypad(void)
{
int status = btn_check();
char buf[15];
char *p = buf;
float scale;
while (TRUE) {
if (status & EVT_UP) {
selection--;
selection %= 16;
draw_keypad();
}
if (status & EVT_DOWN) {
selection++;
selection %= 16;
draw_keypad();
}
if (status == EVT_BUTTON_SINGLE_CLICK) {
int c = keypads[selection].c;
if (c >= KP_X1 && c <= KP_G) {
int n = c - KP_X1;
scale = 1;
while (n-- > 0)
scale *= 1000;
break;
} else if (c <= 9)
*p++ = '0' + c;
else if (c == KP_PERIOD)
*p++ = '.';
else if (c == KP_BS) {
if (p == buf) {
goto cancel;
}
--p;
}
*p = '\0';
draw_numeric_input(buf);
}
status = btn_check();
}
float value = my_atof(buf) * scale;
switch (keypad_mode) {
case KM_START:
set_sweep_frequency(ST_START, value);
break;
case KM_STOP:
set_sweep_frequency(ST_STOP, value);
break;
case KM_CENTER:
set_sweep_frequency(ST_CENTER, value);
break;
case KM_SPAN:
set_sweep_frequency(ST_SPAN, value);
break;
case KM_SCALE:
set_trace_scale(uistat.current_trace, value);
break;
}
cancel:
ui_mode_normal();
redraw();
force_set_markmap();
draw_cell_all();
}
void
ui_process(void)
{
if (!operation_requested)
return;
switch (ui_mode) {
case UI_NORMAL:
ui_process_normal();
break;
case UI_MENU:
ui_process_menu();
break;
case UI_KEYPAD:
ui_process_keypad();
break;
}
operation_requested = FALSE; operation_requested = FALSE;
} }