updated codegen with intensity/value support

This commit is contained in:
peli 2021-02-11 07:13:59 -08:00
Родитель a497ee2995
Коммит 65e0c8f584
70 изменённых файлов: 1428 добавлений и 342 удалений

Просмотреть файл

@ -4,46 +4,140 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class AccelerometerClient extends jacdac.SensorClient<[number,number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ACCELEROMETER, role, "i6.10 i6.10 i6.10");
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacaccelerometer_101_0
//% group="Accelerometer" blockSetVariable=myModule
//% blockCombine block="x" callInDebugger
get x(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacaccelerometer_101_1
//% group="Accelerometer" blockSetVariable=myModule
//% blockCombine block="y" callInDebugger
get y(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacaccelerometer_101_2
//% group="Accelerometer" blockSetVariable=myModule
//% blockCombine block="z" callInDebugger
get z(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[2];
}
/**
* Emitted when accelerometer is tilted in the given direction.
*/
//% block="tilt up" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onTiltUp(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.TiltUp, handler);
}
/**
* Emitted when accelerometer is tilted in the given direction.
*/
//% block="tilt down" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onTiltDown(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.TiltDown, handler);
}
/**
* Emitted when accelerometer is tilted in the given direction.
*/
//% block="tilt left" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onTiltLeft(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.TiltLeft, handler);
}
/**
* Emitted when accelerometer is tilted in the given direction.
*/
//% block="tilt right" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onTiltRight(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.TiltRight, handler);
}
/**
* Emitted when accelerometer is laying flat in the given direction.
*/
//% block="face up" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onFaceUp(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.FaceUp, handler);
}
/**
* Emitted when accelerometer is laying flat in the given direction.
*/
//% block="face down" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onFaceDown(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.FaceDown, handler);
}
/**
* Emitted when total force acting on accelerometer is much less than 1g.
*/
//% block="freefall" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onFreefall(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Freefall, handler);
}
/**
* Emitted when forces change violently a few times.
*/
//% block="shake" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onShake(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Shake, handler);
}
/**
* Emitted when force in any direction exceeds given threshold.
*/
//% block="force 2g" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onForce_2g(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Force_2g, handler);
}
/**
* Emitted when force in any direction exceeds given threshold.
*/
//% block="force 3g" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onForce_3g(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Force_3g, handler);
}
/**
* Emitted when force in any direction exceeds given threshold.
*/
//% block="force 6g" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onForce_6g(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Force_6g, handler);
}
/**
* Emitted when force in any direction exceeds given threshold.
*/
//% block="force 8g" blockSetVariable=myModule
//% group="Accelerometer" blockCombine
onForce_8g(handler: () => void) {
this.registerEvent(jacdac.AccelerometerEvent.Force_8g, handler);
}
}
//% fixedInstance whenUsed
export const accelerometer = new AccelerometerClient("accelerometer");
}

Просмотреть файл

@ -47,7 +47,7 @@ namespace modules {
private get(dimension: JDDimension): number {
const values = this.values();
const s = this.state;
const s = this.values;
if (!s || s.length < 6) return 0;
switch (dimension) {
case JDDimension.X:

Просмотреть файл

@ -8,7 +8,7 @@
},
"files": [
"constants.ts",
"client.ts"
"client.g.ts"
],
"supportedTargets": [
"arcade",

Просмотреть файл

@ -4,24 +4,42 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class AnalogButtonClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ANALOG_BUTTON, role, "u0.16");
}
/**
* Indicates the current pressure (``force``) on the button.
*/
//% blockId=jacdacanalogbutton_101_0
//% group="Analog Button" blockSetVariable=myModule
//% blockCombine block="pressure" callInDebugger
get pressure(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Emitted when button goes from inactive (pressure less than threshold) to active.
*/
//% block="active" blockSetVariable=myModule
//% group="Analog Button" blockCombine
onActive(handler: () => void) {
this.registerEvent(jacdac.AnalogButtonEvent.Active, handler);
}
/**
* Emitted when button goes from active (pressure higher than threshold) to inactive.
*/
//% block="inactive" blockSetVariable=myModule
//% group="Analog Button" blockCombine
onInactive(handler: () => void) {
this.registerEvent(jacdac.AnalogButtonEvent.Inactive, handler);
}
}
//% fixedInstance whenUsed
export const analogButton = new AnalogButtonClient("analog Button");
}

Просмотреть файл

@ -4,37 +4,53 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ArcadeGamepadClient extends jacdac.SensorClient<[([ArcadeGamepadButton, number])[]]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ARCADE_GAMEPAD, role, "r: u8 u0.8");
}
/**
* Indicates which buttons are currently active (pressed).
* `pressure` should be `0xff` for digital buttons, and proportional for analog ones.
*/
//% blockId=jacdacarcadegamepad_101_0
//% group="Arcade Gamepad" blockSetVariable=myModule
//% blockCombine block="button" callInDebugger
get button(): ([ArcadeGamepadButton, number])[] {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Indicates which buttons are currently active (pressed).
* `pressure` should be `0xff` for digital buttons, and proportional for analog ones.
*/
//% blockId=jacdacarcadegamepad_101_1
//% group="Arcade Gamepad" blockSetVariable=myModule
//% blockCombine block="pressure" callInDebugger
get pressure(): undefined {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Emitted when button goes from inactive to active.
*/
//% block="down" blockSetVariable=myModule
//% group="Arcade Gamepad" blockCombine
onDown(handler: () => void) {
this.registerEvent(jacdac.ArcadeGamepadEvent.Down, handler);
}
/**
* Emitted when button goes from active to inactive.
*/
//% block="up" blockSetVariable=myModule
//% group="Arcade Gamepad" blockCombine
onUp(handler: () => void) {
this.registerEvent(jacdac.ArcadeGamepadEvent.Up, handler);
}
}
//% fixedInstance whenUsed
export const arcadeGamepad = new ArcadeGamepadClient("arcade Gamepad");
}

Просмотреть файл

@ -4,13 +4,47 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class BarcodeReaderClient extends jacdac.Client {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_BARCODE_READER, role);
this._enabled = this.addRegister(jacdac.BarcodeReaderReg.Enabled, "u8");
}
}
/**
* Turns on or off the detection of barcodes.
*/
//% group="Barcode reader" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turns on or off the detection of barcodes.
*/
//% group="Barcode reader" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
/**
* Raised when a bar code is detected and decoded. If the reader detects multiple codes, it will issue multiple events.
* In case of numeric barcodes, the `data` field should contain the ASCII (which is the same as UTF8 in that case) representation of the number.
*/
//% block="detect" blockSetVariable=myModule
//% group="Barcode reader" blockCombine
onDetect(handler: () => void) {
this.registerEvent(jacdac.BarcodeReaderEvent.Detect, handler);
}
}
//% fixedInstance whenUsed
export const barcodeReader = new BarcodeReaderClient("barcode Reader");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class BarometerClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_BAROMETER, role, "u22.10");
}
/**
* The air pressure.
*/
//% blockId=jacdacbarometer_101_0
//% group="Barometer" blockSetVariable=myModule
//% blockCombine block="pressure" callInDebugger
get pressure(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const barometer = new BarometerClient("barometer");
}

