I’m working on a new NeoPixel extension that supports the (easier) use of NeoPixel matrices. For that I forked the old NeoPixel extension from AdaFruit and Microsoft and extended and reworked it and handed it in publication to the Micro:Bit Foundation. They seemed to be quite happy with it but a requirement is that the extension works in its own namespace. This unfortunately seems to break the simulator part. Is there even a possiblity to work around that?
I do not fully understand how simulator extensions work. I know they are linked to an extension. I think that is the reason why changing the namespace breaks it. Removing the @parts and leaving the namespace as it is breaks it too. So I do get that the @parts and @trackArgs are linked to the simulator as well. If you could give me some hints about that I would be greatful.
This is the original namespace and code that works
namespace neopixel {
/**
* Create a new NeoPixel driver for `numleds` LEDs with
* brightness set to 128 (~50%).
* @param pin the pin where the neopixel is connected.
* @param numleds number of leds in the strip, eg: 24,30,60,64
*/
//% blockId="neopixel_create"
//% block="NeoPixel at pin %pin|with %numleds|leds as %mode"
//% weight=1000
//% trackArgs=0,2
//% blockSetVariable=strip
//% group="Initialization"
export function create(pin: DigitalPin, numleds: number, mode: NeoPixelMode): Strip {
let strip = new Strip();
let stride = mode === NeoPixelMode.RGBW ? 4 : 3;
strip.buf = pins.createBuffer(numleds * stride);
strip.start = 0;
strip._length = numleds;
strip._matrixDirection = NeoPixelMatrixDirection.LeftTopToTheRight
strip._mode = mode || NeoPixelMode.RGB;
strip._matrixWidth = 0;
strip.setBrightness(128)
strip.setPin(pin)
return strip;
}
// ...
}
As long as I worked inside the namespace of the other extension everything worked without any problems.
My extension can be found here: https://github.com/PasAlt/pxt-neopixel-matrix-extension