pxt-jacdac/illuminance/client.g.ts

67 строки
2.2 KiB
TypeScript
Исходник Постоянная ссылка Обычный вид История

2021-02-11 13:11:35 +03:00
namespace modules {
2021-02-11 14:05:12 +03:00
/**
* Detects the amount of light falling onto a given surface area.
2022-04-08 18:39:19 +03:00
*
* Note that this is different from _luminance_, the amount of light that passes through, emits from, or reflects off an object.
2021-02-11 14:05:12 +03:00
**/
//% fixedInstances blockGap=8
export class IlluminanceClient extends jacdac.SimpleSensorClient {
2022-04-08 18:39:19 +03:00
private readonly _illuminanceError: jacdac.RegisterClient<[number]>
2021-02-23 14:23:30 +03:00
constructor(role: string) {
super(
jacdac.SRV_ILLUMINANCE,
role,
jacdac.IlluminanceRegPack.Illuminance
)
2021-02-23 13:36:16 +03:00
2022-04-08 18:39:19 +03:00
this._illuminanceError = this.addRegister<[number]>(
jacdac.IlluminanceReg.IlluminanceError,
2022-04-19 22:08:59 +03:00
jacdac.IlluminanceRegPack.IlluminanceError,
jacdac.RegisterClientFlags.Optional
2022-04-08 18:39:19 +03:00
)
2021-02-11 13:11:35 +03:00
}
2021-02-11 13:11:35 +03:00
/**
2022-04-08 18:39:19 +03:00
* The amount of illuminance, as lumens per square metre.
*/
2021-02-23 13:36:16 +03:00
//% callInDebugger
//% group="Environment"
2022-05-16 22:11:00 +03:00
//% block="%illuminance illuminance (lux)"
//% blockId=jacdac_illuminance_illuminance___get
2021-02-23 14:23:30 +03:00
//% weight=100
illuminance(): number {
2022-04-08 18:39:19 +03:00
return this.reading()
2021-02-23 13:36:16 +03:00
}
/**
2022-04-08 18:39:19 +03:00
* Error on the reported sensor value.
*/
2021-02-23 13:36:16 +03:00
//% callInDebugger
//% group="Environment"
2021-02-23 14:23:30 +03:00
//% weight=99
illuminanceError(): number {
2022-04-08 18:39:19 +03:00
this.start()
const values = this._illuminanceError.pauseUntilValues() as any[]
return values[0]
2021-02-23 13:36:16 +03:00
}
/**
* Run code when the illuminance changes by the given threshold value.
2022-04-08 18:39:19 +03:00
*/
//% group="Environment"
//% blockId=jacdac_illuminance_on_illuminance_change
2022-05-18 22:29:10 +03:00
//% block="on %illuminance illuminance changed by %threshold (lux)"
2021-03-11 17:13:58 +03:00
//% weight=98
//% threshold.min=0
//% threshold.max=100000
//% threshold.defl=1
onIlluminanceChangedBy(threshold: number, handler: () => void): void {
2022-04-08 18:39:19 +03:00
this.onReadingChangedBy(threshold, handler)
}
2021-02-11 13:11:35 +03:00
}
2022-06-16 00:56:29 +03:00
2022-04-08 18:39:19 +03:00
//% fixedInstance whenUsed weight=1 block="illuminance1"
export const illuminance1 = new IlluminanceClient("illuminance1")
}