Просмотреть файл

@ -4,24 +4,66 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ButtonClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_BUTTON, role, "u8");
}
/**
* Indicates whether the button is currently active (pressed).
*/
//% blockId=jacdacbutton_101_0
//% group="Button" blockSetVariable=myModule
//% blockCombine block="pressed" callInDebugger
get pressed(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Emitted when button goes from inactive (`pressed == 0`) to active.
*/
//% block="down" blockSetVariable=myModule
//% group="Button" blockCombine
onDown(handler: () => void) {
this.registerEvent(jacdac.ButtonEvent.Down, handler);
}
/**
* Emitted when button goes from active (`pressed == 1`) to inactive.
*/
//% block="up" blockSetVariable=myModule
//% group="Button" blockCombine
onUp(handler: () => void) {
this.registerEvent(jacdac.ButtonEvent.Up, handler);
}
/**
* Emitted together with `up` when the press time was not longer than 500ms.
*/
//% block="click" blockSetVariable=myModule
//% group="Button" blockCombine
onClick(handler: () => void) {
this.registerEvent(jacdac.ButtonEvent.Click, handler);
}
/**
* Emitted together with `up` when the press time was more than 500ms.
*/
//% block="long click" blockSetVariable=myModule
//% group="Button" blockCombine
onLongClick(handler: () => void) {
this.registerEvent(jacdac.ButtonEvent.LongClick, handler);
}
/**
* Emitted after the button is held for 1500ms. Hold events are followed by a separate up event.
*/
//% block="hold" blockSetVariable=myModule
//% group="Button" blockCombine
onHold(handler: () => void) {
this.registerEvent(jacdac.ButtonEvent.Hold, handler);
}
}
//% fixedInstance whenUsed
export const button = new ButtonClient("button");
}

Просмотреть файл

@ -4,13 +4,38 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class BuzzerClient extends jacdac.Client {
constructor(role: string) {
private readonly _volume : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_BUZZER, role);
this._volume = this.addRegister(jacdac.BuzzerReg.Volume, "u0.8");
}
}
/**
* The volume (duty cycle) of the buzzer.
*/
//% group="Buzzer" blockSetVariable=myModule
//% blockCombine block="volume" callInDebugger
get volume(): number {
const values = this._volume.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* The volume (duty cycle) of the buzzer.
*/
//% group="Buzzer" blockSetVariable=myModule
//% blockCombine block="volume" callInDebugger
set volume(value: number) {
const values = this._volume.values() as any[];
values[0] = value;
this._volume.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const buzzer = new BuzzerClient("buzzer");
}

Просмотреть файл

@ -4,13 +4,59 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class CharacterScreenClient extends jacdac.Client {
constructor(role: string) {
private readonly _brightness : jacdac.RegisterClient<[number]>;
private readonly _message : jacdac.RegisterClient<[string]>;
constructor(role: string) {
super(jacdac.SRV_CHARACTER_SCREEN, role);
this._brightness = this.addRegister(jacdac.CharacterScreenReg.Brightness, "u0.8");
this._message = this.addRegister(jacdac.CharacterScreenReg.Message, "s");
}
}
/**
* Brightness of the screen. `0` means off.
*/
//% group="Character Screen" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this._brightness.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Text to show. Use `\n` to break lines.
*/
//% group="Character Screen" blockSetVariable=myModule
//% blockCombine block="message" callInDebugger
get message(): string {
const values = this._message.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Brightness of the screen. `0` means off.
*/
//% group="Character Screen" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
set brightness(value: number) {
const values = this._brightness.values() as any[];
values[0] = value;
this._brightness.setValues(values as [number]);
}
/**
* Text to show. Use `\n` to break lines.
*/
//% group="Character Screen" blockSetVariable=myModule
//% blockCombine block="message" callInDebugger
set message(value: string) {
const values = this._message.values() as any[];
values[0] = value;
this._message.setValues(values as [string]);
}
}
//% fixedInstance whenUsed
export const characterScreen = new CharacterScreenClient("character Screen");
}

Просмотреть файл

@ -23,6 +23,15 @@ namespace jacdac {
*/
Message = 0x2,
/**
* Read-write ratio u0.8 (uint8_t). Brightness of the screen. `0` means off.
*
* ```
* const [brightness] = jdunpack<[number]>(buf, "u0.8")
* ```
*/
Brightness = 0x1,
/**
* Constant Variant (uint8_t). Describes the type of character LED screen.
*

Просмотреть файл

Просмотреть файл

@ -4,46 +4,44 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ColorClient extends jacdac.SensorClient<[number,number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_COLOR, role, "u0.16 u0.16 u0.16");
}
/**
* Detected color in the RGB color space.
*/
//% blockId=jacdaccolor_101_0
//% group="Color" blockSetVariable=myModule
//% blockCombine block="red" callInDebugger
get red(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Detected color in the RGB color space.
*/
//% blockId=jacdaccolor_101_1
//% group="Color" blockSetVariable=myModule
//% blockCombine block="green" callInDebugger
get green(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Detected color in the RGB color space.
*/
//% blockId=jacdaccolor_101_2
//% group="Color" blockSetVariable=myModule
//% blockCombine block="blue" callInDebugger
get blue(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[2];
}
}
}
//% fixedInstance whenUsed
export const color = new ColorClient("color");
}

Просмотреть файл

@ -4,24 +4,47 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class CompassClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_COMPASS, role, "u16.16");
this._enabled = this.addRegister(jacdac.CompassReg.Enabled, "u8");
}
/**
* The heading with respect to the magnetic north.
*/
//% blockId=jacdaccompass_101_0
//% group="Compass" blockSetVariable=myModule
//% blockCombine block="heading" callInDebugger
get heading(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn on or off the sensor. Turning on the sensor may start a calibration sequence.
*/
//% group="Compass" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn on or off the sensor. Turning on the sensor may start a calibration sequence.
*/
//% group="Compass" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const compass = new CompassClient("compass");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class DistanceClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_DISTANCE, role, "u16.16");
}
/**
* Current distance from the object
*/
//% blockId=jacdacdistance_101_0
//% group="Distance" blockSetVariable=myModule
//% blockCombine block="distance" callInDebugger
get distance(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const distance = new DistanceClient("distance");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ECO2Client extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_E_CO2, role, "u22.10");
}
/**
* Equivalent CO (eCO) readings.
*/
//% blockId=jacdaceco2_101_0
//% group="Equivalent CO₂" blockSetVariable=myModule
//% blockCombine block="e CO2" callInDebugger
get eCO2(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const eCO2 = new ECO2Client("e CO2");
}

