Avatar for ruvi

ruvi

Member since Oct 2024 • Last active Jan 2025
  • 3 conversations
  • 10 comments

Most recent activity

  • in Bangle.js
    Avatar for ruvi

    Great, thanks for the suggestions.

  • in Bangle.js
    Avatar for ruvi

    I have a menu in my app:

    var mainMenuItems = {
      "":{"title":" "},
      "Lying Down": () => showConfirmationMenu("ly"),
      "Sitting": () => showConfirmationMenu("si"),
      "Standing": () => showConfirmationMenu("st"),
      "Delete last": () => deleteLastLog()
    };
    
    var mainMenu = E.showMenu(mainMenuItems);
    

    The buttons are so narrow compared to my fingertip and it is hard to even tell if I'm pressing the right buttons even if I'm very carefully and slowly pressing them.

    Is there any way to widen buttons? Whether making the font taller or just padding above and below the text on each button?

    I saw something about fontHeight in the graphical_menu library, but that doesn't seem to do anything here.

  • in Bangle.js
    Avatar for ruvi

    Thank you @Gordon and @halemmerich for your help.

    I actually really like the staging file idea. It seems to work well:

    FULL_DATA = 'full_log.csv';
    STAGING_FILE = 'staging_file.csv';
    
    const CSVLogger = {
      
      addLog: (col1, col2, col3) => {
        const line = `${col1},${col2},${col3}\n`;
        
        // Add staged string to full data file
        var stagedString = require("Storage").read(STAGING_FILE);
        if (stagedString) {
          fullData = require("Storage").open(FULL_DATA, "a");
          fullData.write(stagedString);
        }
        
        // Replace the staged file with the new line
        require("Storage").erase(STAGING_FILE);
        require("Storage").write(STAGING_FILE, line);      
      },
    
      getLastLog: () => {
        var stagedString = require("Storage").read(STAGING_FILE);
        return stagedString ? stagedString.trim().split(",") : null;
      },
      
      deleteLastLog: () => {
        require("Storage").erase(STAGING_FILE);
      },
      
      editLastLog: (col1, col2, col3) => {
        const line = `${col1},${col2},${col3}\n`;
      
        require("Storage").erase(STAGING_FILE);
        require("Storage").write(STAGING_FILE, line);      
      },
      
      // Save staged line to full file when ready to export data
      commitLastLog: () => {
        var stagedString = require("Storage").read(STAGING_FILE);
        
        if (stagedString) {
          // Add old string to full data file
          fullData = require("Storage").open(FULL_DATA, "a");
          fullData.write(stagedString);
        }
        
        require("Storage").erase(STAGING_FILE);
    
      },
      
      // For debugging
      showBothFiles: () => {
        
        var fullData = require("Storage").open(FULL_DATA, "r");
        fullString = fullData.read(1000);
        print("Full File:\n" + fullString);
        
        var stagedString = require("Storage").read(STAGING_FILE);
        print("Staged File:\n" + stagedString + "\n");
    
      }
        
    };
    
    
    CSVLogger.addLog('a', 'b', 'c');
    
    CSVLogger.editLastLog('1', '2', '3');
    
    CSVLogger.deleteLastLog();
    

    I'd only be logging a few dozen times per day, so I don't think flash writes should be a big deal.

    It's probably not necessary for my project, but it would be cool to have a more general solution for deleting multiple last lines in sequence, which might require something more like what Gordon was saying with rewriting the whole file, or appending the DELETE_LAST_LINE multiple times.

    • 7 comments
    • 358 views
  • in Bangle.js
    Avatar for ruvi

    Edit: Removed code that doesn't work.

    All I've figured out so far is appending a line, and getting the last line:

    const STORAGE_FILE = "datalog.csv";
    
    const CSVLogger = {
      addLog: (col1, col2, col3) => {
        const line = `${col1},${col2},${col3}\n`;
        const file = require("Storage").open(STORAGE_FILE, "a");
        
        file.write(line);
      },
    
      getLastLog: () => {
        var file = require("Storage").open(STORAGE_FILE, "r");
        
        while (true) {
          buffer = file.readLine();
          if (!buffer) {
            break;
          }
          string = buffer;
        }
        
      return string ? string.trim().split(",") : null;
        
      }
    }
    

    With Storage I think I can edit the last line, but not append. But with StorageFile, I don't see how I can edit or delete. And my function for getting the last line seems very inefficient for large files.

    Edit: Thinking more about my use case, I don't think it'll ever have to be longer than 50kb, so maybe I can just manipulate everything in RAM.

  • in Bangle.js
    Avatar for ruvi

    I'm working on a project that involves data logging in a CSV, but where there should be the option of editing/deleting the last line of the CSV. I'm not sure how to go about this with a Bangle.

    I was thinking maybe something like loading the whole file into a string, deleting the last line, then re-saving it. But I'm worried about the size of the string being larger than the watch can handle if the file gets very long.

    var file = require("Storage").open("positions.csv","r");
    
    // Read whole file with very long length parameter
    csv = file.read(100000);
    
    // Convert to array of lines
    csvNew = csv.split('\n');
    
    // Remove last line
    csvNew.pop();
    
    // Join back into single string
    csvNew = csvNew.join("\n");
    
    var file = require("Storage").open("positions.csv", "w");
    
    file.write(csvNew);
    

    Is there a better way to do this?

    Edit: Oh, maybe I can somehow access just the last chunk with the file\5 notation? I don't know if that's a thing.

    It doesn't necessarily have to be in CSV format.

  • in Bangle.js
    Avatar for ruvi

    Good to know, thanks!

    • 7 comments
    • 375 views
Actions