This commit is contained in:
pelikhan 2022-09-02 07:39:03 -07:00
Родитель 64ad8aa612
Коммит 2a9223eb9a
4 изменённых файлов: 198 добавлений и 2 удалений

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

@ -5,6 +5,9 @@ namespace modules {
//% fixedInstances blockGap=8
export class DcCurrentMeasurementClient extends jacdac.SimpleSensorClient {
private readonly _measurementName: jacdac.RegisterClient<[string]>
private readonly _measurementError: jacdac.RegisterClient<[number]>
private readonly _minMeasurement: jacdac.RegisterClient<[number]>
private readonly _maxMeasurement: jacdac.RegisterClient<[number]>
constructor(role: string) {
super(
@ -18,6 +21,23 @@ namespace modules {
jacdac.DcCurrentMeasurementRegPack.MeasurementName,
jacdac.RegisterClientFlags.Const
)
this._measurementError = this.addRegister<[number]>(
jacdac.DcCurrentMeasurementReg.MeasurementError,
jacdac.DcCurrentMeasurementRegPack.MeasurementError,
jacdac.RegisterClientFlags.Optional
)
this._minMeasurement = this.addRegister<[number]>(
jacdac.DcCurrentMeasurementReg.MinMeasurement,
jacdac.DcCurrentMeasurementRegPack.MinMeasurement,
jacdac.RegisterClientFlags.Optional |
jacdac.RegisterClientFlags.Const
)
this._maxMeasurement = this.addRegister<[number]>(
jacdac.DcCurrentMeasurementReg.MaxMeasurement,
jacdac.DcCurrentMeasurementRegPack.MaxMeasurement,
jacdac.RegisterClientFlags.Optional |
jacdac.RegisterClientFlags.Const
)
}
/**
@ -44,13 +64,49 @@ namespace modules {
return this.reading()
}
/**
* Absolute error on the reading value.
*/
//% callInDebugger
//% group="DC Current Measurement"
//% weight=98
measurementError(): number {
this.start()
const values = this._measurementError.pauseUntilValues() as any[]
return values[0]
}
/**
* Minimum measurable current
*/
//% callInDebugger
//% group="DC Current Measurement"
//% weight=97
minMeasurement(): number {
this.start()
const values = this._minMeasurement.pauseUntilValues() as any[]
return values[0]
}
/**
* Maximum measurable current
*/
//% callInDebugger
//% group="DC Current Measurement"
//% weight=96
maxMeasurement(): number {
this.start()
const values = this._maxMeasurement.pauseUntilValues() as any[]
return values[0]
}
/**
* Run code when the measurement changes by the given threshold value.
*/
//% group="DC Current Measurement"
//% blockId=jacdac_dccurrentmeasurement_on_measurement_change
//% block="on %dccurrentmeasurement measurement changed by %threshold (A)"
//% weight=98
//% weight=95
//% threshold.min=0
//% threshold.defl=1
onMeasurementChangedBy(threshold: number, handler: () => void): void {

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

@ -19,6 +19,33 @@ namespace jacdac {
* ```
*/
Measurement = 0x101,
/**
* Read-only A f64 (uint64_t). Absolute error on the reading value.
*
* ```
* const [measurementError] = jdunpack<[number]>(buf, "f64")
* ```
*/
MeasurementError = 0x106,
/**
* Constant A f64 (uint64_t). Minimum measurable current
*
* ```
* const [minMeasurement] = jdunpack<[number]>(buf, "f64")
* ```
*/
MinMeasurement = 0x104,
/**
* Constant A f64 (uint64_t). Maximum measurable current
*
* ```
* const [maxMeasurement] = jdunpack<[number]>(buf, "f64")
* ```
*/
MaxMeasurement = 0x105,
}
export namespace DcCurrentMeasurementRegPack {
@ -31,5 +58,20 @@ namespace jacdac {
* Pack format for 'measurement' register data.
*/
export const Measurement = "f64"
/**
* Pack format for 'measurement_error' register data.
*/
export const MeasurementError = "f64"
/**
* Pack format for 'min_measurement' register data.
*/
export const MinMeasurement = "f64"
/**
* Pack format for 'max_measurement' register data.
*/
export const MaxMeasurement = "f64"
}
}

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

@ -8,6 +8,9 @@ namespace modules {
[jacdac.DcVoltageMeasurementVoltageMeasurementType]
>
private readonly _measurementName: jacdac.RegisterClient<[string]>
private readonly _measurementError: jacdac.RegisterClient<[number]>
private readonly _minMeasurement: jacdac.RegisterClient<[number]>
private readonly _maxMeasurement: jacdac.RegisterClient<[number]>
constructor(role: string) {
super(
@ -28,6 +31,23 @@ namespace modules {
jacdac.DcVoltageMeasurementRegPack.MeasurementName,
jacdac.RegisterClientFlags.Const
)
this._measurementError = this.addRegister<[number]>(
jacdac.DcVoltageMeasurementReg.MeasurementError,
jacdac.DcVoltageMeasurementRegPack.MeasurementError,
jacdac.RegisterClientFlags.Optional
)
this._minMeasurement = this.addRegister<[number]>(
jacdac.DcVoltageMeasurementReg.MinMeasurement,
jacdac.DcVoltageMeasurementRegPack.MinMeasurement,
jacdac.RegisterClientFlags.Optional |
jacdac.RegisterClientFlags.Const
)
this._maxMeasurement = this.addRegister<[number]>(
jacdac.DcVoltageMeasurementReg.MaxMeasurement,
jacdac.DcVoltageMeasurementRegPack.MaxMeasurement,
jacdac.RegisterClientFlags.Optional |
jacdac.RegisterClientFlags.Const
)
}
/**
@ -66,13 +86,49 @@ namespace modules {
return this.reading()
}
/**
* Absolute error on the reading value.
*/
//% callInDebugger
//% group="DC Voltage Measurement"
//% weight=97
measurementError(): number {
this.start()
const values = this._measurementError.pauseUntilValues() as any[]
return values[0]
}
/**
* Minimum measurable current
*/
//% callInDebugger
//% group="DC Voltage Measurement"
//% weight=96
minMeasurement(): number {
this.start()
const values = this._minMeasurement.pauseUntilValues() as any[]
return values[0]
}
/**
* Maximum measurable current
*/
//% callInDebugger
//% group="DC Voltage Measurement"
//% weight=95
maxMeasurement(): number {
this.start()
const values = this._maxMeasurement.pauseUntilValues() as any[]
return values[0]
}
/**
* Run code when the measurement changes by the given threshold value.
*/
//% group="DC Voltage Measurement"
//% blockId=jacdac_dcvoltagemeasurement_on_measurement_change
//% block="on %dcvoltagemeasurement measurement changed by %threshold (V)"
//% weight=97
//% weight=94
//% threshold.min=0
//% threshold.defl=1
onMeasurementChangedBy(threshold: number, handler: () => void): void {

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

@ -36,6 +36,33 @@ namespace jacdac {
* ```
*/
Measurement = 0x101,
/**
* Read-only V f64 (uint64_t). Absolute error on the reading value.
*
* ```
* const [measurementError] = jdunpack<[number]>(buf, "f64")
* ```
*/
MeasurementError = 0x106,
/**
* Constant V f64 (uint64_t). Minimum measurable current
*
* ```
* const [minMeasurement] = jdunpack<[number]>(buf, "f64")
* ```
*/
MinMeasurement = 0x104,
/**
* Constant V f64 (uint64_t). Maximum measurable current
*
* ```
* const [maxMeasurement] = jdunpack<[number]>(buf, "f64")
* ```
*/
MaxMeasurement = 0x105,
}
export namespace DcVoltageMeasurementRegPack {
@ -53,5 +80,20 @@ namespace jacdac {
* Pack format for 'measurement' register data.
*/
export const Measurement = "f64"
/**
* Pack format for 'measurement_error' register data.
*/
export const MeasurementError = "f64"
/**
* Pack format for 'min_measurement' register data.
*/
export const MinMeasurement = "f64"
/**
* Pack format for 'max_measurement' register data.
*/
export const MaxMeasurement = "f64"
}
}