Просмотреть файл

@ -4,46 +4,44 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class GyroscopeClient extends jacdac.SensorClient<[number,number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_GYROSCOPE, role, "i16.16 i16.16 i16.16");
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacgyroscope_101_0
//% group="Gyroscope" blockSetVariable=myModule
//% blockCombine block="x" callInDebugger
get x(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacgyroscope_101_1
//% group="Gyroscope" blockSetVariable=myModule
//% blockCombine block="y" callInDebugger
get y(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Indicates the current forces acting on accelerometer.
*/
//% blockId=jacdacgyroscope_101_2
//% group="Gyroscope" blockSetVariable=myModule
//% blockCombine block="z" callInDebugger
get z(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[2];
}
}
}
//% fixedInstance whenUsed
export const gyroscope = new GyroscopeClient("gyroscope");
}

Просмотреть файл

@ -7,24 +7,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class HeartRateClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_HEART_RATE, role, "u16.16");
}
/**
* The estimated heart rate.
*/
//% blockId=jacdacheartrate_101_0
//% group="Heart Rate" blockSetVariable=myModule
//% blockCombine block="heart rate" callInDebugger
get heartRate(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const heartRate = new HeartRateClient("heart Rate");
}

Просмотреть файл

@ -11,13 +11,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class HidKeyboardClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_HID_KEYBOARD, role);
}
}
}
//% fixedInstance whenUsed
export const hidKeyboard = new HidKeyboardClient("hid Keyboard");
}

Просмотреть файл

@ -6,13 +6,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class HidMouseClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_HID_MOUSE, role);
}
}
}
//% fixedInstance whenUsed
export const hidMouse = new HidMouseClient("hid Mouse");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class HumidityClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_HUMIDITY, role, "u22.10");
}
/**
* The relative humidity in percentage of full water saturation.
*/
//% blockId=jacdachumidity_101_0
//% group="Humidity" blockSetVariable=myModule
//% blockCombine block="humidity" callInDebugger
get humidity(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const humidity = new HumidityClient("humidity");
}

Просмотреть файл

@ -6,24 +6,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class IlluminanceClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ILLUMINANCE, role, "u22.10");
}
/**
* The amount of illuminance, as lumens per square metre.
*/
//% blockId=jacdacilluminance_101_0
//% group="Illuminance" blockSetVariable=myModule
//% blockCombine block="light" callInDebugger
get light(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const illuminance = new IlluminanceClient("illuminance");
}

Просмотреть файл

@ -4,13 +4,43 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class IotHubClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_IOT_HUB, role);
}
}
/**
* Emitted upon successful connection.
*/
//% block="connected" blockSetVariable=myModule
//% group="Azure IoT Hub" blockCombine
onConnected(handler: () => void) {
this.registerEvent(jacdac.IotHubEvent.Connected, handler);
}
/**
* Emitted when connection was lost.
*/
//% block="connection error" blockSetVariable=myModule
//% group="Azure IoT Hub" blockCombine
onConnectionError(handler: () => void) {
this.registerEvent(jacdac.IotHubEvent.ConnectionError, handler);
}
/**
* This event is emitted upon reception of a cloud to device message, that is a string
* (doesn't contain NUL bytes) and fits in a single event packet.
* For reliable reception, use the `subscribe` command above.
*/
//% block="devicebound str" blockSetVariable=myModule
//% group="Azure IoT Hub" blockCombine
onDeviceboundStr(handler: () => void) {
this.registerEvent(jacdac.IotHubEvent.DeviceboundStr, handler);
}
}
//% fixedInstance whenUsed
export const iotHub = new IotHubClient("iot Hub");
}

Просмотреть файл

@ -4,37 +4,37 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class JoystickClient extends jacdac.SensorClient<[number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_JOYSTICK, role, "i1.15 i1.15");
}
/**
* The direction of the joystick measure in two direction.
* If joystick is digital, then each direction will read as either `-0x8000`, `0x0`, or `0x7fff`.
*/
//% blockId=jacdacjoystick_101_0
//% group="Joystick" blockSetVariable=myModule
//% blockCombine block="x" callInDebugger
get x(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* The direction of the joystick measure in two direction.
* If joystick is digital, then each direction will read as either `-0x8000`, `0x0`, or `0x7fff`.
*/
//% blockId=jacdacjoystick_101_1
//% group="Joystick" blockSetVariable=myModule
//% blockCombine block="y" callInDebugger
get y(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
}
}
//% fixedInstance whenUsed
export const joystick = new JoystickClient("joystick");
}

Просмотреть файл

@ -4,13 +4,61 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class LedMatrixClient extends jacdac.Client {
constructor(role: string) {
private readonly _brightness : jacdac.RegisterClient<[number]>;
private readonly _leds : jacdac.RegisterClient<[Uint8Array]>;
constructor(role: string) {
super(jacdac.SRV_LED_MATRIX, role);
this._brightness = this.addRegister(jacdac.LedMatrixReg.Brightness, "u0.8");
this._leds = this.addRegister(jacdac.LedMatrixReg.Leds, "b");
}
}
/**
* Reads the general brightness of the LEDs. ``0`` when the screen is off.
*/
//% group="LED Matrix" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this._brightness.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* The state of the screen where pixel on/off state is
* stored as a bit, column by column. The column should be byte aligned.
*/
//% group="LED Matrix" blockSetVariable=myModule
//% blockCombine block="leds" callInDebugger
get leds(): Buffer {
const values = this._leds.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Reads the general brightness of the LEDs. ``0`` when the screen is off.
*/
//% group="LED Matrix" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
set brightness(value: number) {
const values = this._brightness.values() as any[];
values[0] = value;
this._brightness.setValues(values as [number]);
}
/**
* The state of the screen where pixel on/off state is
* stored as a bit, column by column. The column should be byte aligned.
*/
//% group="LED Matrix" blockSetVariable=myModule
//% blockCombine block="leds" callInDebugger
set leds(value: Buffer) {
const values = this._leds.values() as any[];
values[0] = value;
this._leds.setValues(values as [Buffer]);
}
}
//% fixedInstance whenUsed
export const ledMatrix = new LedMatrixClient("led Matrix");
}

Просмотреть файл

@ -4,13 +4,40 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class LedPixelClient extends jacdac.Client {
constructor(role: string) {
private readonly _brightness : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_LED_PIXEL, role);
this._brightness = this.addRegister(jacdac.LedPixelReg.Brightness, "u0.8");
}
}
/**
* Set the luminosity of the strip.
* At `0` the power to the strip is completely shut down.
*/
//% group="LED Pixel" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this._brightness.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Set the luminosity of the strip.
* At `0` the power to the strip is completely shut down.
*/
//% group="LED Pixel" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
set brightness(value: number) {
const values = this._brightness.values() as any[];
values[0] = value;
this._brightness.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const ledPixel = new LedPixelClient("led Pixel");
}

Просмотреть файл

