diff --git a/libs/microbit/shims.d.ts b/libs/microbit/shims.d.ts index 5644ffae..14de9d27 100644 --- a/libs/microbit/shims.d.ts +++ b/libs/microbit/shims.d.ts @@ -587,33 +587,34 @@ declare interface Buffer { /** - * Allows to save and read values in the flash storage + * This allows reading and writing of small blocks of data to FLASH memory. */ //% weight=10 color=#cc6600 declare namespace storage { /** - * Writes the key and buffer pair into flash. + * Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs + * have to be rewritten as well. */ - //% blockId="storage_put_buffer" block="storage put buffer %key|with %buffer" weight=50 shim=storage::putBuffer + //% shim=storage::putBuffer function putBuffer(key: string, buffer: Buffer): void; /** * Gets the buffer at the given key if any. If no key is available, empty buffer is returned. */ - //% blockId="storage_get_buffer" block="storage get buffer %key" weight=49 shim=storage::getBuffer + //% shim=storage::getBuffer function getBuffer(key: string): Buffer; /** * Removes an entry identified by the key. */ - //% blockId="storage_remove" block="storage remove %key" weight=20 shim=storage::remove + //% shim=storage::remove function remove(key: string): void; /** * The number of entries in the key value store */ - //% blockId="storage_size" block="storage size" weight=10 shim=storage::size + //% shim=storage::size function size(): number; } diff --git a/libs/microbit/storage.cpp b/libs/microbit/storage.cpp index 0656d578..ef270df5 100644 --- a/libs/microbit/storage.cpp +++ b/libs/microbit/storage.cpp @@ -1,14 +1,15 @@ #include "ksbit.h" /** -* Allows to save and read values in the flash storage +* This allows reading and writing of small blocks of data to FLASH memory. */ //% weight=10 color=#cc6600 namespace storage { /** - * Writes the key and buffer pair into flash. + * Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs + * have to be rewritten as well. */ - //% blockId="storage_put_buffer" block="storage put buffer %key|with %buffer" weight=50 + //% void putBuffer(StringData* key, Buffer buffer) { uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes()); } @@ -16,7 +17,7 @@ namespace storage { /** * Gets the buffer at the given key if any. If no key is available, empty buffer is returned. */ - //% blockId="storage_get_buffer" block="storage get buffer %key" weight=49 + //% Buffer getBuffer(StringData* key) { KeyValuePair* pv = uBit.storage.get(ManagedString(key)); if (pv == NULL) return ManagedBuffer().leakData(); @@ -27,7 +28,7 @@ namespace storage { /** * Removes an entry identified by the key. */ - //% blockId="storage_remove" block="storage remove %key" weight=20 + //% void remove(StringData * key) { uBit.storage.remove(ManagedString(key)); } @@ -35,7 +36,7 @@ namespace storage { /** * The number of entries in the key value store */ - //% blockId="storage_size" block="storage size" weight=10 + //% int size() { return uBit.storage.size(); }