diff --git a/FluxEngine.cydsn/FluxEngine.cydwr b/FluxEngine.cydsn/FluxEngine.cydwr index 4a61eb7d..a7cf4d54 100644 --- a/FluxEngine.cydsn/FluxEngine.cydwr +++ b/FluxEngine.cydsn/FluxEngine.cydwr @@ -3611,12 +3611,12 @@ - + - + @@ -3626,7 +3626,7 @@ - + @@ -3678,17 +3678,17 @@ - + - + - + @@ -3698,12 +3698,12 @@ - + - + @@ -3726,17 +3726,17 @@ - + - + - + @@ -3746,12 +3746,12 @@ - + - + @@ -3761,12 +3761,12 @@ - + - + @@ -3779,7 +3779,7 @@ - + diff --git a/FluxEngine.cydsn/main.c b/FluxEngine.cydsn/main.c index 2748b47b..171efdef 100644 --- a/FluxEngine.cydsn/main.c +++ b/FluxEngine.cydsn/main.c @@ -181,6 +181,14 @@ static void cmd_seek(struct seek_frame* f) send_reply(&r); } +static void cmd_recalibrate(void) +{ + homed = false; + seek_to(0); + DECLARE_REPLY_FRAME(struct any_frame, F_FRAME_RECALIBRATE_REPLY); + send_reply(&r); +} + static void cmd_measure_speed(struct any_frame* f) { start_motor(); @@ -567,6 +575,10 @@ static void handle_command(void) case F_FRAME_ERASE_CMD: cmd_erase((struct erase_frame*) f); break; + + case F_FRAME_RECALIBRATE_CMD: + cmd_recalibrate(); + break; default: send_error(F_ERROR_BAD_COMMAND); diff --git a/lib/reader.cc b/lib/reader.cc index e47755fa..a7140c25 100644 --- a/lib/reader.cc +++ b/lib/reader.cc @@ -189,7 +189,10 @@ void readDiskCommand( std::cout << "giving up" << std::endl << " "; else + { std::cout << retry << " retries remaining" << std::endl; + usbRecalibrate(); + } } int size = 0; diff --git a/lib/usb.cc b/lib/usb.cc index 205daedc..a6cb6e1c 100644 --- a/lib/usb.cc +++ b/lib/usb.cc @@ -114,6 +114,17 @@ void usbSeek(int track) await_reply(F_FRAME_SEEK_REPLY); } +void usbRecalibrate() +{ + usb_init(); + + struct any_frame f = { + { .type = F_FRAME_RECALIBRATE_CMD, .size = sizeof(f) }, + }; + usb_cmd_send(&f, f.f.size); + await_reply(F_FRAME_RECALIBRATE_REPLY); +} + nanoseconds_t usbGetRotationalPeriod(void) { usb_init(); diff --git a/lib/usb.h b/lib/usb.h index 252748b5..e165a355 100644 --- a/lib/usb.h +++ b/lib/usb.h @@ -4,6 +4,7 @@ class Fluxmap; extern int usbGetVersion(); +extern void usbRecalibrate(); extern void usbSeek(int track); extern nanoseconds_t usbGetRotationalPeriod(); extern void usbTestBulkTransport(); diff --git a/protocol.h b/protocol.h index 16bc5b28..c5283a62 100644 --- a/protocol.h +++ b/protocol.h @@ -54,6 +54,8 @@ enum F_FRAME_WRITE_REPLY, /* any_frame */ F_FRAME_ERASE_CMD, /* erase_frame */ F_FRAME_ERASE_REPLY, /* any_frame */ + F_FRAME_RECALIBRATE_CMD, /* any_frame */ + F_FRAME_RECALIBRATE_REPLY, /* any_frame */ }; enum