@ -4,13 +4,40 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class LedClient extends jacdac.Client {
constructor(role: string) {
private readonly _brightness : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_LED, role);
this._brightness = this.addRegister(jacdac.LedReg.Brightness, "u0.16");
}
}
/**
* Set the luminosity of the strip. The value is used to scale `value` in `steps` register.
* At `0` the power to the strip is completely shut down.
*/
//% group="LED" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this._brightness.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Set the luminosity of the strip. The value is used to scale `value` in `steps` register.
* At `0` the power to the strip is completely shut down.
*/
//% group="LED" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
set brightness(value: number) {
const values = this._brightness.values() as any[];
values[0] = value;
this._brightness.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const led = new LedClient("led");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class LightLevelClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_LIGHT_LEVEL, role, "u0.16");
}
/**
* Detect light level
*/
//% blockId=jacdaclightlevel_101_0
//% group="Light level" blockSetVariable=myModule
//% blockCombine block="light level" callInDebugger
get lightLevel(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const lightLevel = new LightLevelClient("light Level");
}

Просмотреть файл

@ -4,49 +4,47 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MagnetometerClient extends jacdac.SensorClient<[number,number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MAGNETOMETER, role, "i32 i32 i32");
}
/**
* Indicates the current magnetic field on magnetometer.
* For reference: `1 mgauss` is `100 nT` (and `1 gauss` is `100 000 nT`).
*/
//% blockId=jacdacmagnetomer_101_0
//% group="Magnetometer" blockSetVariable=myModule
//% blockCombine block="x" callInDebugger
get x(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Indicates the current magnetic field on magnetometer.
* For reference: `1 mgauss` is `100 nT` (and `1 gauss` is `100 000 nT`).
*/
//% blockId=jacdacmagnetomer_101_1
//% group="Magnetometer" blockSetVariable=myModule
//% blockCombine block="y" callInDebugger
get y(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Indicates the current magnetic field on magnetometer.
* For reference: `1 mgauss` is `100 nT` (and `1 gauss` is `100 000 nT`).
*/
//% blockId=jacdacmagnetomer_101_2
//% group="Magnetometer" blockSetVariable=myModule
//% blockCombine block="z" callInDebugger
get z(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[2];
}
}
}
//% fixedInstance whenUsed
export const magnetometer = new MagnetometerClient("magnetometer");
}

Просмотреть файл

@ -4,25 +4,59 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MatrixKeypadClient extends jacdac.SensorClient<[number[]]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MATRIX_KEYPAD, role, "r: u8");
}
/**
* The coordinate of the button currently pressed. Keys are zero-indexed from left to right, top to bottom:
* ``row = index / columns``, ``column = index % columns``.
*/
//% blockId=jacdacmatrixkeypad_101_0
//% group="Matrix Keypad" blockSetVariable=myModule
//% blockCombine block="index" callInDebugger
get index(): number[] {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Emitted when a key, at the given index, goes from inactive (`pressed == 0`) to active.
*/
//% block="down" blockSetVariable=myModule
//% group="Matrix Keypad" blockCombine
onDown(handler: () => void) {
this.registerEvent(jacdac.MatrixKeypadEvent.Down, handler);
}
/**
* Emitted when a key, at the given index, goes from active (`pressed == 1`) to inactive.
*/
//% block="up" blockSetVariable=myModule
//% group="Matrix Keypad" blockCombine
onUp(handler: () => void) {
this.registerEvent(jacdac.MatrixKeypadEvent.Up, handler);
}
/**
* Emitted together with `up` when the press time was not longer than 500ms.
*/
//% block="click" blockSetVariable=myModule
//% group="Matrix Keypad" blockCombine
onClick(handler: () => void) {
this.registerEvent(jacdac.MatrixKeypadEvent.Click, handler);
}
/**
* Emitted together with `up` when the press time was more than 500ms.
*/
//% block="long click" blockSetVariable=myModule
//% group="Matrix Keypad" blockCombine
onLongClick(handler: () => void) {
this.registerEvent(jacdac.MatrixKeypadEvent.LongClick, handler);
}
}
//% fixedInstance whenUsed
export const matrixKeypad = new MatrixKeypadClient("matrix Keypad");
}

Просмотреть файл

@ -4,13 +4,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MicrophoneClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MICROPHONE, role);
}
}
}
//% fixedInstance whenUsed
export const microphone = new MicrophoneClient("microphone");
}

Просмотреть файл

@ -4,13 +4,38 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MidiOutputClient extends jacdac.Client {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_MIDI_OUTPUT, role);
this._enabled = this.addRegister(jacdac.MidiOutputReg.Enabled, "u8");
}
}
/**
* Opens or closes the port to the MIDI device
*/
//% group="MIDI output" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Opens or closes the port to the MIDI device
*/
//% group="MIDI output" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const midiOutput = new MidiOutputClient("midi Output");
}

Просмотреть файл

@ -8,24 +8,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ModelRunnerClient extends jacdac.SensorClient<[number[]]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MODEL_RUNNER, role, "r: f32");
}
/**
* Results of last model invocation as `float32` array.
*/
//% blockId=jacdacmodelrunner_101_0
//% group="Model Runner" blockSetVariable=myModule
//% blockCombine block="output" callInDebugger
get output(): number[] {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const modelRunner = new ModelRunnerClient("model Runner");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MotionClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MOTION, role, "u8");
}
/**
* Reports is movement is currently detected by the sensor.
*/
//% blockId=jacdacmotion_101_0
//% group="Motion" blockSetVariable=myModule
//% blockCombine block="moving" callInDebugger
get moving(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const motion = new MotionClient("motion");
}

Просмотреть файл

