From ac1b811942af774f393adf2482067b75d1166cdf Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 16 Mar 2016 14:56:50 -0700 Subject: [PATCH] added "set accelerometer range" --- libs/microbit/input.ts | 37 ++++++++++++++++++++++++++++++++++++- sim/libmbit.ts | 6 ++++++ sim/state.ts | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/libs/microbit/input.ts b/libs/microbit/input.ts index f91cd1ac..7bcfc67c 100644 --- a/libs/microbit/input.ts +++ b/libs/microbit/input.ts @@ -35,6 +35,29 @@ enum TouchPins { P2, } +enum AcceleratorRange { + /** + * The accelerator measures forces up to 1 gravity + */ + //% blockId="1g" enumval=1 + OneG, + /** + * The accelerator measures forces up to 2 gravity + */ + //% blockId="2g" enumval=2 + TwoG, + /** + * The accelerator measures forces up to 4 gravity + */ + //% blockId="4g" enumval=4 + FourG, + /** + * The accelerator measures forces up to 8 gravity + */ + //% blockId="8g" enumval=8 + EightG +} + /* enum BasicGesture { @@ -207,7 +230,7 @@ namespace input { * Gets the number of milliseconds elapsed since power on. */ //% help=functions/running-time shim=micro_bit::getCurrentTime weight=50 - //% blockId=device_get_running_time block="running time (ms)" blockGap=8 icon="\uf017" + //% blockId=device_get_running_time block="running time (ms)" icon="\uf017" export function runningTime(): number { return 0; } @@ -271,4 +294,16 @@ namespace input { export function onLogoDown(body: Action): void { onGesture(Gestures.LogoDown, body); } + + /** + * Sets the accelerometer sample range in gravities. + * @param range a value describe the maximum strengh of acceleration measured + */ + //% help=functions/set-accelerator-range + //% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135" + //% weight=5 + //% shim=micro_bit::setAccelerometerRange + export function setAccelerometerRange(range : AcceleratorRange) : void { + + } } diff --git a/sim/libmbit.ts b/sim/libmbit.ts index e8301050..28effcc2 100644 --- a/sim/libmbit.ts +++ b/sim/libmbit.ts @@ -289,6 +289,12 @@ namespace ks.rt.micro_bit { default: return Math.sqrt(acc[0] * acc[0] + acc[1] * acc[1] + acc[2] * acc[2]); } } + + export function setAccelerometerRange(range : number) { + let b = board(); + b.accelerometerRange = Math.max(1, Math.min(8, range)); + b.updateView(); + } export function lightLevel(): number { let b = board(); diff --git a/sim/state.ts b/sim/state.ts index 4bfaeb77..a2d73fe3 100644 --- a/sim/state.ts +++ b/sim/state.ts @@ -167,6 +167,7 @@ namespace ks.rt.micro_bit { // sensors usesAcceleration = false; acceleration = [0, 0, -1023]; + accelerometerRange = 2; usesHeading = false; heading = 90;