Git Product home page Git Product logo

pxt-filesystem's Introduction

File system driver Build Status

To use this package, go to https://makecode.microbit.org, click Extensions and search for filesystem.

~ hint

DEPRECATED - This package is no longer maintained or supported.

~

Usage

The package allows to read and write files to the @boardname@ flash.

~hint

The entire file system content is ERASED when a new .hex file is download onto the @boardname@.

~

Writing data

  • append text and a new line character
files.appendLine("data.txt", "Hello");
  • append text to the file
files.appendString("data.txt", "Hello");
  • append a number (as text) to the file
files.appendNumber("data.txt", 42);

Reading data

  • send the content of a file to serial
files.readToSerial("data.txt");

Settings

The package allows to save and load number settings based on the file system

  • save setting value
files.settingsSaveNumber("calibrated", 1)
  • read setting value
let calibrated = files.settingsReadNumber("calibrated");

File class

The File class allows to keep a file instance open, manipulate the pointer position and read from the file.

  • open, flush or close the file
let f = files.open("data.txt");
f.flush();
f.close();
  • write strings or buffers
let f = files.open("data.txt");
f.writeString("yay");
  • read data
let f = files.open("data.txt");
let buf = f.readBuffer(64);
let c = f.read();
  • set the cursor position
let f = files.open("data.txt");
f.setPosition(42);
let pos = f.position();

Example: Writing accelerometer data

The following program allows to collect accelerometer data and save it in a data.csv file. When the user presses button A, the @boardname@ pauses for 3 seconds, then starts collecting 720 acceleration samples. Each sample is written to the file in a format that can be important by spreadsheet programs (CSV).

let file = "data.csv";
input.onButtonPressed(Button.A, () => {    
    basic.pause(3000);
    files.remove(file);
    files.appendLine(file, "Time\tAcceleration");
    for (let i = 0; i < 100; ++i) {
        let t = input.runningTime();
        let ay = input.acceleration(Dimension.Y);
        files.appendLine(file, t + "\t" + ay);
        control.waitMicros(20);
    }
});
input.onButtonPressed(Button.B, () => {
    files.readToSerial(file);
    basic.showString(":)")
})

Supported targets

  • for PXT/ microbit
  • for PXT/ calliope

License

MIT

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

pxt-filesystem's People

Contributors

abchatra avatar mmoskal avatar pelikhan avatar xuefengedu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-filesystem's Issues

Need files.appendByte(255) for efficient storage

This is less important than the #6 corruption issue, but it would be extremely useful to be able to save individual bytes into the memory.

This use of the limited flash storage would be many times more efficient than saving numbers as strings, allowing much more data to be saved.

Can't compile/download in PXT editor when filesystem library included

Hi, I'm keen to use the filesystem via the PXT editor (and appreciate this is BETA) but currently any attempt to compile when the filesystem library results in a ton of errors in the browser console and the project then fails to compile. Didn't know if you guys were aware?

Corruption writing to file with accelerometer example

When using the accelerometer example on the GitHub page, and reading the serial data using TeraTerm, the received data is corrupted, as enclosed. It looks to me like the kind of symptom you'd get with concurrent write access to the file or pointer overruns, but it may have another cause, of course. I don't believe it is corruption on reception of the serial data, because the string "MICROBIT_FS_1 " appears in the data, and it is hard to explain that except by corruption during either reading or writing the file.

Time    Acceleration
4580    704
4653    704
4658    672
4663    672
4735    720
4740    720
4813    720
4818    720
4891    688
ÿÿ      688ÿ!ÿÿÿ        ÿÿIÿ4973        %ÿ
ÿÿÿ•688
ÿÿïÿ    656ÿ=ÿÿÿ        656
5169    656
5174    656
5268    624
5273    624
5366    656
5371    656
5375    688
5470    624
5475    624
5569    672
5574    672
5668    640
5673    640
5767    624
5772    624
5776    624
5870    640
5875    640
5969    640
5974    ÿÿÿ6068 !ÿ
ÿÿÿI640
ÿ%ÿ     640ÿ•ÿÿÿ        640ÿ6177        =ÿ
6270    640
6275    640
6369    640
6374    640
6468    624
6473    624
6567    640
6572    640
6576    640
6670    624
6675    640
6770    640
6776    640
6870    640
6879    640
6972    624
6977    624
6981    624
7075    640
7080    640
7MICROBIT_FS_1  0@œ624
7277    624
7371    624
7376    640
7381    640
7475    640
7480    640
7574    640
7579    640
7673    624
7678    624
7772    640
7777    640
7781    640
7875    624
7880    624
7974    624
7979    640
8073    640
8079    640
8173    640
8179    640
8186    640
8280    62Time  Acceleration
                                8153    16
