update marker position on sweep frequency change

This commit is contained in:
TT 2017-09-17 20:19:12 +09:00
parent a20f3770da
commit 5a441edc6b
4 changed files with 56 additions and 11 deletions

View file

@ -27,7 +27,7 @@ Otherwise, use toolchains included inside LPCxpresso. Like this.
$ PATH=$PATH:/Applications/lpcxpresso_7.8.0_426/lpcxpresso/tools/bin $ PATH=$PATH:/Applications/lpcxpresso_7.8.0_426/lpcxpresso/tools/bin
## Build the firmware ## Build firmware
Fetch ChibiOS submodule into tree. Fetch ChibiOS submodule into tree.
@ -38,7 +38,7 @@ Just make in the top directory.
$ make $ make
## Burn the firmware ## Flash firmware
Boot MCU in DFU mode. To do this, jumper BOOT0 pin at powering device. Boot MCU in DFU mode. To do this, jumper BOOT0 pin at powering device.
Then, burn firmware using dfu-util via USB. Then, burn firmware using dfu-util via USB.

41
main.c
View file

@ -35,6 +35,7 @@
static void apply_error_term(void); static void apply_error_term(void);
static void apply_error_term_at(int i); static void apply_error_term_at(int i);
static void cal_interpolate(int s);
void sweep(void); void sweep(void);
@ -400,7 +401,7 @@ properties_t current_props = {
{ 1, TRC_PHASE, 1, 0, 1.0, 4.0 } { 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
}, },
/* markers[4] */ { /* markers[4] */ {
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 } { 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
}, },
/* active_marker */ 0, /* active_marker */ 0,
/* checksum */ 0 /* checksum */ 0
@ -495,6 +496,37 @@ void sweep(void)
// apply_error_term(); // apply_error_term();
} }
static void
update_marker_index(void)
{
int m;
int i;
for (m = 0; m < 4; m++) {
if (!markers[m].enabled)
continue;
uint32_t f = markers[m].frequency;
if (f < frequencies[0]) {
markers[m].index = 0;
markers[m].frequency = frequencies[0];
} else if (f >= frequencies[sweep_points-1]) {
markers[m].index = sweep_points-1;
markers[m].frequency = frequencies[sweep_points-1];
} else {
for (i = 0; i < sweep_points-1; i++) {
if (frequencies[i] <= f && f < frequencies[i+1]) {
uint32_t mid = (frequencies[i] + frequencies[i+1])/2;
if (f < mid) {
markers[m].index = i;
} else {
markers[m].index = i + 1;
}
break;
}
}
}
}
}
void void
update_frequencies(void) update_frequencies(void)
{ {
@ -517,6 +549,8 @@ update_frequencies(void)
if (cal_auto_interpolate) if (cal_auto_interpolate)
cal_interpolate(0); cal_interpolate(0);
update_marker_index();
frequency_updated = TRUE; frequency_updated = TRUE;
// set grid layout // set grid layout
update_grid(); update_grid();
@ -1287,7 +1321,7 @@ static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
if (argc == 0) { if (argc == 0) {
for (t = 0; t < 4; t++) { for (t = 0; t < 4; t++) {
if (markers[t].enabled) { if (markers[t].enabled) {
chprintf(chp, "%d %d\r\n", t+1, markers[t].index); chprintf(chp, "%d %d %d\r\n", t+1, markers[t].index, markers[t].frequency);
} }
} }
return; return;
@ -1303,7 +1337,7 @@ static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
if (t < 0 || t >= 4) if (t < 0 || t >= 4)
goto usage; goto usage;
if (argc == 1) { if (argc == 1) {
chprintf(chp, "%d %d\r\n", t+1, markers[t].index); chprintf(chp, "%d %d %d\r\n", t+1, markers[t].index, frequency);
active_marker = t; active_marker = t;
markers[t].enabled = TRUE; markers[t].enabled = TRUE;
return; return;
@ -1320,6 +1354,7 @@ static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
markers[t].enabled = TRUE; markers[t].enabled = TRUE;
int index = atoi(argv[1]); int index = atoi(argv[1]);
markers[t].index = index; markers[t].index = index;
markers[t].frequency = frequencies[index];
active_marker = t; active_marker = t;
} }
} }

View file

@ -195,9 +195,9 @@ void set_trace_refpos(int t, float refpos);
// marker // marker
typedef struct { typedef struct {
int enabled; int8_t enabled;
//uint32_t frequency; int16_t index;
int index; uint32_t frequency;
} marker_t; } marker_t;
//extern marker_t markers[4]; //extern marker_t markers[4];

14
ui.c
View file

@ -645,6 +645,7 @@ menu_marker_op_cb(int item)
break; break;
} }
ui_mode_normal(); ui_mode_normal();
draw_cal_status();
//redraw_all(); //redraw_all();
} }
@ -702,7 +703,6 @@ const menuitem_t menu_cal[] = {
{ MT_SUBMENU, "CALIBRATE", menu_calop }, { MT_SUBMENU, "CALIBRATE", menu_calop },
{ MT_CALLBACK, "RESET", menu_cal2_cb }, { MT_CALLBACK, "RESET", menu_cal2_cb },
{ MT_CALLBACK, "CORRECTION", menu_cal2_cb }, { MT_CALLBACK, "CORRECTION", menu_cal2_cb },
{ MT_SUBMENU, "SAVE", menu_save },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -805,6 +805,12 @@ const menuitem_t menu_recall[] = {
{ MT_CALLBACK, "RECALL 2", menu_recall_cb }, { MT_CALLBACK, "RECALL 2", menu_recall_cb },
{ MT_CALLBACK, "RECALL 3", menu_recall_cb }, { MT_CALLBACK, "RECALL 3", menu_recall_cb },
{ MT_CALLBACK, "RECALL 4", menu_recall_cb }, { MT_CALLBACK, "RECALL 4", menu_recall_cb },
{ MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
const menuitem_t menu_recall_save[] = {
{ MT_SUBMENU, "RECALL", menu_recall },
{ MT_SUBMENU, "SAVE", menu_save }, { MT_SUBMENU, "SAVE", menu_save },
{ MT_CANCEL, "BACK", NULL }, { MT_CANCEL, "BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
@ -815,7 +821,7 @@ const menuitem_t menu_top[] = {
{ MT_SUBMENU, "MARKER", menu_marker }, { MT_SUBMENU, "MARKER", menu_marker },
{ MT_SUBMENU, "STIMULUS", menu_stimulus }, { MT_SUBMENU, "STIMULUS", menu_stimulus },
{ MT_SUBMENU, "CAL", menu_cal }, { MT_SUBMENU, "CAL", menu_cal },
{ MT_SUBMENU, "\2RECALL\0/SAVE", menu_recall }, { MT_SUBMENU, "\2RECALL\0SAVE", menu_recall_save },
{ MT_CLOSE, "CLOSE", NULL }, { MT_CLOSE, "CLOSE", NULL },
{ MT_NONE, NULL, NULL } // sentinel { MT_NONE, NULL, NULL } // sentinel
}; };
@ -1176,10 +1182,12 @@ ui_process_normal(void)
if (active_marker >= 0 && markers[active_marker].enabled) { if (active_marker >= 0 && markers[active_marker].enabled) {
if ((status & EVT_DOWN) && markers[active_marker].index > 0) { if ((status & EVT_DOWN) && markers[active_marker].index > 0) {
markers[active_marker].index--; markers[active_marker].index--;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE); redraw_marker(active_marker, FALSE);
} }
if ((status & EVT_UP) && markers[active_marker].index < 100) { if ((status & EVT_UP) && markers[active_marker].index < 100) {
markers[active_marker].index++; markers[active_marker].index++;
markers[active_marker].frequency = frequencies[markers[active_marker].index];
redraw_marker(active_marker, FALSE); redraw_marker(active_marker, FALSE);
} }
} }
@ -1384,6 +1392,7 @@ void drag_marker(int t, int m)
index = search_nearest_index(touch_x, touch_y, t); index = search_nearest_index(touch_x, touch_y, t);
if (index >= 0) { if (index >= 0) {
markers[m].index = index; markers[m].index = index;
markers[m].frequency = frequencies[index];
redraw_marker(m, TRUE); redraw_marker(m, TRUE);
} }
@ -1419,6 +1428,7 @@ touch_pickup_marker(void)
if (sq_distance(x - touch_x, y - touch_y) < 400) { if (sq_distance(x - touch_x, y - touch_y) < 400) {
if (active_marker != m) { if (active_marker != m) {
previous_marker = active_marker;
active_marker = m; active_marker = m;
redraw_marker(active_marker, TRUE); redraw_marker(active_marker, TRUE);
} }