Compare commits

...

43 Commits

Author SHA1 Message Date
Peli de Halleux
57082654a9 0.7.36 2017-01-17 14:55:44 -08:00
Peli de Halleux
8cbf7d38e3 0.7.35 2017-01-17 14:51:28 -08:00
Peli de Halleux
a99a7325bf 0.7.34 2017-01-17 14:13:06 -08:00
Peli de Halleux
fa3ed9dd21 0.7.33 2017-01-17 11:37:35 -08:00
Peli de Halleux
45fd40a553 adding on pin pressed in getting-started 2017-01-17 11:37:20 -08:00
Peli de Halleux
5a18bea9eb 0.7.32 2017-01-17 11:28:38 -08:00
Peli de Halleux
d310312841 Bump pxt-core to 0.10.8 2017-01-17 11:28:35 -08:00
Peli de Halleux
a4b93f7199 support for deletable on start 2017-01-17 11:18:22 -08:00
Sam El-Husseini
538a4b7bbf 0.7.31 2017-01-13 18:11:03 -08:00
Sam El-Husseini
0078e7bc12 Bump pxt-core to 0.10.7 2017-01-13 18:11:02 -08:00
Sam El-Husseini
d2726133a9 Revert "Control event value in simulator (#343)"
This reverts commit 00f4c9cbb3.
2017-01-13 18:04:38 -08:00
chmora
00f4c9cbb3 Control event value in simulator (#343)
* implement pxsim.control.eventValue and pxsim.control.eventTimestamp in the simulator
2017-01-13 16:46:52 -08:00
Sam El-Husseini
e15da5dee1 0.7.30 2017-01-13 15:47:16 -08:00
Sam El-Husseini
85dda4ea84 Bump pxt-core to 0.10.4 2017-01-13 15:47:15 -08:00
Guillaume Jenkins
a3ffe4e1cf Set latest Electron to 0.7.29 (#342) 2017-01-13 14:11:46 -08:00
Sam El-Husseini
90c4d4f73b 0.7.29 2017-01-13 13:55:44 -08:00
Sam El-Husseini
6484d559d6 Bump pxt-core to 0.10.2 2017-01-13 13:55:43 -08:00
Peli de Halleux
357436f14d refactored servostate (#341)
* refactored servostate

* Bump pxt-core to 0.10.1
2017-01-12 23:09:53 -08:00
Peli de Halleux
85fe96b3fd 0.7.28 2017-01-12 16:08:35 -08:00
Peli de Halleux
cdac932c42 Bump pxt-core to 0.9.5 2017-01-12 16:08:32 -08:00
Peli de Halleux
dcfc2a110d Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2017-01-12 16:07:19 -08:00
Peli de Halleux
e9561f54c3 removing custom loader logic 2017-01-12 16:07:10 -08:00
chmora
86f6b58d38 fix"string compare works differently in simulator/on target" (#340)
* fix for "string compare works differently in simulator/on target", fixes #901
2017-01-12 15:50:39 -08:00
Peli de Halleux
eee52a5c04 0.7.27 2017-01-12 15:27:07 -08:00
Peli de Halleux
1a0b0eac71 Bump pxt-core to 0.9.4 2017-01-12 15:27:04 -08:00
Peli de Halleux
5a98ae0bb8 0.7.26 2017-01-12 11:54:33 -08:00
Peli de Halleux
a9eea9a618 Bump pxt-core to 0.9.3 2017-01-12 11:54:30 -08:00
Peli de Halleux
3086c521e3 0.7.25 2017-01-12 11:33:08 -08:00
Peli de Halleux
6788f79650 Bump pxt-core to 0.9.2 2017-01-12 11:33:05 -08:00
Sam El-Husseini
5900239045 changing editor button colors 2017-01-12 10:45:39 -08:00
Peli de Halleux
248267ec2c 0.7.24 2017-01-10 17:47:09 -08:00
Peli de Halleux
9429075555 Bump pxt-core to 0.8.14 2017-01-10 17:47:07 -08:00
Peli de Halleux
1fa871f2e7 Support for serial events (#339)
* added "serial->on data received"

* updated info

* updated docs

* added readline to read entire buffer

* lazy initialize of serial buffers

* init async on event

* updated docs
2017-01-10 16:27:02 -08:00
chmora
04dab7df2c One letter showString shouldn't disappear (#338)
* Fix for "One letter showString shouldn't disappear", fixes #798

* miss semicolon
2017-01-10 16:25:40 -08:00
Guillaume Jenkins
b6474467bc Electron release (#333)
Set latest Electron app release to 0.7.23
2017-01-10 14:16:13 -08:00
Peli de Halleux
79ead74af4 0.7.23 2017-01-10 10:31:04 -08:00
Peli de Halleux
0f8ff95b72 Bump pxt-core to 0.8.13 2017-01-10 10:30:58 -08:00
Peli de Halleux
05028c4527 Serial events (#337)
* added "serial->on data received"

* updated info

* updated docs

* added readline to read entire buffer

* lazy initialize of serial buffers

* init async on event

* updated docs
2017-01-10 10:26:44 -08:00
Peli de Halleux
4054da3483 0.7.22 2017-01-09 21:33:47 -08:00
Peli de Halleux
7052d27d6d Bump pxt-core to 0.8.12 2017-01-09 21:33:44 -08:00
Abhijith Chatra
365af8d672 Merge pull request #335 from Microsoft/default
Default values for array
2017-01-09 20:35:56 -08:00
Brahma Giri Abhijith Chatra
c938618d29 adding default values for beyond the array.length access 2017-01-08 19:08:09 -08:00
Abhijith
91321dab83 Support for default values in array. 2017-01-08 18:43:14 -08:00
23 changed files with 174 additions and 190 deletions

View File

@@ -7,8 +7,11 @@ serial.writeLine("");
serial.writeNumber(0);
serial.writeValue("x", 0);
serial.writeString("");
serial.readUntil(",");
serial.readLine();
serial.readString();
serial.redirect(SerialPin.P0, SerialPin.P0, BaudRate.BaudRate115200);
serial.onDataReceived(",", () => {})
```
### See Also

View 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)

View 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)

View File

@@ -31,6 +31,7 @@ and press **A** to scroll your text.
### Step 5
Place more blocks to display a smiley when button **B** is pressed.
Use the dropdown to find ``B``!
```block
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))
})
```

View File

@@ -1,9 +1,9 @@
{
"versions": {
"0": {
"latest": "v0.6.45",
"latest": "v0.7.29",
"banned": [],
"prompt": "v0.0.0"
"prompt": "v0.7.29"
}
}
}

View File

@@ -1,3 +1,4 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="pxt-on-start"></block>
<block type="device_forever"></block>
</xml>

View File

@@ -231,8 +231,10 @@
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
"serial": "Reading and writing data over a serial connection.",
"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.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|param|delimiter": "text delimiter that separates each text chunk",
"serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.",

View File

@@ -171,7 +171,9 @@
"pins.spiWrite|block": "spi write %value",
"pins|block": "pins",
"serial.delimiters|block": "%del",
"serial.onDataReceived|block": "serial|on data received %delimiters=serial_delimiter_conv",
"serial.readLine|block": "serial|read line",
"serial.readString|block": "serial|read string",
"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.writeLine|block": "serial|write line %text",

View File

@@ -21,7 +21,12 @@ namespace String_ {
//%
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;
}
//%

View File

@@ -150,15 +150,9 @@ namespace pxt {
if (i < length)
{
if (data[i] != Segment::MissingValue)
{
return data[i];
}
error(ERR_MISSING_VALUE);
return 0;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
return Segment::DefaultValue;
}
void Segment::set(uint32_t i, uint32_t value)
@@ -223,12 +217,8 @@ namespace pxt {
{
memcpy(tmp, data, size * sizeof(uint32_t));
}
//fill the rest with missing values;
for(uint16_t i = size; i < newSize; i++)
{
tmp[i] = Segment::MissingValue;
}
//fill the rest with default value
memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t));
//free older segment;
::operator delete(data);
@@ -280,12 +270,11 @@ namespace pxt {
if (length > 0)
{
uint32_t value = data[length];
data[length] = Segment::MissingValue;
data[length] = Segment::DefaultValue;
--length;
return value;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
return Segment::DefaultValue;
}
//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));
}
length--;
data[length] = Segment::MissingValue;
data[length] = Segment::DefaultValue;
#ifdef DEBUG_BUILD
printf("After Segment::remove index:%u\n", i);
this->print();
#endif
return ret;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
return Segment::DefaultValue;
}
//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)
{
if (i > length || data[i] == Segment::MissingValue)
if (i > length)
{
return false;
}
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()
{
#ifdef DEBUG_BUILD
@@ -415,29 +384,16 @@ namespace pxt {
uint32_t RefCollection::getAt(int i)
{
if (head.isValidIndex(i))
uint32_t tmp = head.get(i);
if (isRef())
{
uint32_t tmp = head.get(i);
if (isRef())
{
incr(tmp);
}
return tmp;
}
else
{
error(ERR_OUT_OF_BOUNDS);
return 0;
incr(tmp);
}
return tmp;
}
uint32_t RefCollection::removeAt(int i)
{
if (!head.isValidIndex((uint32_t)i))
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
if (isRef())
{
decr(head.get(i));
@@ -447,18 +403,11 @@ namespace pxt {
void RefCollection::insertAt(int i, uint32_t value)
{
if (i < length())
head.insert(i, value);
if (isRef())
{
head.insert(i, value);
if (isRef())
{
incr(value);
}
}
else
{
error(ERR_OUT_OF_BOUNDS);
}
incr(value);
}
}
void RefCollection::setAt(int i, uint32_t value)
@@ -480,26 +429,31 @@ namespace pxt {
{
StringData *xx = (StringData*)x;
uint32_t i = start;
while(head.getNextValidIndex(start, &i))
while(head.isValidIndex(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;
}
start = i;
i++;
}
}
else
{
uint32_t i = start;
while(head.getNextValidIndex(start, &i))
while(head.isValidIndex(i))
{
if (head.get(i) == x)
{
return (int)i;
}
start = i;
i++;
}
}
@@ -550,12 +504,9 @@ namespace pxt {
{
if (this->isRef())
{
uint32_t start = 0;
uint32_t i = 0;
while(head.getNextValidIndex(start, &i))
for(uint32_t i = 0; i < this->head.getLength(); i++)
{
decr(this->head.get(i));
start = i;
}
}
this->head.destroy();

View File

@@ -38,7 +38,6 @@ namespace pxt {
ERR_OUT_OF_BOUNDS = 8,
ERR_REF_DELETED = 7,
ERR_SIZE = 9,
ERR_MISSING_VALUE = 10,
} ERROR;
extern const uint32_t functionsAndBytecode[];
@@ -175,7 +174,7 @@ namespace pxt {
uint16_t size;
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);
void growByMin(uint16_t minSize);
@@ -197,10 +196,6 @@ namespace pxt {
uint32_t remove(uint32_t i);
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);
void destroy();

View File

@@ -51,24 +51,27 @@ namespace serial {
}
/**
* Reads a line of text from the serial port.
*/
//% help=serial/read-line
//% blockId=serial_read_line block="serial|read line"
//% weight=20 blockGap=8
StringData* readLine() {
return readUntil(ManagedString("\n").leakData());
* Reads the buffered received data as a string
*/
//% blockId=serial_read_buffer block="serial|read string"
//% weight=18
StringData* readString() {
int n = uBit.serial.getRxBufferSize();
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
* @param delimiters the characters to match received characters against. eg:"\n"
* 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
//% help=serial/on-data-received
//% weight=18 blockId=serial_on_data_received block="serial|on data received %delimiters=serial_delimiter_conv"
void onDataReceived(StringData* delimiters, Action body) {
uBit.serial.eventOn(ManagedString(delimiters));
registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);
// lazy initialization of serial buffers
uBit.serial.read(MicroBitSerialMode::ASYNC);
}
/**

View File

@@ -38,20 +38,20 @@ namespace serial {
}
/**
* Registers an event to be fired when a line has been received
*/
// help=serial/on-line-received
// blockId=serial_on_line_received block="serial on line received"
// weight=21 blockGap=8
export function onLineReceived(body: Action): void {
// serial.onDataReceived("\n", body);
* Reads a line of text from the serial port.
*/
//% help=serial/read-line
//% blockId=serial_read_line block="serial|read line"
//% weight=20 blockGap=8
export function readLine(): string {
return serial.readUntil(delimiters(Delimiters.NewLine));
}
/**
* Returns the delimiter corresponding string
*/
//% blockId="serial_delimiter_conv" block="%del"
//% weight=1
//% weight=1 blockHidden=true
export function delimiters(del: Delimiters): string {
// even though it might not look like, this is more
// (memory) efficient than the C++ implementation, because the

17
libs/core/shims.d.ts vendored
View File

@@ -672,12 +672,19 @@ declare namespace serial {
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_line block="serial|read line"
//% weight=20 blockGap=8 shim=serial::readLine
function readLine(): string;
//% blockId=serial_read_buffer block="serial|read string"
//% weight=18 shim=serial::readString
function readString(): 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.

View File

@@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.7.21",
"version": "0.7.36",
"description": "micro:bit target for PXT",
"keywords": [
"JavaScript",
@@ -36,6 +36,6 @@
"semantic-ui-less": "^2.2.4"
},
"dependencies": {
"pxt-core": "0.8.11"
"pxt-core": "0.10.8"
}
}

View File

@@ -72,7 +72,8 @@
"logicBlocks": true,
"variablesBlocks": true,
"onStartColor": "#0078D7",
"onStartNamespace": "basic"
"onStartNamespace": "basic",
"onStartWeight": 54
},
"simulator": {
"autoRun": true,

View File

@@ -14,7 +14,6 @@ namespace pxsim {
radioState: RadioState;
// TODO: not singletons
neopixelState: NeoPixelState;
servosState: MicroServosState;
fileSystem: FileSystemState;
constructor() {
@@ -53,7 +52,13 @@ namespace pxsim {
0,
DAL.MICROBIT_ID_IO_P19,
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["accelerometer"] = this.accelerometerState = new AccelerometerState(runtime);
@@ -62,12 +67,7 @@ namespace pxsim {
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
this.builtinParts["compass"] = this.compassState = new CompassState();
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
"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["microservo"] = this.edgeConnectorState;
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();

View File

@@ -76,8 +76,7 @@ namespace pxsim.pins {
if (!pin) return;
analogSetPeriod(pinId, 20000);
const state = board().servosState.servoState(pinId);
state.setAngle(value);
pin.servoAngle = value;
}
export function servoSetPulse(pinId: number, micros: number) {

View File

@@ -228,7 +228,7 @@ namespace pxsim.basic {
clearScreen();
pause(interval * 5);
} 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);
}
}

View File

@@ -35,18 +35,14 @@ namespace pxsim.serial {
board().writeSerial(s);
}
export function readUntil(del: string): string {
return readString();
}
export function readString(): string {
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) {
let b = board();
b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler);

View File

@@ -1,56 +1,3 @@
/*******************************
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}
}

View File

@@ -1,8 +1,3 @@
/*******************************
User Variable Overrides
*******************************/
@loaderSpeed: 2s;
@loaderAngle: 5deg;
@large : 200px;

View File

@@ -29,10 +29,18 @@
&:extend(.orange all);
}
.ui.button.editortools-btn {
&:extend(.blue all);
}
#filelist, #editortools {
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
}
#downloadArea {
background: transparent !important;
}
/*******************************
Blockly
*******************************/