This commit is contained in:
Peli de Halleux 2018-11-06 08:24:27 -08:00
Родитель 3c0aa8a15d
Коммит c8f5f0e162
4 изменённых файлов: 24 добавлений и 20 удалений

6
enums.d.ts поставляемый
Просмотреть файл

@ -7,11 +7,11 @@
declare const enum FileSystemSeekFlags {
//% block=set
Set = 0x01, // MB_SEEK_SET
Set = 1, // MB_SEEK_SET
//% block=current
Current = 0x04, // MB_SEEK_CUR
Current = 4, // MB_SEEK_CUR
//% block=end
End = 0x02, // MB_SEEK_END
End = 2, // MB_SEEK_END
}
declare namespace files {
}

Просмотреть файл

@ -220,16 +220,20 @@ int fsWriteBuffer(int fd, Buffer buffer) {
//% weight=0 advanced=true
Buffer fsReadBuffer(int fd, int length) {
if (fd < 0 || length < 0)
return ManagedBuffer().leakData();
return mkBuffer(NULL, 0);
initFileSystem();
ManagedBuffer buf(length);
Buffer buf = mkBuffer(NULL, length);
int ret = MicroBitFileSystem::defaultFileSystem->read(fd, buf.getBytes(), buf.length());
int ret = MicroBitFileSystem::defaultFileSystem->read(fd, PXT_BUFFER_DATA(buf), buf->length);
if (ret < 0) return ManagedBuffer().leakData();
else if (ret != length) return buf.slice(0, ret).leakData();
else return buf.leakData();
if (ret < 0) return mkBuffer(NULL, 0);
else if (ret != length) {
auto sbuf = mkBuffer(PXT_BUFFER_DATA(buf), ret);
decrRC(buf);
return sbuf;
}
else return buf;
}
/**

20
shims.d.ts поставляемый
Просмотреть файл

@ -55,60 +55,60 @@ declare namespace files {
*/
//% blockId=settings_read_number block="settings read number %name"
//% weight=19 shim=files::settingsReadNumber
function settingsReadNumber(name: string): number;
function settingsReadNumber(name: string): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsOpen
function fsOpen(path: string): number;
function fsOpen(path: string): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsFlush
function fsFlush(fd: number): number;
function fsFlush(fd: int32): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsClose
function fsClose(fd: number): number;
function fsClose(fd: int32): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsRemove
function fsRemove(name: string): number;
function fsRemove(name: string): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsSeek
function fsSeek(fd: number, offset: number, flags: number): number;
function fsSeek(fd: int32, offset: int32, flags: int32): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsWriteString
function fsWriteString(fd: number, text: string): number;
function fsWriteString(fd: int32, text: string): int32;
/**
*
*/
//% weight=0 advanced=true shim=files::fsWriteBuffer
function fsWriteBuffer(fd: number, buffer: Buffer): number;
function fsWriteBuffer(fd: int32, buffer: Buffer): int32;
/**
*/
//% weight=0 advanced=true shim=files::fsReadBuffer
function fsReadBuffer(fd: number, length: number): Buffer;
function fsReadBuffer(fd: int32, length: int32): Buffer;
/**
*
*/
//% weight=0 advanced=true shim=files::fsRead
function fsRead(fd: number): number;
function fsRead(fd: int32): int32;
}
// Auto-generated. Do not edit. Really.

Просмотреть файл

@ -21,7 +21,7 @@ input.onButtonPressed(Button.B, () => {
files.readToSerial(file);
basic.showString(":)")
})
let test = Math.random(1000);
let test = Math.randomRange(0, 1000);
files.settingsSaveNumber("test", test);
serial.writeValue("test", test);
let serTest = files.settingsReadNumber("test");