@ -4,13 +4,63 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MotorClient extends jacdac.Client {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
private readonly _duty : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_MOTOR, role);
this._enabled = this.addRegister(jacdac.MotorReg.Enabled, "u8");
this._duty = this.addRegister(jacdac.MotorReg.Duty, "i1.15");
}
}
/**
* Turn the power to the motor on/off.
*/
//% group="Motor" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* PWM duty cycle of the motor. Use negative/positive values to run the motor forwards and backwards.
* Positive is recommended to be clockwise rotation and negative counterclockwise. A duty of ``0``
* while ``enabled`` acts as brake.
*/
//% group="Motor" blockSetVariable=myModule
//% blockCombine block="duty" callInDebugger
get duty(): number {
const values = this._duty.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn the power to the motor on/off.
*/
//% group="Motor" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
/**
* PWM duty cycle of the motor. Use negative/positive values to run the motor forwards and backwards.
* Positive is recommended to be clockwise rotation and negative counterclockwise. A duty of ``0``
* while ``enabled`` acts as brake.
*/
//% group="Motor" blockSetVariable=myModule
//% blockCombine block="duty" callInDebugger
set duty(value: number) {
const values = this._duty.values() as any[];
values[0] = value;
this._duty.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const motor = new MotorClient("motor");
}

Просмотреть файл

@ -4,26 +4,76 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class MultitouchClient extends jacdac.SensorClient<[number[]]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_MULTITOUCH, role, "r: i32");
}
/**
* Capacitance of channels. The capacitance is continuously calibrated, and a value of `0` indicates
* no touch, wheres a value of around `100` or more indicates touch.
* It's best to ignore this (unless debugging), and use events.
*/
//% blockId=jacdacmultitouch_101_0
//% group="Multitouch" blockSetVariable=myModule
//% blockCombine block="capacitance" callInDebugger
get capacitance(): number[] {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Emitted when an input is touched.
*/
//% block="touch" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onTouch(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.Touch, handler);
}
/**
* Emitted when an input is no longer touched.
*/
//% block="release" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onRelease(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.Release, handler);
}
/**
* Emitted when an input is briefly touched. TODO Not implemented.
*/
//% block="tap" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onTap(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.Tap, handler);
}
/**
* Emitted when an input is touched for longer than 500ms. TODO Not implemented.
*/
//% block="long press" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onLongPress(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.LongPress, handler);
}
/**
* Emitted when input channels are successively touched in order of increasing channel numbers.
*/
//% block="swipe pos" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onSwipePos(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.SwipePos, handler);
}
/**
* Emitted when input channels are successively touched in order of decreasing channel numbers.
*/
//% block="swipe neg" blockSetVariable=myModule
//% group="Multitouch" blockCombine
onSwipeNeg(handler: () => void) {
this.registerEvent(jacdac.MultitouchEvent.SwipeNeg, handler);
}
}
//% fixedInstance whenUsed
export const multitouch = new MultitouchClient("multitouch");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class PotentiometerClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_POTENTIOMETER, role, "u0.16");
}
/**
* The relative position of the slider between `0` and `1`.
*/
//% blockId=jacdacpotentiometer_101_0
//% group="Potentiometer" blockSetVariable=myModule
//% blockCombine block="position" callInDebugger
get position(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const potentiometer = new PotentiometerClient("potentiometer");
}

Просмотреть файл

@ -4,24 +4,47 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class PowerClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_POWER, role, "u16");
this._enabled = this.addRegister(jacdac.PowerReg.Enabled, "u8");
}
/**
* Present current draw from the bus.
*/
//% blockId=jacdacpower_101_0
//% group="Power" blockSetVariable=myModule
//% blockCombine block="current draw" callInDebugger
get currentDraw(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn the power to the bus on/off.
*/
//% group="Power" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn the power to the bus on/off.
*/
//% group="Power" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const power = new PowerClient("power");
}

Просмотреть файл

@ -5,13 +5,65 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ProtoTestClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_PROTO_TEST, role);
}
}
/**
* An event raised when rw_bool is modified
*/
//% block="e bool" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEBool(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EBool, handler);
}
/**
* An event raised when rw_u32 is modified
*/
//% block="e u32" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEU32(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EU32, handler);
}
/**
* An event raised when rw_i32 is modified
*/
//% block="e i32" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEI32(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EI32, handler);
}
/**
* An event raised when rw_string is modified
*/
//% block="e string" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEString(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EString, handler);
}
/**
* An event raised when rw_bytes is modified
*/
//% block="e bytes" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEBytes(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EBytes, handler);
}
/**
* An event raised when rw_i8_u8_u16_i32 is modified
*/
//% block="e i8 u8 u16 i32" blockSetVariable=myModule
//% group="Protocol Test" blockCombine
onEI8U8U16I32(handler: () => void) {
this.registerEvent(jacdac.ProtoTestEvent.EI8U8U16I32, handler);
}
}
//% fixedInstance whenUsed
export const protoTest = new ProtoTestClient("proto Test");
}

Просмотреть файл

@ -6,24 +6,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class PulseOximeterClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_PULSE_OXIMETER, role, "u8.8");
}
/**
* The estimated oxygen level in blood.
*/
//% blockId=jacdacpulseoximeter_101_0
//% group="Pulse Oximeter" blockSetVariable=myModule
//% blockCombine block="oxygen" callInDebugger
get oxygen(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const pulseOximeter = new PulseOximeterClient("pulse Oximeter");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RainGaugeClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_RAIN_GAUGE, role, "u16.16");
}
/**
* Total precipitation recorded so far.
*/
//% blockId=jacdacraingauge_101_0
//% group="Rain gauge" blockSetVariable=myModule
//% blockCombine block="precipitation" callInDebugger
get precipitation(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const rainGauge = new RainGaugeClient("rain Gauge");
}

Просмотреть файл

@ -4,111 +4,101 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RealTimeClockClient extends jacdac.SensorClient<[number,number,number,number,number,number,number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_REAL_TIME_CLOCK, role, "u16 u8 u8 u8 u8 u8 u8");
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_0
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="year" callInDebugger
get year(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_1
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="month" callInDebugger
get month(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[1];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_2
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="day of month" callInDebugger
get dayOfMonth(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[2];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_3
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="day of week" callInDebugger
get dayOfWeek(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[3];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_4
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="hour" callInDebugger
get hour(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[4];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_5
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="min" callInDebugger
get min(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[5];
}
/**
* Current time in 24h representation.
* * ``day_of_month`` is day of the month, starting at ``1``
* * ``day_of_week`` is day of the week, starting at ``1`` as monday
* Default streaming period is 1 second.
*/
//% blockId=jacdacrealtimeclock_101_6
//% group="Real time clock" blockSetVariable=myModule
//% blockCombine block="sec" callInDebugger
get sec(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[6];
}
}
}
//% fixedInstance whenUsed
export const realTimeClock = new RealTimeClockClient("real Time Clock");
}

Просмотреть файл

@ -4,24 +4,42 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ReflectedLightClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_REFLECTED_LIGHT, role, "u0.16");
}
/**
* Reports the reflected brightness. It may be a digital value or, for some sensor, analog value.
*/
//% blockId=jacdacreflectedlight_101_0
//% group="Reflected light" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* The sensor detected a transition from light to dark
*/
//% block="dark" blockSetVariable=myModule
//% group="Reflected light" blockCombine
onDark(handler: () => void) {
this.registerEvent(jacdac.ReflectedLightEvent.Dark, handler);
}
/**
* The sensor detected a transition from dark to light
*/
//% block="light" blockSetVariable=myModule
//% group="Reflected light" blockCombine
onLight(handler: () => void) {
this.registerEvent(jacdac.ReflectedLightEvent.Light, handler);
}
}
//% fixedInstance whenUsed
export const reflectedLight = new ReflectedLightClient("reflected Light");
}

Просмотреть файл

