From cdbc34550a8bd07c880fa571e838a24a2eb23851 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 11 Oct 2017 11:31:07 -0700 Subject: [PATCH] Various fixes (#548) * adding running time micros * support for system micro seconds * restore display mode after plotting sprites * bump pxt --- docs/reference/input.md | 1 + docs/reference/input/running-time-micros.md | 17 +++++++++++++++++ docs/reference/input/running-time.md | 2 +- libs/core/_locales/core-jsdoc-strings.json | 1 + libs/core/_locales/core-strings.json | 1 + libs/core/game.ts | 9 +++------ libs/core/input.cpp | 12 +++++++++++- libs/core/shims.d.ts | 10 +++++++++- package.json | 2 +- sim/state/misc.ts | 4 ++++ 10 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 docs/reference/input/running-time-micros.md diff --git a/docs/reference/input.md b/docs/reference/input.md index c3bc2337..cc067255 100644 --- a/docs/reference/input.md +++ b/docs/reference/input.md @@ -21,6 +21,7 @@ input.lightLevel(); input.rotation(Rotation.Pitch); input.magneticForce(Dimension.X); input.runningTime(); +input.runningTimeMicros(); input.setAccelerometerRange(AcceleratorRange.OneG); ``` diff --git a/docs/reference/input/running-time-micros.md b/docs/reference/input/running-time-micros.md new file mode 100644 index 00000000..413cf4ef --- /dev/null +++ b/docs/reference/input/running-time-micros.md @@ -0,0 +1,17 @@ +# Running Time Micros + +Find how long it has been since the program started in micro-seconds. + +```sig +input.runningTimeMicros(); +``` + +## Returns + +* the [Number](/types/number) of microseconds since the program started. +(One second is 1000000 microseconds.) + +## See also + +[show number](/reference/basic/show-number), [pause](/reference/basic/pause) + diff --git a/docs/reference/input/running-time.md b/docs/reference/input/running-time.md index db209d16..099fb640 100644 --- a/docs/reference/input/running-time.md +++ b/docs/reference/input/running-time.md @@ -1,6 +1,6 @@ # Running Time -Find how long it has been since the program started. +Find how long it has been since the program started in milli-seconds. ```sig input.runningTime(); diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index c1adf164..8ea340a1 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -179,6 +179,7 @@ "input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.", "input.rotation|param|kind": "TODO", "input.runningTime": "Gets the number of milliseconds elapsed since power on.", + "input.runningTimeMicros": "Gets the number of microseconds elapsed since power on.", "input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.", "input.setAccelerometerRange|param|range": "a value describe the maximum strengh of acceleration measured", "input.temperature": "Gets the temperature in Celsius degrees (°C).", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index fb3f9dfe..859ca87e 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -268,6 +268,7 @@ "input.onPinReleased|block": "on pin %NAME|released", "input.pinIsPressed|block": "pin %NAME|is pressed", "input.rotation|block": "rotation (°)|%NAME", + "input.runningTimeMicros|block": "running time (micros)", "input.runningTime|block": "running time (ms)", "input.setAccelerometerRange|block": "set accelerometer|range %range", "input.temperature|block": "temperature (°C)", diff --git a/libs/core/game.ts b/libs/core/game.ts index 205ee9f5..97ad0b89 100644 --- a/libs/core/game.ts +++ b/libs/core/game.ts @@ -73,16 +73,11 @@ namespace game { _backgroundAnimation = true; control.inBackground(() => { led.stopAnimation(); - const dm = led.displayMode(); - if (dm != DisplayMode.BackAndWhite) - led.setDisplayMode(DisplayMode.BackAndWhite); basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20); - if (dm != DisplayMode.BackAndWhite) - led.setDisplayMode(dm); _backgroundAnimation = false; }); } @@ -125,7 +120,6 @@ namespace game { unplugEvents(); led.stopAnimation(); led.setBrightness(255); - led.setDisplayMode(DisplayMode.BackAndWhite); while (true) { for (let i = 0; i < 8; i++) { basic.clearScreen(); @@ -777,6 +771,9 @@ namespace game { _sprites[i]._plot(now); } _img.plotImage(0); + // restore previous display mode + if (dm != DisplayMode.Greyscale) + led.setDisplayMode(dm); } /** diff --git a/libs/core/input.cpp b/libs/core/input.cpp index d6932473..63dbccf9 100644 --- a/libs/core/input.cpp +++ b/libs/core/input.cpp @@ -339,13 +339,23 @@ namespace input { /** * Gets the number of milliseconds elapsed since power on. */ - //% help=input/running-time weight=50 + //% help=input/running-time weight=50 blockGap=8 //% blockId=device_get_running_time block="running time (ms)" //% advanced=true int runningTime() { return system_timer_current_time(); } + /** + * Gets the number of microseconds elapsed since power on. + */ + //% help=input/running-time-micros weight=49 + //% blockId=device_get_running_time_micros block="running time (micros)" + //% advanced=true + int runningTimeMicros() { + return system_timer_current_time_us(); + } + /** * Obsolete, compass calibration is automatic. */ diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index f5fae3e3..9001c17b 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -332,11 +332,19 @@ declare namespace input { /** * Gets the number of milliseconds elapsed since power on. */ - //% help=input/running-time weight=50 + //% help=input/running-time weight=50 blockGap=8 //% blockId=device_get_running_time block="running time (ms)" //% advanced=true shim=input::runningTime function runningTime(): number; + /** + * Gets the number of microseconds elapsed since power on. + */ + //% help=input/running-time-micros weight=49 + //% blockId=device_get_running_time_micros block="running time (micros)" + //% advanced=true shim=input::runningTimeMicros + function runningTimeMicros(): number; + /** * Obsolete, compass calibration is automatic. */ diff --git a/package.json b/package.json index f8b4fd4a..6e1bb1d3 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,6 @@ "semantic-ui-less": "^2.2.4" }, "dependencies": { - "pxt-core": "0.14.1" + "pxt-core": "0.14.3" } } diff --git a/sim/state/misc.ts b/sim/state/misc.ts index cc16ed92..597b4720 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -86,6 +86,10 @@ namespace pxsim.input { return runtime.runningTime(); } + export function runningTimeMicros(): number { + return runtime.runningTimeUs(); + } + export function calibrateCompass() { // device calibrates... }