From dff4f3adb3f21b022a728db551535ce40d2c644a Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 11 Oct 2016 22:58:53 -0700 Subject: [PATCH] basic motor block support --- libs/core/enums.d.ts | 2 ++ libs/core/motors.cpp | 17 +++++++++++++++++ libs/core/parts/dcmotor.svg | 12 ++++++++++++ libs/core/pxt.json | 2 ++ libs/core/pxtparts.json | 23 ++++++++++++++++++++++- libs/core/shims.d.ts | 16 ++++++++++++++++ sim/state/soundmotor.ts | 5 +++++ 7 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 libs/core/motors.cpp create mode 100644 libs/core/parts/dcmotor.svg create mode 100644 sim/state/soundmotor.ts diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 6994d2b1..48f7509b 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -238,6 +238,8 @@ declare namespace control { // TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE } declare namespace led { +} +declare namespace motors { } diff --git a/libs/core/motors.cpp b/libs/core/motors.cpp new file mode 100644 index 00000000..2a2366f3 --- /dev/null +++ b/libs/core/motors.cpp @@ -0,0 +1,17 @@ +#include "ksbit.h" + +/** +* Blocks to control the onboard motors +*/ +//% weight=30 +namespace motors { + /** + * Controls the power sent to a single motor + * @param power %percent of power sent to the motor. Negative power goes backward. eg: 50 + */ + //% blockId=motor_on block="motor on at %percent|%" + //% parts=dcmotor + void motorOn(int power) { + uBit.soundmotor.Motor_On(power); + } +} \ No newline at end of file diff --git a/libs/core/parts/dcmotor.svg b/libs/core/parts/dcmotor.svg new file mode 100644 index 00000000..8603d301 --- /dev/null +++ b/libs/core/parts/dcmotor.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/core/pxt.json b/libs/core/pxt.json index bc9b082a..359cb75c 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -22,6 +22,7 @@ "game.ts", "led.cpp", "led.ts", + "motors.cpp", "music.ts", "pins.cpp", "pins.ts", @@ -31,6 +32,7 @@ "pxtparts.json", "parts/speaker.svg", "parts/headphone.svg", + "parts/dcmotor.svg", "_locales/fr/microbit-jsdoc-strings.json" ], "public": true, diff --git a/libs/core/pxtparts.json b/libs/core/pxtparts.json index 4afc3f78..c1bbde2f 100644 --- a/libs/core/pxtparts.json +++ b/libs/core/pxtparts.json @@ -144,5 +144,26 @@ {"part": true, "pinIndices": [0]}, {"pinIndices": [1]} ] - } + }, + "dcmotor": { + "numberOfPins": 2, + "visual": { + "image": "parts/dcmotor.svg", + "width": 488, + "height": 836, + "pinDistance": 65, + "pinLocations": [ + {"x": 89, "y": 48}, + {"x": 395, "y": 48} ] + }, + "pinDefinitions": [ + { "target": "P1", "style": "croc", "orientation": "-Z"}, + { "target": "ground", "style": "croc", "orientation": "-Z"} + ], + "instantiation": {"kind": "singleton"}, + "assembly": [ + {"part": true, "pinIndices": [0]}, + {"pinIndices": [1]} + ] + } } \ No newline at end of file diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index a6f67489..5c6cf686 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -508,6 +508,22 @@ declare namespace led { //% parts="ledmatrix" shim=led::screenshot function screenshot(): Image; } + + + /** + * Blocks to control the onboard motors + */ + //% weight=30 +declare namespace motors { + + /** + * Controls the power sent to a single motor + * @param power %percent of power sent to the motor. Negative power goes backward. eg: 50 + */ + //% blockId=motor_on block="motor on at %percent|%" + //% parts=dcmotor shim=motors::motorOn + function motorOn(power: number): void; +} declare namespace pins { /** diff --git a/sim/state/soundmotor.ts b/sim/state/soundmotor.ts new file mode 100644 index 00000000..71f4386b --- /dev/null +++ b/sim/state/soundmotor.ts @@ -0,0 +1,5 @@ +namespace pxsim.motors { + export function motorOn(power: number) { + // TODO + } +}