avoid generics
This commit is contained in:
Родитель
f45236b41c
Коммит
825d8c6199
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A 3-axis accelerometer.
|
* A 3-axis accelerometer.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class AccelerometerClient extends jacdac.SensorClient<[number,number,number]> {
|
export class AccelerometerClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _forcesError : jacdac.RegisterClient<[number]>;
|
private readonly _forcesError : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _maxForce : jacdac.RegisterClient<[number]>;
|
private readonly _maxForce : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace modules {
|
namespace modules {
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class AccelerometerClient extends jacdac.BufferedSensorClient<[number, number, number]> {
|
export class AccelerometerClient extends jacdac.BufferedSensorClient {
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
super(jacdac.SRV_ACCELEROMETER, role, "i6.10 i6.10 i6.10");
|
super(jacdac.SRV_ACCELEROMETER, role, "i6.10 i6.10 i6.10");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace modules {
|
||||||
* If a device has multiple controllers, it should have multiple gamepad services, using consecutive service identifiers.
|
* If a device has multiple controllers, it should have multiple gamepad services, using consecutive service identifiers.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class ArcadeGamepadClient extends jacdac.SensorClient<[([jacdac.ArcadeGamepadButton, number])[]]> {
|
export class ArcadeGamepadClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _availableButtons : jacdac.RegisterClient<[jacdac.ArcadeGamepadButton[]]>;
|
private readonly _availableButtons : jacdac.RegisterClient<[jacdac.ArcadeGamepadButton[]]>;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A push-button, which returns to inactive position when not operated anymore.
|
* A push-button, which returns to inactive position when not operated anymore.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class ButtonClient extends jacdac.SensorClient<[boolean]> {
|
export class ButtonClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
|
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* Senses RGB colors
|
* Senses RGB colors
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class ColorClient extends jacdac.SensorClient<[number,number,number]> {
|
export class ColorClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
|
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A 3-axis gyroscope.
|
* A 3-axis gyroscope.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class GyroscopeClient extends jacdac.SensorClient<[number,number,number]> {
|
export class GyroscopeClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _rotationRatesError : jacdac.RegisterClient<[number]>;
|
private readonly _rotationRatesError : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _maxRate : jacdac.RegisterClient<[number]>;
|
private readonly _maxRate : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A two axis directional joystick
|
* A two axis directional joystick
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class JoystickClient extends jacdac.SensorClient<[number,number]> {
|
export class JoystickClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _variant : jacdac.RegisterClient<[jacdac.JoystickVariant]>;
|
private readonly _variant : jacdac.RegisterClient<[jacdac.JoystickVariant]>;
|
||||||
private readonly _digital : jacdac.RegisterClient<[boolean]>;
|
private readonly _digital : jacdac.RegisterClient<[boolean]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A 3-axis magnetometer.
|
* A 3-axis magnetometer.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class MagnetometerClient extends jacdac.SensorClient<[number,number,number]> {
|
export class MagnetometerClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _forcesError : jacdac.RegisterClient<[number]>;
|
private readonly _forcesError : jacdac.RegisterClient<[number]>;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A matrix of buttons connected as a keypad
|
* A matrix of buttons connected as a keypad
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class MatrixKeypadClient extends jacdac.SensorClient<[number[]]> {
|
export class MatrixKeypadClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _rows : jacdac.RegisterClient<[number]>;
|
private readonly _rows : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _columns : jacdac.RegisterClient<[number]>;
|
private readonly _columns : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace modules {
|
||||||
* Multiple instances of this service may be present, if more than one model format is supported by a device.
|
* Multiple instances of this service may be present, if more than one model format is supported by a device.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class ModelRunnerClient extends jacdac.SensorClient<[number[]]> {
|
export class ModelRunnerClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _autoInvokeEvery : jacdac.RegisterClient<[number]>;
|
private readonly _autoInvokeEvery : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _inputShape : jacdac.RegisterClient<[number[]]>;
|
private readonly _inputShape : jacdac.RegisterClient<[number[]]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A sensor, typically PIR, that detects object motion within a certain range
|
* A sensor, typically PIR, that detects object motion within a certain range
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class MotionClient extends jacdac.SensorClient<[boolean]> {
|
export class MotionClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _maxDistance : jacdac.RegisterClient<[number]>;
|
private readonly _maxDistance : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _angle : jacdac.RegisterClient<[number]>;
|
private readonly _angle : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A capacitive touch sensor with multiple inputs.
|
* A capacitive touch sensor with multiple inputs.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class MultitouchClient extends jacdac.SensorClient<[number[]]> {
|
export class MultitouchClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
|
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace modules {
|
||||||
*/
|
*/
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
export class MultiTouchClient extends jacdac.SensorClient<number[]> {
|
export class MultiTouchClient extends jacdac.SensorClient {
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
super(jacdac.SRV_MULTITOUCH, role, "i32[]");
|
super(jacdac.SRV_MULTITOUCH, role, "i32[]");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace modules {
|
||||||
value(index: number): number {
|
value(index: number): number {
|
||||||
if (!this._reading.hasValues())
|
if (!this._reading.hasValues())
|
||||||
pauseUntil(() => this._reading.hasValues(), 2000)
|
pauseUntil(() => this._reading.hasValues(), 2000)
|
||||||
const values = this._reading.values;
|
const values = this._reading.values as number[];
|
||||||
const value = values[index >> 0];
|
const value = values[index >> 0];
|
||||||
return value != null ? value : -1;
|
return value != null ? value : -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* Real time clock to support collecting data with precise time stamps.
|
* Real time clock to support collecting data with precise time stamps.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class RealTimeClockClient extends jacdac.SensorClient<[number,number,number,number,number,number,number]> {
|
export class RealTimeClockClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _error : jacdac.RegisterClient<[number]>;
|
private readonly _error : jacdac.RegisterClient<[number]>;
|
||||||
private readonly _precision : jacdac.RegisterClient<[number]>;
|
private readonly _precision : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A roving robot.
|
* A roving robot.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class RoverClient extends jacdac.SensorClient<[number,number,number,number,number]> {
|
export class RoverClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
|
|
||||||
constructor(role: string) {
|
constructor(role: string) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace modules {
|
||||||
* (often used as input to machine learning models on the same device, see model runner service).
|
* (often used as input to machine learning models on the same device, see model runner service).
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class SensorAggregatorClient extends jacdac.SensorClient<[Buffer]> {
|
export class SensorAggregatorClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _inputs : jacdac.RegisterClient<[number,number,([Buffer, number, number, number, jacdac.SensorAggregatorSampleType, number])[]]>;
|
private readonly _inputs : jacdac.RegisterClient<[number,number,([Buffer, number, number, number, jacdac.SensorAggregatorSampleType, number])[]]>;
|
||||||
private readonly _numSamples : jacdac.RegisterClient<[number]>;
|
private readonly _numSamples : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
namespace jacdac {
|
namespace jacdac {
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
//% weight=1
|
//% weight=1
|
||||||
export class SensorClient<TReading extends PackSimpleDataType[]> extends Client {
|
export class SensorClient extends Client {
|
||||||
protected readonly _reading: RegisterClient<TReading>
|
protected readonly _reading: RegisterClient<PackSimpleDataType[]>
|
||||||
|
|
||||||
public isStreaming = false
|
public isStreaming = false
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ namespace jacdac {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BufferedSensorClient<TReading extends (string | number | Buffer)[]> extends SensorClient<TReading> {
|
export class BufferedSensorClient extends SensorClient {
|
||||||
protected _samples: TReading[]
|
protected _samples: any[]
|
||||||
protected _numSamples: number
|
protected _numSamples: number
|
||||||
protected _interval: number
|
protected _interval: number
|
||||||
protected _lastTimestamp: number
|
protected _lastTimestamp: number
|
||||||
|
@ -59,7 +59,7 @@ namespace jacdac {
|
||||||
|
|
||||||
handlePacket(packet: JDPacket) {
|
handlePacket(packet: JDPacket) {
|
||||||
if (this._samples && packet.serviceCommand == (CMD_GET_REG | jacdac.SystemReg.Reading)) {
|
if (this._samples && packet.serviceCommand == (CMD_GET_REG | jacdac.SystemReg.Reading)) {
|
||||||
const v = jdunpack(packet.data, this._reading.packFormat) as TReading;
|
const v = jdunpack(packet.data, this._reading.packFormat) as any[];
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
let num = 1
|
let num = 1
|
||||||
if (this._lastTimestamp != undefined) {
|
if (this._lastTimestamp != undefined) {
|
||||||
|
@ -80,7 +80,7 @@ namespace jacdac {
|
||||||
}
|
}
|
||||||
|
|
||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class SimpleSensorClient extends SensorClient<[number]> {
|
export class SimpleSensorClient extends SensorClient {
|
||||||
constructor(deviceClass: number, role: string, stateFormat: string) {
|
constructor(deviceClass: number, role: string, stateFormat: string) {
|
||||||
super(deviceClass, role, stateFormat);
|
super(deviceClass, role, stateFormat);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ namespace jacdac {
|
||||||
|
|
||||||
let last: number = this.reading()
|
let last: number = this.reading()
|
||||||
this.onStateChanged(() => {
|
this.onStateChanged(() => {
|
||||||
const [current] = this._reading.values
|
const [current] = this._reading.values as any[] as [number]
|
||||||
if (current == null)
|
if (current == null)
|
||||||
return; // ignore missing data
|
return; // ignore missing data
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A microphone that analyzes the sound specturm
|
* A microphone that analyzes the sound specturm
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class SoundSpectrumClient extends jacdac.SensorClient<[Buffer]> {
|
export class SoundSpectrumClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _enabled : jacdac.RegisterClient<[boolean]>;
|
private readonly _enabled : jacdac.RegisterClient<[boolean]>;
|
||||||
private readonly _fftPow2Size : jacdac.RegisterClient<[number]>;
|
private readonly _fftPow2Size : jacdac.RegisterClient<[number]>;
|
||||||
|
|
|
@ -3,7 +3,7 @@ namespace modules {
|
||||||
* A switch, which keeps its position.
|
* A switch, which keeps its position.
|
||||||
**/
|
**/
|
||||||
//% fixedInstances blockGap=8
|
//% fixedInstances blockGap=8
|
||||||
export class SwitchClient extends jacdac.SensorClient<[boolean]> {
|
export class SwitchClient extends jacdac.SensorClient {
|
||||||
|
|
||||||
private readonly _variant : jacdac.RegisterClient<[jacdac.SwitchVariant]>;
|
private readonly _variant : jacdac.RegisterClient<[jacdac.SwitchVariant]>;
|
||||||
private readonly _autoOffDelay : jacdac.RegisterClient<[number]>;
|
private readonly _autoOffDelay : jacdac.RegisterClient<[number]>;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче