Implement tagged integers in C++ (#813)
* Start on the C++ conversion for tagged ints
This commit is contained in:
committed by
Sam El-Husseini
parent
01c7c0b588
commit
cad13785e2
@ -38,7 +38,7 @@ namespace basic {
|
||||
//% blockId=device_show_leds
|
||||
//% block="show leds" icon="\uf00a"
|
||||
//% parts="ledmatrix"
|
||||
void showLeds(ImageLiteral leds, int interval = 400) {
|
||||
void showLeds(ImageLiteral_ leds, int interval = 400) {
|
||||
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
|
||||
}
|
||||
|
||||
@ -53,18 +53,17 @@ namespace basic {
|
||||
//% async
|
||||
//% blockId=device_print_message
|
||||
//% parts="ledmatrix"
|
||||
void showString(StringData *text, int interval = 150) {
|
||||
void showString(String text, int interval = 150) {
|
||||
if (interval <= 0)
|
||||
interval = 1;
|
||||
ManagedString s(text);
|
||||
int l = s.length();
|
||||
int l = text ? text->length : 0;
|
||||
if (l == 0) {
|
||||
uBit.display.clear();
|
||||
fiber_sleep(interval * 5);
|
||||
} else if (l > 1) {
|
||||
uBit.display.scroll(s, interval);
|
||||
uBit.display.scroll(MSTR(text), interval);
|
||||
} else {
|
||||
uBit.display.print(s.charAt(0), interval * 5);
|
||||
uBit.display.print(text->data[0], interval * 5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +85,7 @@ namespace basic {
|
||||
*/
|
||||
//% help=basic/show-animation imageLiteral=1 async
|
||||
//% parts="ledmatrix"
|
||||
void showAnimation(ImageLiteral leds, int interval = 400) {
|
||||
void showAnimation(ImageLiteral_ leds, int interval = 400) {
|
||||
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0, 0);
|
||||
}
|
||||
|
||||
@ -96,18 +95,11 @@ namespace basic {
|
||||
*/
|
||||
//% help=basic/plot-leds weight=80
|
||||
//% parts="ledmatrix"
|
||||
void plotLeds(ImageLiteral leds) {
|
||||
void plotLeds(ImageLiteral_ leds) {
|
||||
MicroBitImage i(imageBytes(leds));
|
||||
uBit.display.print(i, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void forever_stub(void *a) {
|
||||
while (true) {
|
||||
runAction0((Action)a);
|
||||
fiber_sleep(20);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats the code forever in the background. On each iteration, allows other codes to run.
|
||||
* @param body code to execute
|
||||
@ -115,10 +107,7 @@ namespace basic {
|
||||
//% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
|
||||
//% blockId=device_forever block="forever" icon="\uf01e"
|
||||
void forever(Action a) {
|
||||
if (a != 0) {
|
||||
incr(a);
|
||||
create_fiber(forever_stub, (void*)a);
|
||||
}
|
||||
runForever(a);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user