8158    16
8230    16
8235    16
8239    16
8312    112
8316    112
8388    32
8393    32
8465    32
8470    32
8542    32
                8546    32
8550

appendLine/appendString block names swapped

The block comments for appendLine and appendString are incorrect, leading to the two functions being named the wrong way round in the PXT blocks editor:

files.cpp, L31 is:
//% blockId="files_append_line" block="file %filename|append string %text"
should be:
//% blockId="files_append_line" block="file %filename|append line %text"

files.cpp, L48 is:
//% blockId="fs_append_string" block="file %filename|append line %text"
should be:
//% blockId="fs_append_string" block="file %filename|append string %text"

I have submitted a change.

W10 app: "read to serial" block from filesystem could result in a file in the 'serial viewer

Inside the 'fileystem' module there's a 'read data to serial' block

This blocks doesn't interact very well with the W10 app's serial data viewer.

It would be great if use of this block could trigger a 'file' object inside the serial viewer, that could be dragged back onto the filesystem.

Here's an example program:
https://makecode.microbit.org/35902-71245-24007-20291

Even without a drag/dropable file, making a list of 'files' that have been sent over serial that could be 'downloaded' or opened in Excel would be great.

Program Error: pxsim.files.createDirectory is not a function

While using the filesystem package in the I get an error trying to use settings save number in the Blockeditor or files.settingsSaveNumber in the javascript editor. The error message is:

Program Error: pxsim.files.createDirectory is not a function

File System package simulator error

In the File System, the settings save number ["_"] as [_] causes the following simulator error:

Program Error: pxsim.files.createDirectory is not a function

fs

Same thing happens with the settings read number ["_"] block.

Hex files with Filesystem extension crash on Microbit, works in simulator

Describe the bug
A clear and concise description of what the bug is.
when use the 'Filesystem' extension in Makecode, the simulator works fine, but when transfered to the Microbit, the program crashes with sad-face-code 030.

Even if I include just a single block of "File", this happens.
For instance, the supplied demo program of "accelerator measuring" on the extension page does this.

Desktop (please complete the following information):

  • OS: Win 10
  • MAkecode App
  • Version :version makecode.microbit.org: 2.0.6
    version Microsoft MakeCode: 5.15.12
    version microbit runtime: pxtgc-0

I have the latest Firmware on the 'bit.

-Morten

File Download

Is there currently no way to access and download the files saved to the microbit? Dumping to serial is a problem as this tends to be blocked in UK schools :-(

The MicroPython version of file store has a utility call MicroFS that allows you to put and get the files. So I can write my data as a csv file to the flash and then use the tool to "download" the file.

Extension filesystem: filesystem/files.cpp(17): cannot determine value of Set = MB_SEEK_SET, filesystem/files.cpp(19): cannot determine value of Current = MB_SEEK_CUR, filesystem/files.cpp(21): cannot determine value of End = MB_SEEK_END

I tried to implement filesystem in my project, but it gives me this error.

Extension filesystem: filesystem/files.cpp(17): cannot determine value of Set = MB_SEEK_SET, filesystem/files.cpp(19): cannot determine value of Current = MB_SEEK_CUR, filesystem/files.cpp(21): cannot determine value of End = MB_SEEK_END

Hex file does not compile in win10 app

Describe the bug
A clear and concise description of what the bug is.
User reports that microbit-light_level_external_sensor_v63.hex.zip will open in the makecode web editor and recompile, but not in the win 10 app which reports a compilation failure. The file also runs on the micro:bit hardware without error.

To Reproduce
Steps to reproduce the behavior:

  1. Open attached Hex in Windows10 app
  2. Click on Download
  3. See compilation error

Expected behavior
Code should compile as in web app

Screenshots
Add screenshots to help explain your problem. You can copy paste the screenshot in the github report. The .gif screen recording is very useful as well.

Desktop (please complete the following information):

  • OS: Win 10 v1803

App version is out of sync with browser version. Is it supposed to auto update?
screenshot 2018-12-17 at 11 40 26

Need block for sequential file read

Hello,

I am recording data from sensors attached to a microbit and storing the values in a csv format file. I can cause the microbit to dump the file to the serial port on demand (which is very useful).

I would like to be able to read through a file sequentially, assigning the next line of the file to a variable. If this were possible, I could transmit the data using either radio or bluetooth.

I don't have an urgent need for this but it would make the pxt solution more complete.

Rae

support for data files

The possiblity of data files that can be used by a program
Probably something that should be given thought to as to how to create a general solution.
use case should be added to this enhancement issue.
This is copied from slack: Jonny suggested to be able to add data files in the project (e.g. Text file) and we would automatically pre-populate the filesystem with those files when flashing the device.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.