summaryrefslogtreecommitdiffstats
path: root/movement/movement.c
diff options
context:
space:
mode:
authorjoeycastillo <joeycastillo@utexas.edu>2022-08-03 11:56:52 -0600
committerGitHub <noreply@github.com>2022-08-03 11:56:52 -0600
commite790a025787e0e1aa59b98b95e194cf4318d1578 (patch)
tree149bd53bbd46ebddd31957cc827a7c40ccf6f1a0 /movement/movement.c
parent6d87f5a6268a9a516d8c577dfd71b39a5bfc384a (diff)
parentbcd3b666848214a735f37a5a4f08b157ba7bb3a1 (diff)
downloadSensor-Watch-e790a025787e0e1aa59b98b95e194cf4318d1578.tar.gz
Sensor-Watch-e790a025787e0e1aa59b98b95e194cf4318d1578.tar.bz2
Sensor-Watch-e790a025787e0e1aa59b98b95e194cf4318d1578.zip
Merge pull request #80 from joeycastillo/lfs
Movement: add a lil file system with lfs
Diffstat (limited to 'movement/movement.c')
-rw-r--r--movement/movement.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/movement/movement.c b/movement/movement.c
index 361a7aa1..d79142ec 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
@@ -259,6 +263,8 @@ void app_init(void) {
movement_state.next_available_backup_register = 4;
_movement_reset_inactivity_countdown();
+ filesystem_init();
+
#if __EMSCRIPTEN__
int32_t time_zone_offset = EM_ASM_INT({
return -new Date().getTimezoneOffset();
@@ -442,6 +448,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)) filesystem_process_command(line);
+ }
+
event.subsecond = 0;
return can_sleep && (movement_state.light_ticks == -1) && !movement_state.is_buzzing;