]> git.earman.xyz Git - sensor-watch.git/commitdiff
add file browser to movement, remove old app
authorJoey Castillo <joeycastillo@utexas.edu>
Mon, 9 May 2022 17:01:12 +0000 (13:01 -0400)
committerJoey Castillo <joeycastillo@utexas.edu>
Mon, 9 May 2022 17:05:37 +0000 (13:05 -0400)
apps/filesystem-browser/Makefile [deleted file]
apps/filesystem-browser/browser.c [deleted file]
movement/filesystem.c
movement/movement.c
watch-library/simulator/main.c

diff --git a/apps/filesystem-browser/Makefile b/apps/filesystem-browser/Makefile
deleted file mode 100755 (executable)
index a37c98d..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-TOP = ../..
-include $(TOP)/make.mk
-
-INCLUDES += \
-  -I$(TOP)/littlefs/ \
-  -I./
-
-SRCS += \
-  $(TOP)/littlefs/lfs.c \
-  $(TOP)/littlefs/lfs_util.c \
-  ./browser.c
-
-include $(TOP)/rules.mk
diff --git a/apps/filesystem-browser/browser.c b/apps/filesystem-browser/browser.c
deleted file mode 100644 (file)
index daa7786..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <peripheral_clk_config.h>
-#include "watch.h"
-#include "lfs.h"
-#include "hpl_flash.h"
-
-int lfs_storage_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size);
-int lfs_storage_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size);
-int lfs_storage_erase(const struct lfs_config *cfg, lfs_block_t block);
-int lfs_storage_sync(const struct lfs_config *cfg);
-
-int lfs_storage_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) {
-    (void) cfg;
-    return !watch_storage_read(block, off, (void *)buffer, size);
-}
-
-int lfs_storage_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
-    (void) cfg;
-    return !watch_storage_write(block, off, (void *)buffer, size);
-}
-
-int lfs_storage_erase(const struct lfs_config *cfg, lfs_block_t block) {
-    (void) cfg;
-    return !watch_storage_erase(block);
-}
-
-int lfs_storage_sync(const struct lfs_config *cfg) {
-    (void) cfg;
-    return !watch_storage_sync();
-}
-
-const struct lfs_config cfg = {
-    // block device operations
-    .read  = lfs_storage_read,
-    .prog  = lfs_storage_prog,
-    .erase = lfs_storage_erase,
-    .sync  = lfs_storage_sync,
-
-    // block device configuration
-    .read_size = 16,
-    .prog_size = NVMCTRL_PAGE_SIZE,
-    .block_size = NVMCTRL_ROW_SIZE,
-    .block_count = NVMCTRL_RWWEE_PAGES / 4,
-    .cache_size = NVMCTRL_PAGE_SIZE,
-    .lookahead_size = 16,
-    .block_cycles = 100,
-};
-
-lfs_t lfs;
-lfs_file_t file;
-
-static int _traverse_df_cb(void *p, lfs_block_t block) {
-    (void) block;
-       uint32_t *nb = p;
-       *nb += 1;
-       return 0;
-}
-
-static int get_free_space(void){
-       int err;
-
-       uint32_t free_blocks = 0;
-       err = lfs_fs_traverse(&lfs, _traverse_df_cb, &free_blocks);
-       if(err < 0){
-               return err;
-       }
-
-       uint32_t available = cfg.block_count * cfg.block_size - free_blocks * cfg.block_size;
-
-       return available;
-}
-
-static int lfs_ls(lfs_t *lfs, const char *path) {
-    lfs_dir_t dir;
-    int err = lfs_dir_open(lfs, &dir, path);
-    if (err) {
-        return err;
-    }
-
-    struct lfs_info info;
-    while (true) {
-        int res = lfs_dir_read(lfs, &dir, &info);
-        if (res < 0) {
-            return res;
-        }
-
-        if (res == 0) {
-            break;
-        }
-
-        switch (info.type) {
-            case LFS_TYPE_REG: printf("file "); break;
-            case LFS_TYPE_DIR: printf("dir  "); break;
-            default:           printf("?    "); break;
-        }
-
-        printf("%4ld bytes ", info.size);
-
-        printf("%s\n", info.name);
-    }
-
-    err = lfs_dir_close(lfs, &dir);
-    if (err) {
-        return err;
-    }
-
-    return 0;
-}
-
-void app_init(void) {
-}
-
-void app_wake_from_backup(void) {
-}
-
-void app_setup(void) {
-    // mount the filesystem
-    int err = lfs_mount(&lfs, &cfg);
-
-    // reformat if we can't mount the filesystem
-    // this should only happen on the first boot
-    if (err) {
-        lfs_format(&lfs, &cfg);
-        lfs_mount(&lfs, &cfg);
-    }
-}
-
-void app_prepare_for_standby(void) {
-}
-
-void app_wake_from_standby(void) {
-}
-
-bool app_loop(void) {
-    char line[256] = {0};
-    char *buf;
-    struct lfs_info info;
-
-    read(0, line, 256);
-    if (strlen(line)) {
-        printf("$ %s", line);
-        char *command = strtok(line, " \n");
-        
-        if (strcmp(command, "ls") == 0) {
-            char *directory = strtok(NULL, " \n");
-            if (directory == NULL) {
-                lfs_ls(&lfs, "/");
-            } else {
-                printf("usage: ls\n");
-            }
-        } else if (strcmp(command, "cat") == 0) {
-            char *filename = strtok(NULL, " \n");
-            if (filename == NULL) {
-                printf("usage: cat file\n");
-            } else {
-                info.type = 0;
-                lfs_stat(&lfs, filename, &info);
-                if (info.type == LFS_TYPE_REG) {
-                    if (info.size > 0) {
-                        buf = malloc(info.size);
-                        lfs_file_open(&lfs, &file, filename, LFS_O_RDONLY);
-                        lfs_file_read(&lfs, &file, buf, info.size);
-                        printf("%s\n", buf);
-                        free(buf);
-                        lfs_file_close(&lfs, &file);
-                    } else {
-                        printf("\n");
-                    }
-                } else {
-                    printf("cat: %s: No such file\n", filename);
-                }
-            }
-        } else if (strcmp(command, "df") == 0) {
-            printf("free space: %d bytes\n", get_free_space());
-        } else if (strcmp(command, "rm") == 0) {
-            char *filename = strtok(NULL, " \n");
-            if (filename == NULL) {
-                printf("usage: rm file\n");
-            } else {
-                info.type = 0;
-                lfs_stat(&lfs, filename, &info);
-                if (info.type == LFS_TYPE_REG) {
-                    lfs_remove(&lfs, filename);
-                } else {
-                    printf("rm: %s: No such file\n", filename);
-                }
-            } 
-        } else if (strcmp(command, "echo") == 0) {
-            buf = malloc(64);
-            memset(buf, 0, 64);
-            size_t pos = 0;
-            char *text = strtok(NULL, " \n");
-            while (strcmp(text, ">")) {
-                sprintf(buf + pos, "%s ", text);
-                pos += strlen(text) + 1;
-                text = strtok(NULL, " \n");
-                if (text == NULL) break;
-            }
-            buf[strlen(buf) - 1] = 0;
-            char *filename = strtok(NULL, " \n");
-            if (filename == NULL) {
-                printf("usage: echo text > file\n");
-            } else if (strchr(filename, '/') || strchr(filename, '\\')) {
-                printf("subdirectories are not supported\n");
-            } else {
-                lfs_file_open(&lfs, &file, filename, LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC);
-                lfs_file_write(&lfs, &file, buf, strlen(buf));
-                lfs_file_close(&lfs, &file);
-            }
-            free(buf);
-        } else {
-            printf("%s: command not found\n", command);
-        }
-    }
-    return false;
-}
index 2a1319fb028dd8080d38aa56b62236ddb06dd716..559bd53de846f0871f00e2a24cd18a946478b195 100644 (file)
@@ -117,9 +117,11 @@ bool filesystem_init(void) {
     // reformat if we can't mount the filesystem
     // this should only happen on the first boot
     if (err) {
+        printf("Ignore that error! Formatting filesystem...\n");
         err = lfs_format(&lfs, &cfg);
         if (err) return false;
         err = lfs_mount(&lfs, &cfg) == LFS_ERR_OK;
+        printf("Filesystem mounted with %d bytes free.\n", filesystem_get_free_space());
     }
 
     return err == LFS_ERR_OK;
index 72c087e99f0bfe3f2483df49a7eb4584aa938cd5..3444a3785635200188994662c5c093d76e66a55f 100644 (file)
@@ -254,6 +254,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();
@@ -450,7 +452,7 @@ bool app_loop(void) {
 #else
         read(0, line, 256);
 #endif
-        if (strlen(line)) printf(line);
+        if (strlen(line)) filesystem_process_command(line);
     }
 
     event.subsecond = 0;
index 14bf44e6d797e2c0fa57a818b862feb4f3fe75fa..ac9db6ac156703102d3331057350b43cff406da1 100644 (file)
@@ -102,8 +102,6 @@ static void main_loop_set_sleeping(bool sleeping) {
 }
 
 int main(void) {
-    printf("Hello, world!\n");
-
     app_init();
     _watch_init();
     app_setup();