@ -4,13 +4,54 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RelayClient extends jacdac.Client {
constructor(role: string) {
private readonly _closed : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_RELAY, role);
this._closed = this.addRegister(jacdac.RelayReg.Closed, "u8");
}
}
/**
* Indicates whether the relay circuit is currently on (closed) or off (closed).
*/
//% group="Relay" blockSetVariable=myModule
//% blockCombine block="closed" callInDebugger
get closed(): number {
const values = this._closed.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Indicates whether the relay circuit is currently on (closed) or off (closed).
*/
//% group="Relay" blockSetVariable=myModule
//% blockCombine block="closed" callInDebugger
set closed(value: number) {
const values = this._closed.values() as any[];
values[0] = value;
this._closed.setValues(values as [number]);
}
/**
* Emitted when relay goes from ``off`` to ``on`` state.
*/
//% block="on" blockSetVariable=myModule
//% group="Relay" blockCombine
onOn(handler: () => void) {
this.registerEvent(jacdac.RelayEvent.On, handler);
}
/**
* Emitted when relay goes from ``on`` to ``off`` state.
*/
//% block="off" blockSetVariable=myModule
//% group="Relay" blockCombine
onOff(handler: () => void) {
this.registerEvent(jacdac.RelayEvent.Off, handler);
}
}
//% fixedInstance whenUsed
export const relay = new RelayClient("relay");
}

Просмотреть файл

@ -7,13 +7,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RngClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_RNG, role);
}
}
}
//% fixedInstance whenUsed
export const rng = new RngClient("rng");
}

Просмотреть файл

@ -15,13 +15,25 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RoleManagerClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ROLE_MANAGER, role);
}
}
/**
* Emit notifying that the internal state of the service changed.
*/
//% block="change" blockSetVariable=myModule
//% group="Role Manager" blockCombine
onChange(handler: () => void) {
this.registerEvent(jacdac.RoleManagerEvent.Change, handler);
}
}
//% fixedInstance whenUsed
export const roleManager = new RoleManagerClient("role Manager");
}

Просмотреть файл

@ -4,25 +4,27 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class RotaryEncoderClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_ROTARY_ENCODER, role, "i32");
}
/**
* Upon device reset starts at `0` (regardless of the shaft position).
* Increases by `1` for a clockwise "click", by `-1` for counter-clockwise.
*/
//% blockId=jacdacrotaryencoder_101_0
//% group="Rotary encoder" blockSetVariable=myModule
//% blockCombine block="position" callInDebugger
get position(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const rotaryEncoder = new RotaryEncoderClient("rotary Encoder");
}

Просмотреть файл

@ -272,6 +272,51 @@ namespace jacdac {
[index: string]: T;
}
export class RegisterClient<TValues extends (string | number | Buffer)[]> {
private data: Buffer;
private _localTime: number;
private _dataChangedHandler: () => void;
constructor(
public readonly service: Client,
public readonly code: number,
public readonly packFormat: string,
defaultValue?: TValues) {
this.data = defaultValue && jdpack(this.packFormat, defaultValue) || Buffer.create(0);
this._localTime = control.millis()
}
values(): TValues {
return jdunpack(this.data, this.packFormat) as TValues;
}
setValues(values: TValues) {
const d = jdpack(this.packFormat, values);
this.data = d;
// send set request to the service
this.service.setReg(this.code, this.packFormat, values);
}
get lastGetTime() {
return this._localTime;
}
onDataChanged(handler: () => void) {
this._dataChangedHandler = handler;
}
handlePacket(packet: JDPacket): void {
if (packet.isRegGet && this.code !== packet.regCode) {
const d = packet.data
const changed = !d.equals(this.data);
this.data = d;
this._localTime = control.millis();
if (changed && this._dataChangedHandler)
this._dataChangedHandler();
}
}
}
//% fixedInstances
export class Client {
device: Device
@ -286,6 +331,7 @@ namespace jacdac {
protected systemActive = false;
protected readonly config: ClientPacketQueue
private readonly registers: RegisterClient<(string | number | Buffer)[]>[] = [];
constructor(
public readonly serviceClass: number,
@ -297,6 +343,19 @@ namespace jacdac {
throw "no role"
}
protected addRegister<TValues extends (string | number | Buffer)[]>(code: number, packFormat: string, defaultValues?: TValues): RegisterClient<TValues> {
let reg = this.registers.find(reg => reg.code === code);
if (!reg) {
reg = new RegisterClient<TValues>(this, code, packFormat, defaultValues);
this.registers.push(reg);
}
return reg as RegisterClient<TValues>;
}
register(code: number) {
return this.registers.find(reg => reg.code === code);
}
broadcastDevices() {
return devices().filter(d => d.clients.indexOf(this) >= 0)
}
@ -320,6 +379,8 @@ namespace jacdac {
this.raiseEvent(code, pkt.intData)
}
for(const register of this.registers)
register.handlePacket(pkt);
this.handlePacket(pkt)
}

Просмотреть файл

@ -5,24 +5,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SensorAggregatorClient extends jacdac.SensorClient<[Buffer]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_SENSOR_AGGREGATOR, role, "b");
}
/**
* Last collected sample.
*/
//% blockId=jacdacsensoraggregator_101_0
//% group="Sensor Aggregator" blockSetVariable=myModule
//% blockCombine block="current sample" callInDebugger
get currentSample(): Buffer {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const sensorAggregator = new SensorAggregatorClient("sensor Aggregator");
}

Просмотреть файл

