summaryrefslogtreecommitdiffstats
path: root/movement/movement.c
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-05-09 12:55:58 -0400
committerJoey Castillo <joeycastillo@utexas.edu>2022-05-09 13:00:15 -0400
commit22b1ac0283a6aed800ea86960305284199747cdc (patch)
tree4756b7024263098ea9f43ef42df15566f296304e /movement/movement.c
parent21ee056e26c3e158cf56f8577169f86b8d577a65 (diff)
downloadSensor-Watch-22b1ac0283a6aed800ea86960305284199747cdc.tar.gz
Sensor-Watch-22b1ac0283a6aed800ea86960305284199747cdc.tar.bz2
Sensor-Watch-22b1ac0283a6aed800ea86960305284199747cdc.zip
simulator: add USB serial input field
Diffstat (limited to 'movement/movement.c')
-rw-r--r--movement/movement.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/movement/movement.c b/movement/movement.c
index 4a5bc04e..72c087e9 100644
--- a/movement/movement.c
+++ b/movement/movement.c
@@ -25,7 +25,11 @@
#include <stdio.h>
#include <string.h>
#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
#include "watch.h"
+#include "filesystem.h"
#include "movement.h"
#ifndef MOVEMENT_FIRMWARE
@@ -423,6 +427,32 @@ bool app_loop(void) {
}
}
+ // if we are plugged into USB, handle the file browser tasks
+ if (watch_is_usb_enabled()) {
+ char line[256] = {0};
+#if __EMSCRIPTEN__
+ // This is a terrible hack; ideally this should be handled deeper in the watch library.
+ // Alas, emscripten treats read() as something that should pop up an input box, so I
+ // wasn't able to implement this over there. I sense that this relates to read() being
+ // the wrong way to read data from USB (like we should be using fgets or something), but
+ // until I untangle that, this will have to do.
+ char *received_data = (char*)EM_ASM_INT({
+ var len = lengthBytesUTF8(tx) + 1;
+ var s = _malloc(len);
+ stringToUTF8(tx, s, len);
+ return s;
+ });
+ memcpy(line, received_data, min(255, strlen(received_data)));
+ free(received_data);
+ EM_ASM({
+ tx = "";
+ });
+#else
+ read(0, line, 256);
+#endif
+ if (strlen(line)) printf(line);
+ }
+
event.subsecond = 0;
return can_sleep && (movement_state.light_ticks == -1) && !movement_state.is_buzzing;