[Extension] Device control - control namespace ported to blocks!

Hey everyone, back with another extension. Today I was wondering why the control namespace hasn’t been ported to blocks like the settings namespace for example. That’s why I like usually, decided to do it myself. The namespace i’ve ported them to is named blockControl, alike blockSettings.

The ‘control’ namespace

For anyone unfamiliar, the control namespace is a namespace that contains many methods used for managing the device and retrieving its information such as the ram size, serial number etc.

I have separated the blocks into 3 categories: Device control, Debugging and Device & session information.

P.S: If you’re unfamiliar with these functions and their use, don’t bother with this extension.
One thing to add is that not all methods from the namspace are present, because i’m either unfamiliar with some of them, or they don’t serve a particular purpose. If you have any requests, let me know and I’ll be glad to add them to this extension.

Device control

The device control sections consists of methods that manipulate system memory or the flow of the program running.

blockControl.assert (control.assert)

This method asserts a condition. If the condition is not met, the program is halted and a PANIC CODE is raised. Currently under testing since it’s raising the incorrect code.

function assert(condition: boolean, code: number) => void

blockControl.raiseEvent (control.raiseEvent)

This method raises an event to registered handlers with a component ID (src) and it’s specific event code

function raiseEvent(src: number, value: number) => void

blockControl.onEvent (control.onEvent)

Execute code on registered event (with the raiseEvent method) with a component ID, code and optional flags.

function onEvent(src: number, code: number, flags?: number) => void

blockControl.waitForEvent (control.waitForEvent)

Block calling thread until the specified event is run.

function waitForEvent(src: number, code: number) => void

blockControl.runInBackground (control.runInBackground)

Run code in background.

// NOTICE: This method is deprecated! Use `control.runInParallel` instead.
function runInBackground(handler: () => void) => void

blockControl.runInParallel (control.runInParallel)

Run code in parallel to main thread.

function runInParallel(handler: () => void) => void

blockControl.createBuffer (control.createBuffer)

Create and return a zero-initiated buffer with a given size in bytes.

function createBuffer(size: number) => Buffer

blockControl.createBufferFromUTF8 (control.createBufferFromUTF8)

Create and return a buffer from a UTF8-encoded string. (Unicode)

function createBufferFromUTF8(str: string) => Buffer

(available blocks, matching above methods)


The debugging section consists of various tools for debugging performance and functionality of the device.

blockControl.dmesgValue (control.dmesgValue)

This method dumps internal information about any value or object.

function dmesgValue(value: any) => void

blockControl.gc (control.gc)

This method forces garbage collection and dumps basic informations about the heap.

function gc() => void

blockControl.dumpHeap (control.dumpHeap)

This method forces garbage collection and waits for a debugger to fully dump the heap.

function dumpHeap() => void

blockControl.setDebugFlags (control.setDebugFlags)

Set flags for debugging.

function setDebugFlags(flags: number) => void

blockControl.heapSnapshot (control.heapSnapshot)

Record a heap snapshot for debugging memory leaks.

function heapSnapshot() => void

blockControl.benchmark (control.benchmark)

Run a block of code or method and return runtime in microseconds.

function benchmark(func: () => void) => void


(available blocks, matching above methods)

Device & session information

The device and session information section includes method that retrieve information and data about the device and / or session.

blockControl.timeSinceStart (control.millis + control.micros)

This method returns time since device start in micro/milliseconds.

// TimeFormat = Microseconds | Milliseconds
function timeSinceStart(format: TimeFormat) => number

blockControl.deviceSerialNumber (control.deviceSerialNumber)

This method returns a unique serial number of the device.

function deviceSerialNumber() => number

blockControl.deviceLongSerialNumber (control.deviceLongSerialNumber)

This method returns a 64-bit unique serial number of the device.

function deviceLongSerialNumber() => Buffer

blockControl.deviceDalVersion (control.deviceDalVersion)

This method returns the system software version string of the device. (sim if running in the simulator)

function deviceDalVersion() => string

blockControl.profilingEnabled (control.profilingEnabled)

Return true if profiling is enabled.

function profilingEnabled() => boolean

blockControl.programHash (control.programHash)

Return the program hash.

function programHash() => number

blockControl.programName (control.programName)

Return the program name.

function programName() => string

blockControl.ramSize (control.ramSize)

Return estimated RAM size in bytes.

function ramSize() => number


(available blocks, matching above methods)

If you’ve made it this far, thank you for reading! If you have any questions or suggestions, feel free to leave them in the replies!

By the way, I still haven’t made a release for this extension, so I hope I’ll get around to doing that in the next few days!

(extension / repo link)


holy moly you are making a lot of extensions, but very nice!