@ -2,26 +2,19 @@ namespace jacdac {
//% fixedInstances
//% weight=1
export class SensorClient<TReading extends (string | number | Buffer)[]> extends Client {
// virtual mode only
protected _localTime: number;
protected _lastState: Buffer;
readonly reading: RegisterClient<TReading>
private _stateChangedHandler: () => void;
public isStreaming = false
constructor(deviceClass: number, role: string, protected readonly stateFormat: string) {
constructor(deviceClass: number, role: string, stateFormat: string) {
super(deviceClass, role);
this._lastState = control.createBuffer(0);
}
public get state() {
this.start();
return this._lastState;
this.reading = this.addRegister(SystemReg.Reading, stateFormat)
}
public values(): TReading {
const unpacked = jdunpack(this.state, this.stateFormat) as TReading;
return unpacked;
this.start();
return this.reading.values()
}
announceCallback() {
@ -49,34 +42,9 @@ namespace jacdac {
}
public onStateChanged(handler: () => void) {
this._stateChangedHandler = handler;
this.reading.onDataChanged(handler);
this.start();
}
handlePacket(packet: JDPacket) {
// this.log(`vpkt ${packet.service_command}`)
switch (packet.serviceCommand) {
case CMD_GET_REG | SystemReg.Reading: {
const state = packet.data
const changed = !state.equals(this._lastState);
this.handleVirtualState(state);
this._lastState = state;
this._localTime = control.millis();
if (changed && this._stateChangedHandler)
this._stateChangedHandler();
break
}
default:
this.handleCustomCommand(packet);
break
}
}
protected handleCustomCommand(pkt: JDPacket) {
}
protected handleVirtualState(state: Buffer) {
}
}
export class BufferedSensorClient<TReading extends (string | number | Buffer)[]> extends SensorClient<TReading> {
@ -104,7 +72,7 @@ namespace jacdac {
handlePacket(packet: JDPacket) {
if (this._samples && packet.serviceCommand == (CMD_GET_REG | SystemReg.Reading)) {
const v = jdunpack(packet.data, this.stateFormat) as TReading;
const v = jdunpack(packet.data, this.reading.packFormat) as TReading;
if (v != null) {
let num = 1
if (this._lastTimestamp != undefined) {

Просмотреть файл

@ -4,13 +4,59 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ServoClient extends jacdac.Client {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
private readonly _angle : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_SERVO, role);
this._enabled = this.addRegister(jacdac.ServoReg.Enabled, "u8");
this._angle = this.addRegister(jacdac.ServoReg.Angle, "i16.16");
}
}
/**
* Turn the power to the servo on/off.
*/
//% group="Servo" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Specifies the angle of the arm.
*/
//% group="Servo" blockSetVariable=myModule
//% blockCombine block="angle" callInDebugger
get angle(): number {
const values = this._angle.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Turn the power to the servo on/off.
*/
//% group="Servo" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
/**
* Specifies the angle of the arm.
*/
//% group="Servo" blockSetVariable=myModule
//% blockCombine block="angle" callInDebugger
set angle(value: number) {
const values = this._angle.values() as any[];
values[0] = value;
this._angle.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const servo = new ServoClient("servo");
}

Просмотреть файл

@ -4,13 +4,25 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SettingsClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_SETTINGS, role);
}
}
/**
* Notifies that some setting have been modified.
*/
//% block="change" blockSetVariable=myModule
//% group="Settings" blockCombine
onChange(handler: () => void) {
this.registerEvent(jacdac.SettingsEvent.Change, handler);
}
}
//% fixedInstance whenUsed
export const settings = new SettingsClient("settings");
}

Просмотреть файл

@ -4,13 +4,85 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SevenSegmentDisplayClient extends jacdac.Client {
constructor(role: string) {
private readonly _brightness : jacdac.RegisterClient<[number]>;
private readonly _digits : jacdac.RegisterClient<[Uint8Array]>;
constructor(role: string) {
super(jacdac.SRV_SEVEN_SEGMENT_DISPLAY, role);
this._brightness = this.addRegister(jacdac.SevenSegmentDisplayReg.Brightness, "u0.16");
this._digits = this.addRegister(jacdac.SevenSegmentDisplayReg.Digits, "b");
}
}
/**
* Controls the brightness of the LEDs. ``0`` means off.
*/
//% group="7-segment display" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
get brightness(): number {
const values = this._brightness.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Each byte encodes the display status of a digit using,
* where bit 0 encodes segment `A`, bit 1 encodes segments `B`, ..., bit 6 encodes segments `G`, and bit 7 encodes the decimal point (if present).
* If incoming ``digits`` data is smaller than `digit_count`, the remaining digits will be cleared.
* Thus, sending an empty ``digits`` payload clears the screen.
*
* ```text
* - A -
* G B
* | |
* - F -
* | | -
* E C |DP|
* - D - -
* ```
*/
//% group="7-segment display" blockSetVariable=myModule
//% blockCombine block="digits" callInDebugger
get digits(): Buffer {
const values = this._digits.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Controls the brightness of the LEDs. ``0`` means off.
*/
//% group="7-segment display" blockSetVariable=myModule
//% blockCombine block="brightness" callInDebugger
set brightness(value: number) {
const values = this._brightness.values() as any[];
values[0] = value;
this._brightness.setValues(values as [number]);
}
/**
* Each byte encodes the display status of a digit using,
* where bit 0 encodes segment `A`, bit 1 encodes segments `B`, ..., bit 6 encodes segments `G`, and bit 7 encodes the decimal point (if present).
* If incoming ``digits`` data is smaller than `digit_count`, the remaining digits will be cleared.
* Thus, sending an empty ``digits`` payload clears the screen.
*
* ```text
* - A -
* G B
* | |
* - F -
* | | -
* E C |DP|
* - D - -
* ```
*/
//% group="7-segment display" blockSetVariable=myModule
//% blockCombine block="digits" callInDebugger
set digits(value: Buffer) {
const values = this._digits.values() as any[];
values[0] = value;
this._digits.setValues(values as [Buffer]);
}
}
//% fixedInstance whenUsed
export const sevenSegmentDisplay = new SevenSegmentDisplayClient("seven Segment Display");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SoilMoistureClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_SOIL_MOISTURE, role, "u0.16");
}
/**
* Indicates the wetness of the soil, from ``dry`` to ``wet``.
*/
//% blockId=jacdacsoilmoisture_101_0
//% group="Soil moisture" blockSetVariable=myModule
//% blockCombine block="moisture" callInDebugger
get moisture(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const soilMoisture = new SoilMoistureClient("soil Moisture");
}

Просмотреть файл

@ -4,24 +4,42 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SoundLevelClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_SOUND_LEVEL, role, "u0.16");
}
/**
* The sound level detected by the microphone
*/
//% blockId=jacdacsoundlevel_101_0
//% group="Sound level" blockSetVariable=myModule
//% blockCombine block="sound level" callInDebugger
get soundLevel(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Raised when a loud sound is detected
*/
//% block="loud" blockSetVariable=myModule
//% group="Sound level" blockCombine
onLoud(handler: () => void) {
this.registerEvent(jacdac.SoundLevelEvent.Loud, handler);
}
/**
* Raised when a period of quietness is detected
*/
//% block="quiet" blockSetVariable=myModule
//% group="Sound level" blockCombine
onQuiet(handler: () => void) {
this.registerEvent(jacdac.SoundLevelEvent.Quiet, handler);
}
}
//% fixedInstance whenUsed
export const soundLevel = new SoundLevelClient("sound Level");
}

Просмотреть файл

@ -4,13 +4,38 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SoundPlayerClient extends jacdac.Client {
constructor(role: string) {
private readonly _volume : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_SOUND_PLAYER, role);
this._volume = this.addRegister(jacdac.SoundPlayerReg.Volume, "u0.16");
}
}
/**
* Global volume of the output. ``0`` means completely off. This volume is mixed with each play volumes.
*/
//% group="Sound player" blockSetVariable=myModule
//% blockCombine block="volume" callInDebugger
get volume(): number {
const values = this._volume.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Global volume of the output. ``0`` means completely off. This volume is mixed with each play volumes.
*/
//% group="Sound player" blockSetVariable=myModule
//% blockCombine block="volume" callInDebugger
set volume(value: number) {
const values = this._volume.values() as any[];
values[0] = value;
this._volume.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const soundPlayer = new SoundPlayerClient("sound Player");
}

Просмотреть файл

@ -4,13 +4,38 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SpeechSynthesisClient extends jacdac.Client {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_SPEECH_SYNTHESIS, role);
this._enabled = this.addRegister(jacdac.SpeechSynthesisReg.Enabled, "u8");
}
}
/**
* Determines if the speech engine is in a non-paused state.
*/
//% group="Speech synthesis" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Determines if the speech engine is in a non-paused state.
*/
//% group="Speech synthesis" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const speechSynthesis = new SpeechSynthesisClient("speech Synthesis");
}

