moving into separate project

This commit is contained in:
Peli de Halleux
2017-11-30 09:38:04 -08:00
parent e365e3d1be
commit 3d8c697586
19 changed files with 79 additions and 57 deletions

View File

@ -74,15 +74,11 @@
"sensors.InfraredSensor.on|param|handler": "the code to run when detected",
"sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)",
"sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
"sensors.InfraredSensor.wait": "Waits for the event to occur",
"sensors.InfraredSensor.waitUntil": "Waits for the event to occur",
"sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.",
"sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down",
"sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised",
"sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.",
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters",
"sensors.UltraSonicSensor.on": "Registers code to run when the given color is close",
"sensors.UltraSonicSensor.on|param|handler": "the code to run when detected",
"sensors.UltraSonicSensor.wait": "Waits for the event to occur",
"sensors.remoteButtonBottomLeft": "Remote bottom-left button.",
"sensors.remoteButtonBottomRight": "Remote bottom-right button.",
"sensors.remoteButtonCenter": "Remote beacon (center) button.",

View File

@ -19,8 +19,6 @@
"Output.B|block": "B",
"Output.C|block": "C",
"Output.D|block": "D",
"UltrasonicSensorEvent.ObjectDetected|block": "object detected",
"UltrasonicSensorEvent.ObjectNear|block": "object near",
"brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed",
"brick.Button.onEvent|block": "on `icons.brickButtons` %button|%event",
"brick.Button.wasPressed|block": "`icons.brickButtons` %button|was pressed",
@ -63,13 +61,10 @@
"sensors.InfraredSensor.on|block": "on `icons.infraredSensor` %sensor|%event",
"sensors.InfraredSensor.proximity|block": "`icons.infraredSensor` %infrared|proximity",
"sensors.InfraredSensor.remoteCommand|block": "`icons.infraredSensor` %infrared|remote command",
"sensors.InfraredSensor.wait|block": "wait `icons.infraredSensor` %sensor|for %event",
"sensors.InfraredSensor.waitUntil|block": "wait `icons.infraredSensor` %sensor|until %event",
"sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed",
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event",
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed",
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
"sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event",
"sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event",
"sensors.gyro1|block": "1",
"sensors.gyro2|block": "2",
"sensors.gyro3|block": "3",
@ -83,10 +78,6 @@
"sensors.remoteButtonCenter|block": "center",
"sensors.remoteButtonTopLeft|block": "top-left",
"sensors.remoteButtonTopRight|block": "top-right",
"sensors.ultrasonic1|block": "1",
"sensors.ultrasonic2|block": "2",
"sensors.ultrasonic3|block": "3",
"sensors.ultrasonic4|block": "4",
"sensors|block": "sensors",
"serial|block": "serial",
"{id:category}Brick": "Brick",
@ -105,6 +96,5 @@
"{id:group}Light": "Light",
"{id:group}Motors": "Motors",
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
"{id:group}Screen": "Screen",
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
"{id:group}Screen": "Screen"
}

View File

@ -209,14 +209,14 @@ namespace sensors {
* Waits for the event to occur
*/
//% help=input/ultrasonic/wait
//% block="wait `icons.infraredSensor` %sensor|for %event"
//% block="wait `icons.infraredSensor` %sensor|until %event"
//% blockId=infraredwait
//% parts="infraredsensor"
//% blockNamespace=sensors
//% weight=99 blockGap=8
//% group="Infrared Sensor"
wait(event: InfraredSensorEvent) {
// TODO
waitUntil(event: InfraredSensorEvent) {
control.waitForEvent(this._id, event);
}
/**

View File

@ -20,7 +20,6 @@
"input.ts",
"ir.ts",
"gyro.ts",
"ultrasonic.ts",
"shims.d.ts",
"enums.d.ts",
"dal.d.ts",

View File

@ -1,100 +0,0 @@
const enum UltrasonicSensorEvent {
//% block="object near"
ObjectNear = 1,
//% block="object detected"
ObjectDetected = 2
}
namespace sensors {
//% fixedInstances
export class UltraSonicSensor extends internal.UartSensor {
private promixityThreshold: number;
private movementThreshold: number;
constructor(port: number) {
super(port)
this.promixityThreshold = 10;
this.movementThreshold = 1;
}
_deviceType() {
return DAL.DEVICE_TYPE_ULTRASONIC
}
_query(): number {
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
}
_update(prev: number, curr: number) {
// is there an object near?
if (prev >= this.promixityThreshold && curr < this.promixityThreshold)
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectNear); // TODO proper HI-LO sensor
// did something change?
if (Math.abs(prev - curr) > this.movementThreshold)
control.raiseEvent(this._id, UltrasonicSensorEvent.ObjectDetected); // TODO debouncing
}
/**
* Registers code to run when the given color is close
* @param handler the code to run when detected
*/
//% help=input/ultrasonic/on
//% blockId=ultrasonicOn
//% block="on `icons.ultrasonicSensor` %sensor|%event"
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% weight=100 blockGap=8
//% group="Ultrasonic Sensor"
on(event: UltrasonicSensorEvent, handler: () => void) {
control.onEvent(this._id, event, handler);
if (event == UltrasonicSensorEvent.ObjectNear
&& this.distance() < this.promixityThreshold)
control.runInBackground(handler);
}
/**
* Waits for the event to occur
*/
//% help=input/ultrasonic/wait
//% block="wait `icons.ultrasonicSensor` %sensor|for %event"
//% blockId=ultrasonicWait
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% weight=99 blockGap=8
//% group="Ultrasonic Sensor"
wait(event: UltrasonicSensorEvent) {
// TODO
}
/**
* Gets the distance from the sonar in millimeters
* @param sensor the ultrasonic sensor port
*/
//% help=input/ultrasonic/distance
//% block="`icons.ultrasonicSensor` %sensor|distance"
//% blockId=sonarGetDistance
//% parts="ultrasonicsensor"
//% blockNamespace=sensors
//% weight=65 blockGap=8
//% group="Ultrasonic Sensor"
distance() {
// it supposedly also has an inch mode, but we stick to cm
this._setMode(0)
return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff;
}
}
//% fixedInstance whenUsed block="1"
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
//% fixedInstance whenUsed block="4"
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
//% fixedInstance whenUsed block="2"
export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2)
//% fixedInstance whenUsed block="3"
export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
}