• Here is a screenshot of my proof of concept steps watch face. This reads the last log line from the ActivePedomiter CSV log file. The code needs polishing up. For example there is a 1 second delay while the log file gets read. The code only needs to read the last data, so maybe some optimision might be possible. Also need to handle the log file not being present and a hint to use
    the ActivePedominter App.

    I managed to write the code below to ped2.face.js to Storage and when the multiclock reloads this face gets added. Obviously this is not the correct way. Need to setup my github / bootloader.

    (() => {
    
       function getFace(){
                        
      function getArrayFromCSV(file, column) { 
        var history = 86400000; // 28800000=8h 43200000=12h //86400000=24h
    
        i = 0;
        array = [];
        now = new Date();
        while ((nextLine = file.readLine())) { //as long as there is a next line
          if(nextLine) {
            dataSplitted = nextLine.split(','); //split line, 
            diff = now - dataSplitted[0]; //calculate difference between now and stored time
            if (diff <= history) { //only entries from the last x ms
              array.push(dataSplitted[column]);
            }
          }
          i++;
        }
        return array;
      }
            
      function draw() {
        const storage = require("Storage");
        let now = new Date();
        let month = now.getMonth() + 1;
          
        if (month < 10) month = "0" + month;
        
        let filename = "activepedom" + now.getFullYear() + month + now.getDate() + ".data";
        let csvFile = storage.open(filename, "r");
        let data = getArrayFromCSV(csvFile, 1);
        let steps = data[data.length-1];      
        csvFile = undefined;
        data = undefined;
          
        if (steps > 99999){
             steps = steps % 100000; // cap to five digits + comma = 6 characters
        }
    
        let stps = steps.toString();
        g.reset();
        g.clearRect(0,24,239,239);
        g.setFont("Vector",48);
        g.setColor(1,1,1);  // white
        g.drawString("Steps",50,24,true);
        g.setColor(0,255,0);
        g.drawString(stps,50,96,true);   
      }
           
      function onSecond(){
        var t = new Date();
        if (t.getSeconds() === 0) draw();
      }
    
        return {init:draw, tick:onSecond};
      }
    
      return getFace;
    
    })();
    
    

    1 Attachment

    • IMG_20210103_210741.jpg
About

Avatar for HughB @HughB started