Просмотреть файл

@ -4,24 +4,42 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class SwitchClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_SWITCH, role, "u8");
}
/**
* Indicates whether the switch is currently active (on).
*/
//% blockId=jacdacswitch_101_0
//% group="Switch" blockSetVariable=myModule
//% blockCombine block="active" callInDebugger
get active(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Emitted when switch goes from ``off`` to ``on``.
*/
//% block="on" blockSetVariable=myModule
//% group="Switch" blockCombine
onOn(handler: () => void) {
this.registerEvent(jacdac.SwitchEvent.On, handler);
}
/**
* Emitted when switch goes from ``on`` to ``off``.
*/
//% block="off" blockSetVariable=myModule
//% group="Switch" blockCombine
onOff(handler: () => void) {
this.registerEvent(jacdac.SwitchEvent.Off, handler);
}
}
//% fixedInstance whenUsed
export const switch = new SwitchClient("switch");
}

Просмотреть файл

@ -4,13 +4,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class TcpClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_TCP, role);
}
}
}
//% fixedInstance whenUsed
export const tcp = new TcpClient("tcp");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ThermocoupleClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_THERMOCOUPLE, role, "i22.10");
}
/**
* The temperature.
*/
//% blockId=jacdacthermocouple_101_0
//% group="Thermocouple" blockSetVariable=myModule
//% blockCombine block="temperature" callInDebugger
get temperature(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const thermocouple = new ThermocoupleClient("thermocouple");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class ThermometerClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_THERMOMETER, role, "i22.10");
}
/**
* The temperature.
*/
//% blockId=jacdacthermometer_101_0
//% group="Thermometer" blockSetVariable=myModule
//% blockCombine block="temperature" callInDebugger
get temperature(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const thermometer = new ThermometerClient("thermometer");
}

Просмотреть файл

@ -4,13 +4,17 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class TrafficLightClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_TRAFFIC_LIGHT, role);
}
}
}
//% fixedInstance whenUsed
export const trafficLight = new TrafficLightClient("traffic Light");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class TvocClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_TVOC, role, "u22.10");
}
/**
* Total volatile organic compound readings in parts per billion.
*/
//% blockId=jacdactvoc_101_0
//% group="Total Volatile organic compound" blockSetVariable=myModule
//% blockCombine block="TVOC" callInDebugger
get tVOC(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const tvoc = new TvocClient("tvoc");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class UvIndexClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_UV_INDEX, role, "u16.16");
}
/**
* Ultraviolet index, typically refreshed every second.
*/
//% blockId=jacdacuvindex_101_0
//% group="UV index" blockSetVariable=myModule
//% blockCombine block="uv index" callInDebugger
get uvIndex(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const uvIndex = new UvIndexClient("uv Index");
}

Просмотреть файл

@ -4,26 +4,49 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class VibrationMotorClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
private readonly _enabled : jacdac.RegisterClient<[number]>;
constructor(role: string) {
super(jacdac.SRV_VIBRATION_MOTOR, role, "u0.8");
this._enabled = this.addRegister(jacdac.VibrationMotorReg.Enabled, "u8");
}
/**
* Rotation speed of the motor. If only one rotation speed is supported,
* then `0` shell be off, and any other number on.
* Use the ``vibrate`` command to control the register.
*/
//% blockId=jacdacvibration_101_0
//% group="Vibration motor" blockSetVariable=myModule
//% blockCombine block="speed" callInDebugger
get speed(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Determines if the vibration motor responds to vibrate commands.
*/
//% group="Vibration motor" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
get enabled(): number {
const values = this._enabled.values() as any[];
return values && values.length > 0 && values[0];
}
/**
* Determines if the vibration motor responds to vibrate commands.
*/
//% group="Vibration motor" blockSetVariable=myModule
//% blockCombine block="enabled" callInDebugger
set enabled(value: number) {
const values = this._enabled.values() as any[];
values[0] = value;
this._enabled.setValues(values as [number]);
}
}
//% fixedInstance whenUsed
export const vibrationMotor = new VibrationMotorClient("vibration Motor");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class WaterLevelClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_WATER_LEVEL, role, "u0.16");
}
/**
* The reported water level.
*/
//% blockId=jacdacwaterlevel_101_0
//% group="Water level" blockSetVariable=myModule
//% blockCombine block="level" callInDebugger
get level(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const waterLevel = new WaterLevelClient("water Level");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class WeightScaleClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_WEIGHT_SCALE, role, "u16.16");
}
/**
* The reported weight.
*/
//% blockId=jacdacweightscale_101_0
//% group="Weight Scale" blockSetVariable=myModule
//% blockCombine block="weight" callInDebugger
get weight(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const weightScale = new WeightScaleClient("weight Scale");
}

Просмотреть файл

@ -4,13 +4,33 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class WifiClient extends jacdac.Client {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_WIFI, role);
}
}
/**
* Emitted upon successful join and IP address assignment.
*/
//% block="got ip" blockSetVariable=myModule
//% group="WIFI" blockCombine
onGotIp(handler: () => void) {
this.registerEvent(jacdac.WifiEvent.GotIp, handler);
}
/**
* Emitted when disconnected from network.
*/
//% block="lost ip" blockSetVariable=myModule
//% group="WIFI" blockCombine
onLostIp(handler: () => void) {
this.registerEvent(jacdac.WifiEvent.LostIp, handler);
}
}
//% fixedInstance whenUsed
export const wifi = new WifiClient("wifi");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class WindDirectionClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_WIND_DIRECTION, role, "u16");
}
/**
* The direction of the wind.
*/
//% blockId=jacdacwinddirection_101_0
//% group="Wind direction" blockSetVariable=myModule
//% blockCombine block="wind direction" callInDebugger
get windDirection(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const windDirection = new WindDirectionClient("wind Direction");
}

Просмотреть файл

@ -4,24 +4,26 @@ namespace modules {
**/
//% fixedInstances blockGap=8
export class WindSpeedClient extends jacdac.SensorClient<[number]> {
constructor(role: string) {
constructor(role: string) {
super(jacdac.SRV_WIND_SPEED, role, "u16.16");
}
/**
* The velocity of the wind.
*/
//% blockId=jacdacwindspeed_101_0
//% group="Wind speed" blockSetVariable=myModule
//% blockCombine block="wind speed" callInDebugger
get windSpeed(): number {
const values = this.values() as any[];
return values && values.length > 0 && values[0];
}
}
}
//% fixedInstance whenUsed
export const windSpeed = new WindSpeedClient("wind Speed");
}