+do_save(struct cc_usb *usb)
+{
+ int ret = 0;
+
+ printf("Saving calibration to device\n");
+ cc_usb_printf(usb, "c w\nv\n");
+ for (;;) {
+ char line[512];
+
+ cc_usb_getline(usb, line, sizeof (line));
+ if (strstr(line, "Nothing to save"))
+ ret = 1;
+ if (strstr(line, "Saved"))
+ ret = 1;
+ if (strstr(line, "software-version"))
+ break;
+ }
+ if (!ret) {
+ printf("Calibration save failed\n");
+ }
+ return ret;
+}
+
+int
+do_output(char *output, int cur_cal)
+{
+ printf ("Saving calibration value to file \"%s\"\n", output);
+
+ FILE *out = fopen(output, "w");
+ int ret = 1;
+
+ if (!out) {
+ perror(output);
+ return 0;
+ }
+
+ if (fprintf(out, "%d\n", cur_cal) < 0) {
+ perror("fprintf");
+ ret = 0;
+ }
+ if (fflush(out) != 0) {
+ perror("fflush");
+ ret = 0;
+ }
+ if (fclose(out) != 0) {
+ perror("fclose");
+ ret = 0;
+ }
+ return ret;
+}
+
+int
+do_cal(char *tty, int save, char *output)
+{