summaryrefslogtreecommitdiffstats
path: root/main/fix-serial.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/fix-serial.patch')
-rw-r--r--main/fix-serial.patch97
1 files changed, 97 insertions, 0 deletions
diff --git a/main/fix-serial.patch b/main/fix-serial.patch
new file mode 100644
index 0000000..80b11c5
--- /dev/null
+++ b/main/fix-serial.patch
@@ -0,0 +1,97 @@
+diff --git a/movement/filesystem.c b/movement/filesystem.c
+index 97e3545..d3c2f83 100644
+--- a/movement/filesystem.c
++++ b/movement/filesystem.c
+@@ -275,6 +275,10 @@ void filesystem_process_command(char *line) {
+ filesystem_append_file(filename, "\n", 1);
+ }
+ free(text);
++ } else if (strcmp(command, "format") == 0) {
++ lfs_unmount(&lfs);
++ lfs_format(&lfs, &cfg);
++ lfs_mount(&lfs, &cfg);
+ } else {
+ printf("%s: command not found\n", command);
+ }
+diff --git a/movement/movement.c b/movement/movement.c
+index 825f130..c7066f7 100644
+--- a/movement/movement.c
++++ b/movement/movement.c
+@@ -547,7 +547,29 @@ bool app_loop(void) {
+ tx = "";
+ });
+ #else
+- read(0, line, 256);
++#if 0
++ read(0, &line[ll], sizeof(line)-ll);
++#else
++ // JMM yuck just yuck, we do our best to patch this mess up
++ {
++ static char buf[sizeof(line) - 1];
++ static int bl; //again really signed?
++ int red;
++
++ red = read(0, &buf[bl], sizeof(buf) - 1);
++
++ if (red > 0) {
++ write(0, &buf[bl], red);
++ bl += red;
++ if (buf[bl-1] == '\r') {
++ for (red = 0; red < bl; ++red)
++ line[red] = buf[red] == '\r' ? '\n' : buf[red];
++ //memcpy(line,buf,bl-1);
++ bl = 0;
++ }
++ }
++ }
++#endif
+ #endif
+ if (strlen(line)) filesystem_process_command(line);
+ }
+diff --git a/watch-library/hardware/watch/watch_private.c b/watch-library/hardware/watch/watch_private.c
+index cd607b8..5081fdb 100644
+--- a/watch-library/hardware/watch/watch_private.c
++++ b/watch-library/hardware/watch/watch_private.c
+@@ -246,9 +246,18 @@ void _watch_enable_usb(void) {
+ // this function ends up getting called by printf to log stuff to the USB console.
+ int _write(int file, char *ptr, int len) {
+ (void)file;
++ int i; //it's 2023 boys and girls you can use size_t and ssize_t
+ if (hri_usbdevice_get_CTRLA_ENABLE_bit(USB)) {
+- tud_cdc_n_write(0, (void const*)ptr, len);
+- tud_cdc_n_write_flush(0);
++ //tud_cdc_n_write(0, (void const*)ptr, len);
++ for (i = 0; i < len; ++i)
++ {
++ if (ptr[i]=='\n') {
++ tud_cdc_n_write(0, (void const*)"\r\n", 2);
++ } else {
++ tud_cdc_n_write(0, (void const*)&ptr[i], 1);
++ }
++ tud_cdc_n_write_flush(0);
++ }
+ return len;
+ }
+
+@@ -262,6 +271,8 @@ int _read(int file, char *ptr, int len) {
+ int actual_length = strlen(buf);
+ if (actual_length) {
+ memcpy(ptr, buf, min(len, actual_length));
++ //JMM yuckity yuck yuck
++ buf[0] = 0;
+ return actual_length;
+ }
+ return 0;
+diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h
+index 790f9a1..b280ae6 100644
+--- a/watch-library/shared/watch/watch.h
++++ b/watch-library/shared/watch/watch.h
+@@ -95,5 +95,6 @@ void watch_reset_to_bootloader(void);
+ * @return The number of bytes read, or zero if no bytes were read.
+ */
+ int read(int file, char *ptr, int len);
++int write(int file, char *ptr, int len);
+
+-#endif /* WATCH_H_ */
+\ No newline at end of file
++#endif /* WATCH_H_ */