Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57082654a9 | ||
|
|
8cbf7d38e3 | ||
|
|
a99a7325bf | ||
|
|
fa3ed9dd21 | ||
|
|
45fd40a553 | ||
|
|
5a18bea9eb | ||
|
|
d310312841 | ||
|
|
a4b93f7199 | ||
|
|
538a4b7bbf | ||
|
|
0078e7bc12 | ||
|
|
d2726133a9 | ||
|
|
00f4c9cbb3 | ||
|
|
e15da5dee1 | ||
|
|
85dda4ea84 | ||
|
|
a3ffe4e1cf | ||
|
|
90c4d4f73b | ||
|
|
6484d559d6 | ||
|
|
357436f14d | ||
|
|
85fe96b3fd | ||
|
|
cdac932c42 | ||
|
|
dcfc2a110d | ||
|
|
e9561f54c3 | ||
|
|
86f6b58d38 | ||
|
|
eee52a5c04 | ||
|
|
1a0b0eac71 | ||
|
|
5a98ae0bb8 | ||
|
|
a9eea9a618 | ||
|
|
3086c521e3 | ||
|
|
6788f79650 | ||
|
|
5900239045 | ||
|
|
248267ec2c | ||
|
|
9429075555 | ||
|
|
1fa871f2e7 | ||
|
|
04dab7df2c | ||
|
|
b6474467bc | ||
|
|
79ead74af4 | ||
|
|
0f8ff95b72 | ||
|
|
05028c4527 | ||
|
|
4054da3483 | ||
|
|
7052d27d6d | ||
|
|
365af8d672 | ||
|
|
c938618d29 | ||
|
|
91321dab83 |
@@ -7,8 +7,11 @@ serial.writeLine("");
|
|||||||
serial.writeNumber(0);
|
serial.writeNumber(0);
|
||||||
serial.writeValue("x", 0);
|
serial.writeValue("x", 0);
|
||||||
serial.writeString("");
|
serial.writeString("");
|
||||||
|
serial.readUntil(",");
|
||||||
serial.readLine();
|
serial.readLine();
|
||||||
|
serial.readString();
|
||||||
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
|
||||||
|
serial.onDataReceived(",", () => {})
|
||||||
```
|
```
|
||||||
|
|
||||||
### See Also
|
### See Also
|
||||||
|
|||||||
29
docs/reference/serial/on-data-received.md
Normal file
29
docs/reference/serial/on-data-received.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Serial On Data Received
|
||||||
|
|
||||||
|
Registers an event to be fired when one of the delimiter is matched.
|
||||||
|
|
||||||
|
|
||||||
|
```sig
|
||||||
|
serial.onDataReceived(",", () => {})
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* `delimiters` is a [string](/reference/types/string) containing any of the character to match
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
Read values separated by `,`:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
serial.onDataReceived(serial.delimiters(Delimiters.Comma), () => {
|
||||||
|
basic.showString(serial.readUntil(serial.delimiters(Delimiters.Comma)))
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### See also
|
||||||
|
|
||||||
|
[serial](/device/serial),
|
||||||
|
[serial write line](/reference/serial/write-line),
|
||||||
|
[serial write value](/reference/serial/write-value)
|
||||||
|
|
||||||
27
docs/reference/serial/read-string.md
Normal file
27
docs/reference/serial/read-string.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Serial Read String
|
||||||
|
|
||||||
|
Read the buffered serial data as a string
|
||||||
|
|
||||||
|
```sig
|
||||||
|
serial.readString();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
* a [string](/reference/types/string) containing input from the serial port. Empty if no data available.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
The following program scrolls text on the screen as it arrives from serial.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showString(serial.readString());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### See also
|
||||||
|
|
||||||
|
[serial](/device/serial),
|
||||||
|
[serial write line](/reference/serial/write-line),
|
||||||
|
[serial write value](/reference/serial/write-value)
|
||||||
@@ -31,6 +31,7 @@ and press **A** to scroll your text.
|
|||||||
### Step 5
|
### Step 5
|
||||||
|
|
||||||
Place more blocks to display a smiley when button **B** is pressed.
|
Place more blocks to display a smiley when button **B** is pressed.
|
||||||
|
Use the dropdown to find ``B``!
|
||||||
|
|
||||||
```block
|
```block
|
||||||
input.onButtonPressed(Button.B, () => {
|
input.onButtonPressed(Button.B, () => {
|
||||||
@@ -59,3 +60,15 @@ input.onGesture(Gesture.Shake, () => {
|
|||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Step 7
|
||||||
|
|
||||||
|
Drag more blocks to display a random number when pin ``P0`` is touched.
|
||||||
|
Hold your right thumb on the ``GND`` metal pin
|
||||||
|
at press the ``0`` pin with your right hand to trigger this event.
|
||||||
|
|
||||||
|
```block
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(Math.random(7))
|
||||||
|
})
|
||||||
|
```
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"versions": {
|
"versions": {
|
||||||
"0": {
|
"0": {
|
||||||
"latest": "v0.6.45",
|
"latest": "v0.7.29",
|
||||||
"banned": [],
|
"banned": [],
|
||||||
"prompt": "v0.0.0"
|
"prompt": "v0.7.29"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<block type="pxt-on-start"></block>
|
<block type="pxt-on-start"></block>
|
||||||
|
<block type="device_forever"></block>
|
||||||
</xml>
|
</xml>
|
||||||
@@ -231,8 +231,10 @@
|
|||||||
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
|
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
|
||||||
"serial": "Reading and writing data over a serial connection.",
|
"serial": "Reading and writing data over a serial connection.",
|
||||||
"serial.delimiters": "Returns the delimiter corresponding string",
|
"serial.delimiters": "Returns the delimiter corresponding string",
|
||||||
"serial.onLineReceived": "Registers an event to be fired when a line has been received",
|
"serial.onDataReceived": "Registers an event to be fired when one of the delimiter is matched.",
|
||||||
|
"serial.onDataReceived|param|delimiters": "the characters to match received characters against.",
|
||||||
"serial.readLine": "Reads a line of text from the serial port.",
|
"serial.readLine": "Reads a line of text from the serial port.",
|
||||||
|
"serial.readString": "Reads the buffered received data as a string",
|
||||||
"serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.",
|
"serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.",
|
||||||
"serial.readUntil|param|delimiter": "text delimiter that separates each text chunk",
|
"serial.readUntil|param|delimiter": "text delimiter that separates each text chunk",
|
||||||
"serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.",
|
"serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.",
|
||||||
|
|||||||
@@ -171,7 +171,9 @@
|
|||||||
"pins.spiWrite|block": "spi write %value",
|
"pins.spiWrite|block": "spi write %value",
|
||||||
"pins|block": "pins",
|
"pins|block": "pins",
|
||||||
"serial.delimiters|block": "%del",
|
"serial.delimiters|block": "%del",
|
||||||
|
"serial.onDataReceived|block": "serial|on data received %delimiters=serial_delimiter_conv",
|
||||||
"serial.readLine|block": "serial|read line",
|
"serial.readLine|block": "serial|read line",
|
||||||
|
"serial.readString|block": "serial|read string",
|
||||||
"serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
|
"serial.readUntil|block": "serial|read until %delimiter=serial_delimiter_conv",
|
||||||
"serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
|
"serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate",
|
||||||
"serial.writeLine|block": "serial|write line %text",
|
"serial.writeLine|block": "serial|write line %text",
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ namespace String_ {
|
|||||||
|
|
||||||
//%
|
//%
|
||||||
int compare(StringData *s, StringData *that) {
|
int compare(StringData *s, StringData *that) {
|
||||||
return strcmp(s->data, that->data);
|
int compareResult = strcmp(s->data, that->data);
|
||||||
|
if (compareResult < 0)
|
||||||
|
return -1;
|
||||||
|
else if (compareResult > 0)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//%
|
//%
|
||||||
|
|||||||
@@ -150,15 +150,9 @@ namespace pxt {
|
|||||||
|
|
||||||
if (i < length)
|
if (i < length)
|
||||||
{
|
{
|
||||||
if (data[i] != Segment::MissingValue)
|
|
||||||
{
|
|
||||||
return data[i];
|
return data[i];
|
||||||
}
|
|
||||||
error(ERR_MISSING_VALUE);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segment::set(uint32_t i, uint32_t value)
|
void Segment::set(uint32_t i, uint32_t value)
|
||||||
@@ -223,12 +217,8 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
memcpy(tmp, data, size * sizeof(uint32_t));
|
memcpy(tmp, data, size * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
|
//fill the rest with default value
|
||||||
//fill the rest with missing values;
|
memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t));
|
||||||
for(uint16_t i = size; i < newSize; i++)
|
|
||||||
{
|
|
||||||
tmp[i] = Segment::MissingValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//free older segment;
|
//free older segment;
|
||||||
::operator delete(data);
|
::operator delete(data);
|
||||||
@@ -280,12 +270,11 @@ namespace pxt {
|
|||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
uint32_t value = data[length];
|
uint32_t value = data[length];
|
||||||
data[length] = Segment::MissingValue;
|
data[length] = Segment::DefaultValue;
|
||||||
--length;
|
--length;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//this function removes an element at index i and shifts the rest of the elements to
|
//this function removes an element at index i and shifts the rest of the elements to
|
||||||
@@ -306,15 +295,14 @@ namespace pxt {
|
|||||||
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
|
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
length--;
|
length--;
|
||||||
data[length] = Segment::MissingValue;
|
data[length] = Segment::DefaultValue;
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
printf("After Segment::remove index:%u\n", i);
|
printf("After Segment::remove index:%u\n", i);
|
||||||
this->print();
|
this->print();
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
return Segment::DefaultValue;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//this function inserts element value at index i by shifting the rest of the elements right.
|
//this function inserts element value at index i by shifting the rest of the elements right.
|
||||||
@@ -360,32 +348,13 @@ namespace pxt {
|
|||||||
|
|
||||||
bool Segment::isValidIndex(uint32_t i)
|
bool Segment::isValidIndex(uint32_t i)
|
||||||
{
|
{
|
||||||
if (i > length || data[i] == Segment::MissingValue)
|
if (i > length)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Segment::getNextValidIndex(uint32_t i, uint32_t *result)
|
|
||||||
{
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
if (data[i] != Segment::MissingValue)
|
|
||||||
{
|
|
||||||
*result = i;
|
|
||||||
|
|
||||||
#ifdef DEBUG_BUILD
|
|
||||||
printf("In Segment::getNextValidIndex result=%u\n",i);
|
|
||||||
this->print();
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Segment::destroy()
|
void Segment::destroy()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
@@ -415,29 +384,16 @@ namespace pxt {
|
|||||||
|
|
||||||
uint32_t RefCollection::getAt(int i)
|
uint32_t RefCollection::getAt(int i)
|
||||||
{
|
{
|
||||||
if (head.isValidIndex(i))
|
uint32_t tmp = head.get(i);
|
||||||
|
if (isRef())
|
||||||
{
|
{
|
||||||
uint32_t tmp = head.get(i);
|
incr(tmp);
|
||||||
if (isRef())
|
|
||||||
{
|
|
||||||
incr(tmp);
|
|
||||||
}
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RefCollection::removeAt(int i)
|
uint32_t RefCollection::removeAt(int i)
|
||||||
{
|
{
|
||||||
if (!head.isValidIndex((uint32_t)i))
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (isRef())
|
if (isRef())
|
||||||
{
|
{
|
||||||
decr(head.get(i));
|
decr(head.get(i));
|
||||||
@@ -447,18 +403,11 @@ namespace pxt {
|
|||||||
|
|
||||||
void RefCollection::insertAt(int i, uint32_t value)
|
void RefCollection::insertAt(int i, uint32_t value)
|
||||||
{
|
{
|
||||||
if (i < length())
|
head.insert(i, value);
|
||||||
|
if (isRef())
|
||||||
{
|
{
|
||||||
head.insert(i, value);
|
incr(value);
|
||||||
if (isRef())
|
}
|
||||||
{
|
|
||||||
incr(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error(ERR_OUT_OF_BOUNDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefCollection::setAt(int i, uint32_t value)
|
void RefCollection::setAt(int i, uint32_t value)
|
||||||
@@ -480,26 +429,31 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
StringData *xx = (StringData*)x;
|
StringData *xx = (StringData*)x;
|
||||||
uint32_t i = start;
|
uint32_t i = start;
|
||||||
while(head.getNextValidIndex(start, &i))
|
while(head.isValidIndex(i))
|
||||||
{
|
{
|
||||||
StringData *ee = (StringData*)head.get(i);
|
StringData *ee = (StringData*)head.get(i);
|
||||||
if (xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
|
if (ee == xx)
|
||||||
|
{
|
||||||
|
//handles ee being null
|
||||||
|
return (int) i;
|
||||||
|
}
|
||||||
|
if (ee && xx->len == ee->len && memcmp(xx->data, ee->data, xx->len) == 0)
|
||||||
{
|
{
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
start = i;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32_t i = start;
|
uint32_t i = start;
|
||||||
while(head.getNextValidIndex(start, &i))
|
while(head.isValidIndex(i))
|
||||||
{
|
{
|
||||||
if (head.get(i) == x)
|
if (head.get(i) == x)
|
||||||
{
|
{
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
start = i;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,12 +504,9 @@ namespace pxt {
|
|||||||
{
|
{
|
||||||
if (this->isRef())
|
if (this->isRef())
|
||||||
{
|
{
|
||||||
uint32_t start = 0;
|
for(uint32_t i = 0; i < this->head.getLength(); i++)
|
||||||
uint32_t i = 0;
|
|
||||||
while(head.getNextValidIndex(start, &i))
|
|
||||||
{
|
{
|
||||||
decr(this->head.get(i));
|
decr(this->head.get(i));
|
||||||
start = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->head.destroy();
|
this->head.destroy();
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ namespace pxt {
|
|||||||
ERR_OUT_OF_BOUNDS = 8,
|
ERR_OUT_OF_BOUNDS = 8,
|
||||||
ERR_REF_DELETED = 7,
|
ERR_REF_DELETED = 7,
|
||||||
ERR_SIZE = 9,
|
ERR_SIZE = 9,
|
||||||
ERR_MISSING_VALUE = 10,
|
|
||||||
} ERROR;
|
} ERROR;
|
||||||
|
|
||||||
extern const uint32_t functionsAndBytecode[];
|
extern const uint32_t functionsAndBytecode[];
|
||||||
@@ -175,7 +174,7 @@ namespace pxt {
|
|||||||
uint16_t size;
|
uint16_t size;
|
||||||
|
|
||||||
static const uint16_t MaxSize = 0xFFFF;
|
static const uint16_t MaxSize = 0xFFFF;
|
||||||
static const uint32_t MissingValue = 0x80000000;
|
static const uint32_t DefaultValue = 0x0;
|
||||||
|
|
||||||
static uint16_t growthFactor(uint16_t size);
|
static uint16_t growthFactor(uint16_t size);
|
||||||
void growByMin(uint16_t minSize);
|
void growByMin(uint16_t minSize);
|
||||||
@@ -197,10 +196,6 @@ namespace pxt {
|
|||||||
uint32_t remove(uint32_t i);
|
uint32_t remove(uint32_t i);
|
||||||
void insert(uint32_t i, uint32_t value);
|
void insert(uint32_t i, uint32_t value);
|
||||||
|
|
||||||
//Returns true if there is a valid index greater than or equal to 'i', returns false otherwise
|
|
||||||
//If 'i' is valid returns it in 'result', if not tries to find the next valid
|
|
||||||
//index < length which is valid.
|
|
||||||
bool getNextValidIndex(uint32_t i, uint32_t *result);
|
|
||||||
bool isValidIndex(uint32_t i);
|
bool isValidIndex(uint32_t i);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|||||||
@@ -51,24 +51,27 @@ namespace serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a line of text from the serial port.
|
* Reads the buffered received data as a string
|
||||||
*/
|
*/
|
||||||
//% help=serial/read-line
|
//% blockId=serial_read_buffer block="serial|read string"
|
||||||
//% blockId=serial_read_line block="serial|read line"
|
//% weight=18
|
||||||
//% weight=20 blockGap=8
|
StringData* readString() {
|
||||||
StringData* readLine() {
|
int n = uBit.serial.getRxBufferSize();
|
||||||
return readUntil(ManagedString("\n").leakData());
|
if (n == 0) return ManagedString("").leakData();
|
||||||
|
return ManagedString(uBit.serial.read(n, MicroBitSerialMode::ASYNC)).leakData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers an event to be fired when one of the delimiter is matched
|
* Registers an event to be fired when one of the delimiter is matched.
|
||||||
* @param delimiters the characters to match received characters against. eg:"\n"
|
* @param delimiters the characters to match received characters against.
|
||||||
*/
|
*/
|
||||||
// help=serial/on-data-received
|
//% help=serial/on-data-received
|
||||||
// weight=18
|
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv"
|
||||||
void onDataReceived(StringData* delimiters, Action body) {
|
void onDataReceived(StringData* delimiters, Action body) {
|
||||||
uBit.serial.eventOn(ManagedString(delimiters));
|
uBit.serial.eventOn(ManagedString(delimiters));
|
||||||
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
|
||||||
|
// lazy initialization of serial buffers
|
||||||
|
uBit.serial.read(MicroBitSerialMode::ASYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,20 +38,20 @@ namespace serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers an event to be fired when a line has been received
|
* Reads a line of text from the serial port.
|
||||||
*/
|
*/
|
||||||
// help=serial/on-line-received
|
//% help=serial/read-line
|
||||||
// blockId=serial_on_line_received block="serial on line received"
|
//% blockId=serial_read_line block="serial|read line"
|
||||||
// weight=21 blockGap=8
|
//% weight=20 blockGap=8
|
||||||
export function onLineReceived(body: Action): void {
|
export function readLine(): string {
|
||||||
// serial.onDataReceived("\n", body);
|
return serial.readUntil(delimiters(Delimiters.NewLine));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the delimiter corresponding string
|
* Returns the delimiter corresponding string
|
||||||
*/
|
*/
|
||||||
//% blockId="serial_delimiter_conv" block="%del"
|
//% blockId="serial_delimiter_conv" block="%del"
|
||||||
//% weight=1
|
//% weight=1 blockHidden=true
|
||||||
export function delimiters(del: Delimiters): string {
|
export function delimiters(del: Delimiters): string {
|
||||||
// even though it might not look like, this is more
|
// even though it might not look like, this is more
|
||||||
// (memory) efficient than the C++ implementation, because the
|
// (memory) efficient than the C++ implementation, because the
|
||||||
|
|||||||
17
libs/core/shims.d.ts
vendored
17
libs/core/shims.d.ts
vendored
@@ -672,12 +672,19 @@ declare namespace serial {
|
|||||||
function readUntil(delimiter: string): string;
|
function readUntil(delimiter: string): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a line of text from the serial port.
|
* Reads the buffered received data as a string
|
||||||
*/
|
*/
|
||||||
//% help=serial/read-line
|
//% blockId=serial_read_buffer block="serial|read string"
|
||||||
//% blockId=serial_read_line block="serial|read line"
|
//% weight=18 shim=serial::readString
|
||||||
//% weight=20 blockGap=8 shim=serial::readLine
|
function readString(): string;
|
||||||
function readLine(): string;
|
|
||||||
|
/**
|
||||||
|
* Registers an event to be fired when one of the delimiter is matched.
|
||||||
|
* @param delimiters the characters to match received characters against.
|
||||||
|
*/
|
||||||
|
//% help=serial/on-data-received
|
||||||
|
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv" shim=serial::onDataReceived
|
||||||
|
function onDataReceived(delimiters: string, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a piece of text through Serial connection.
|
* Sends a piece of text through Serial connection.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pxt-microbit",
|
"name": "pxt-microbit",
|
||||||
"version": "0.7.21",
|
"version": "0.7.36",
|
||||||
"description": "micro:bit target for PXT",
|
"description": "micro:bit target for PXT",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"JavaScript",
|
"JavaScript",
|
||||||
@@ -36,6 +36,6 @@
|
|||||||
"semantic-ui-less": "^2.2.4"
|
"semantic-ui-less": "^2.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-core": "0.8.11"
|
"pxt-core": "0.10.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,8 @@
|
|||||||
"logicBlocks": true,
|
"logicBlocks": true,
|
||||||
"variablesBlocks": true,
|
"variablesBlocks": true,
|
||||||
"onStartColor": "#0078D7",
|
"onStartColor": "#0078D7",
|
||||||
"onStartNamespace": "basic"
|
"onStartNamespace": "basic",
|
||||||
|
"onStartWeight": 54
|
||||||
},
|
},
|
||||||
"simulator": {
|
"simulator": {
|
||||||
"autoRun": true,
|
"autoRun": true,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace pxsim {
|
|||||||
radioState: RadioState;
|
radioState: RadioState;
|
||||||
// TODO: not singletons
|
// TODO: not singletons
|
||||||
neopixelState: NeoPixelState;
|
neopixelState: NeoPixelState;
|
||||||
servosState: MicroServosState;
|
|
||||||
fileSystem: FileSystemState;
|
fileSystem: FileSystemState;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -53,7 +52,13 @@ namespace pxsim {
|
|||||||
0,
|
0,
|
||||||
DAL.MICROBIT_ID_IO_P19,
|
DAL.MICROBIT_ID_IO_P19,
|
||||||
DAL.MICROBIT_ID_IO_P20
|
DAL.MICROBIT_ID_IO_P20
|
||||||
]
|
],
|
||||||
|
servos: {
|
||||||
|
"P0": DAL.MICROBIT_ID_IO_P0,
|
||||||
|
"P1": DAL.MICROBIT_ID_IO_P1,
|
||||||
|
"P2": DAL.MICROBIT_ID_IO_P2,
|
||||||
|
"P3": DAL.MICROBIT_ID_IO_P3
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.builtinParts["radio"] = this.radioState = new RadioState(runtime);
|
this.builtinParts["radio"] = this.radioState = new RadioState(runtime);
|
||||||
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
this.builtinParts["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
|
||||||
@@ -62,12 +67,7 @@ namespace pxsim {
|
|||||||
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
||||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||||
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
|
this.builtinParts["microservo"] = this.edgeConnectorState;
|
||||||
"P0": DAL.MICROBIT_ID_IO_P0,
|
|
||||||
"P1": DAL.MICROBIT_ID_IO_P1,
|
|
||||||
"P2": DAL.MICROBIT_ID_IO_P2,
|
|
||||||
"P3": DAL.MICROBIT_ID_IO_P3
|
|
||||||
});
|
|
||||||
|
|
||||||
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ namespace pxsim.pins {
|
|||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
|
|
||||||
analogSetPeriod(pinId, 20000);
|
analogSetPeriod(pinId, 20000);
|
||||||
const state = board().servosState.servoState(pinId);
|
pin.servoAngle = value;
|
||||||
state.setAngle(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function servoSetPulse(pinId: number, micros: number) {
|
export function servoSetPulse(pinId: number, micros: number) {
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ namespace pxsim.basic {
|
|||||||
clearScreen();
|
clearScreen();
|
||||||
pause(interval * 5);
|
pause(interval * 5);
|
||||||
} else {
|
} else {
|
||||||
if (s.length == 1) showLeds(createImageFromString(s + " "), interval * 5)
|
if (s.length == 1) showLeds(createImageFromString(s), 0);
|
||||||
else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval);
|
else ImageMethods.scrollImage(createImageFromString(s + " "), 1, interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,14 @@ namespace pxsim.serial {
|
|||||||
board().writeSerial(s);
|
board().writeSerial(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readUntil(del: string): string {
|
||||||
|
return readString();
|
||||||
|
}
|
||||||
|
|
||||||
export function readString(): string {
|
export function readString(): string {
|
||||||
return board().serialState.readSerial();
|
return board().serialState.readSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readLine(): string {
|
|
||||||
return board().serialState.readSerial();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function readUntil(del: string): string {
|
|
||||||
return readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function onDataReceived(delimiters: string, handler: RefAction) {
|
export function onDataReceived(delimiters: string, handler: RefAction) {
|
||||||
let b = board();
|
let b = board();
|
||||||
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);
|
||||||
|
|||||||
@@ -1,56 +1,3 @@
|
|||||||
/*******************************
|
/*******************************
|
||||||
Site Overrides
|
Site Overrides
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|
||||||
.ui.loader:before {
|
|
||||||
border: none;
|
|
||||||
border-radius: 0px;
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ui.loader:after {
|
|
||||||
border: none;
|
|
||||||
box-shadow: none;
|
|
||||||
border-radius: 0px;
|
|
||||||
margin: 40px auto;
|
|
||||||
background: transparent data-uri("static/loader.svg") no-repeat center center;
|
|
||||||
background-size: 100%;
|
|
||||||
-webkit-animation: loader-pxt @loaderSpeed infinite ease-in-out;
|
|
||||||
animation: loader-pxt @loaderSpeed infinite ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@-webkit-keyframes loader-pxt {
|
|
||||||
0% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
opacity: 0}
|
|
||||||
15% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(-@loaderAngle);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(-@loaderAngle); }
|
|
||||||
50% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(@loaderAngle);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(@loaderAngle);
|
|
||||||
opacity: 1}
|
|
||||||
100% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
opacity: 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes loader-pxt {
|
|
||||||
0% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
opacity: 0}
|
|
||||||
15% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(-10deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(-10deg); }
|
|
||||||
50% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(10deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(10deg);
|
|
||||||
opacity: 1}
|
|
||||||
100% {
|
|
||||||
-webkit-transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
transform: perspective(160px) rotateX(0deg) rotateY(0deg);
|
|
||||||
opacity: 0}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,3 @@
|
|||||||
/*******************************
|
/*******************************
|
||||||
User Variable Overrides
|
User Variable Overrides
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|
||||||
@loaderSpeed: 2s;
|
|
||||||
@loaderAngle: 5deg;
|
|
||||||
|
|
||||||
@large : 200px;
|
|
||||||
@@ -29,10 +29,18 @@
|
|||||||
&:extend(.orange all);
|
&:extend(.orange all);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ui.button.editortools-btn {
|
||||||
|
&:extend(.blue all);
|
||||||
|
}
|
||||||
|
|
||||||
#filelist, #editortools {
|
#filelist, #editortools {
|
||||||
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
|
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#downloadArea {
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
Blockly
|
Blockly
|
||||||
*******************************/
|
*******************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user