* use format

* updated monolight

* adding supported targets

* removing most jacdac in blocks

* surviver
This commit is contained in:
Peli de Halleux 2020-12-15 16:27:53 +01:00 коммит произвёл GitHub
Родитель 097f239374
Коммит 6cfeb917f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
43 изменённых файлов: 172 добавлений и 59 удалений

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

@ -42,7 +42,7 @@ namespace modules {
* Reads a value of the sensor
* @param dimension which channel to read
*/
//% blockId=jacdacaccget block="jacdac %accelerometer %dimension"
//% blockId=jacdacaccget block="%accelerometer %dimension"
//% group="Accelerometer" weight=5
get(dimension: JDDimension): number {
const s = this.state;
@ -67,7 +67,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jacadacacconevent block="jacdac %accelerometer on %gesture"
//% blockId=jacadacacconevent block="%accelerometer on %gesture"
//% group="Accelerometer"
onEvent(gesture: jacdac.AccelerometerEvent, handler: () => void) {
this.registerEvent(gesture, handler);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -19,7 +19,7 @@ namespace modules {
/**
* Reads the current x value from the sensor
*/
//% blockId=jacadacbtispressed block="jacdac %button is pressed"
//% blockId=jacadacbtispressed block="%button is pressed"
//% group="Buttons"
isPressed(): boolean {
const s = this.state;
@ -32,7 +32,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jacadacbtnonevent block="jacdac %button on %event"
//% blockId=jacadacbtnonevent block="%button on %event"
//% group="Buttons"
onEvent(event: jacdac.ButtonEvent, handler: () => void) {
this.registerEvent(event, handler);

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

@ -34,4 +34,4 @@ namespace jacdac {
LongClick = 0x4,
}
}
}

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -6,6 +6,10 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker"
],
"dependencies": {
"core": "*",
"mixer": "*",

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

@ -5,6 +5,9 @@
"files": [
"controllerclient.ts"
],
"supportedTargets": [
"arcade"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -6,6 +6,9 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -17,7 +17,7 @@ namespace jacdac {
* Shows a string on the LCD screen
* @param text the text to show
*/
//% blockId=jdlcdshowstring block="jacdac %client show string %text"
//% blockId=jdlcdshowstring block="%client show string %text"
//% group="LCD" blockGap=8
showString(text: string) {
// test for change
@ -36,7 +36,7 @@ namespace jacdac {
* Shows a number on the LCD screen
* @param value the number to show
*/
//% blockId=jdlcdshownumber block="jacdac %client show number %value"
//% blockId=jdlcdshownumber block="%client show number %value"
//% group="LCD" blockGap=8
showNumber(value: number) {
this.showString(value.toString());
@ -45,7 +45,7 @@ namespace jacdac {
/**
* Clears the screen
*/
//% blockId=jdlcdclear block="jacdac clear %client"
//% blockId=jdlcdclear block="clear %client"
//% group="LCD" blockGap=8
clear() {
this.showString("");
@ -64,7 +64,7 @@ namespace jacdac {
* Enables or disables display
* @param enabled true to turn the display on; false otherwise
*/
//% blockId=jdlcdsetdisplay block="jacdac set %client display %enabled"
//% blockId=jdlcdsetdisplay block="set %client display %enabled"
//% enabled.shadow=toggleOnOff
//% group="LCD" blockGap=8
setDisplay(enabled: boolean) {
@ -75,7 +75,7 @@ namespace jacdac {
* Enables or disables blinking
* @param enabled true to blink
*/
//% blockId=jdlcdsetblink block="jacdac set %client blink %enabled"
//% blockId=jdlcdsetblink block="set %client blink %enabled"
//% enabled.shadow=toggleOnOff
//% group="LCD" blockGap=8
setBlink(enabled: boolean) {
@ -86,7 +86,7 @@ namespace jacdac {
* Show or hide cursor
* @param enabled true to display cursor, false otherwise
*/
//% blockId=jdlcdsetcursor block="jacdac set %client cursor %enabled"
//% blockId=jdlcdsetcursor block="set %client cursor %enabled"
//% enabled.shadow=toggleOnOff
//% group="LCD" blockGap=8
setCursor(enabled: boolean) {

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

@ -15,7 +15,7 @@ namespace jacdac {
/**
* Reads the current x value from the sensor
*/
//% blockId=jacdaclightsensorlevel block="jacdac %lightsensor light level"
//% blockId=jacdaclightsensorlevel block="%lightsensor light level"
//% group="Light sensor"
get lightLevel(): number {
const s = this.state;
@ -28,7 +28,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jacadaclightsensoronevent block="jacdac %client on %event"
//% blockId=jacadaclightsensoronevent block="%client on %event"
//% group="Light sensor"
onEvent(event: JDLightCondition, handler: () => void) {
this.registerEvent(event, handler);
@ -39,7 +39,7 @@ namespace jacdac {
* @param level
* @param value
*/
//% blockId=jacdaclightsetthrshold block="jacdac %lightsensor set threshold %level to %value"
//% blockId=jacdaclightsetthrshold block="%lightsensor set threshold %level to %value"
//% group="Light sensor"
setLightConditionThreshold(level: JDLightCondition, value: number) {
this.setThreshold(level == JDLightCondition.Dark, value);

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

@ -22,7 +22,7 @@ namespace jacdac {
/**
* Reads the full spectrum
*/
//% blockId=jdlightspectrumfull block="jacdac %client full"
//% blockId=jdlightspectrumfull block="%client full"
//% group="Light spectrum sensor"
get full(): number {
const s = this.state;
@ -33,7 +33,7 @@ namespace jacdac {
/**
* Reads the full spectrum
*/
//% blockId=jdlightspectruminfrared block="jacdac %client infrared"
//% blockId=jdlightspectruminfrared block="%client infrared"
//% group="Light spectrum sensor"
get infrared(): number {
const s = this.state;
@ -44,7 +44,7 @@ namespace jacdac {
/**
* Reads the full spectrum
*/
//% blockId=jdlightspectrumvisible block="jacdac %client visible"
//% blockId=jdlightspectrumvisible block="%client visible"
//% group="Light spectrum sensor"
get visible(): number {
const s = this.state;
@ -57,7 +57,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jacadaclightsensorspectrumonevent block="jacdac %client on %event"
//% blockId=jacadaclightsensorspectrumonevent block="%client on %event"
//% group="Light sensor"
onEvent(event: JDLightSpectrumEvent, handler: () => void) {
this.registerEvent(event, handler);

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

@ -77,7 +77,7 @@ namespace jacdac {
* Broadcasts a message over JacDac
* @param msg
*/
//% blockId=jacdacBroadcastMessage block="jacdac send $msg"
//% blockId=jacdacBroadcastMessage block="send $msg"
//% msg.shadow=jacdacMessageCode draggableParameters
//% weight=200
//% blockGap=8
@ -93,7 +93,7 @@ namespace jacdac {
* @param msg
* @param handler
*/
//% blockId=jacdacOnMessageReceived block="on jacdac $msg received"
//% blockId=jacdacOnMessageReceived block="on $msg received"
//% msg.shadow=jacdacMessageCode draggableParameters
//% weight=199
//% help=jacdac/on-received-message

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

@ -22,7 +22,7 @@ namespace jacdac {
* Set the on-board pixel to a given color.
* @param color RGB color of the LED
*/
//% blockId="jadacpixelsetcolor" block="jacdac set %pixel color %rgb=colorNumberPicker"
//% blockId="jadacpixelsetcolor" block="set %pixel color %rgb=colorNumberPicker"
//% weight=99
//% blockGap=8
//% group="Pixel"

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

@ -13,7 +13,7 @@ namespace jacdac {
/**
* Gets the distance measure by the sensor. Negative if missing
*/
//% blockId=jdproximtitydistance block="jacdac %client distance"
//% blockId=jdproximtitydistance block="%client distance"
//% group="Promixity"
get distance(): number {
const s = this.state;
@ -26,7 +26,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jdproximityevent block="jacdac %client on %event"
//% blockId=jdproximityevent block="%client on %event"
//% group="Promixity"
onEvent(event: JDPromixityEvent, handler: () => void) {
this.registerEvent(event, handler);

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

@ -8,7 +8,7 @@ namespace jacdac {
/**
* Reads the current x value from the sensor
*/
//% blockId=jacdacswitchright block="jacdac %switch right"
//% blockId=jacdacswitchright block="%switch right"
//% group="Switch"
right(): boolean {
const s = this.state;
@ -21,7 +21,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jacdacswitchonevent block="jacdac %switch on %event"
//% blockId=jacdacswitchonevent block="%switch on %event"
//% group="Switch"
onEvent(event: SwitchDirection, handler: () => void) {
this.registerEvent(event, handler);

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

@ -8,7 +8,7 @@ namespace jacdac {
/**
* Reads the current x value from the sensor
*/
//% blockId=jacadactouchispressed block="jacdac %button value"
//% blockId=jacadactouchispressed block="%button value"
//% group="Touch"
value(): number {
const s = this.state;
@ -21,7 +21,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jacadactouchonevent block="jacdac %button on %event"
//% blockId=jacadactouchonevent block="%button on %event"
//% group="Touch"
onEvent(event: JDButtonEvent, handler: () => void) {
this.registerEvent(event, handler);
@ -42,7 +42,7 @@ namespace jacdac {
/**
* Reads the current x value from the sensor
*/
//% blockId=jdtoubhbuttonsvalue block="jacdac %button value"
//% blockId=jdtoubhbuttonsvalue block="%button value"
//% group="Touch"
value(index: number): number {
const s = this.state;
@ -55,7 +55,7 @@ namespace jacdac {
* @param gesture
* @param handler
*/
//% blockId=jdtouchbuttonsevent block="jacdac %client %index on %event"
//% blockId=jdtouchbuttonsevent block="%client %index on %event"
//% group="Touch"
onEvent(index: number, event: JDButtonEvent, handler: () => void) {
const j = jacdac.BUTTON_EVENTS.indexOf(<number>event);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -7,6 +7,7 @@ namespace jacdac {
Log = 0x1,
Warning = 0x2,
Error = 0x3,
Silent = 0x4,
}
export const enum LoggerReg {

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

@ -8,7 +8,7 @@ namespace modules {
/**
* Reads the current x value from the sensor
*/
//% blockId=jacdacmicrophonevent block="jacdac %microphone sound level"
//% blockId=jacdacmicrophonevent block="%microphone sound level"
//% group="Microphone"
get soundLevel(): number {
const s = this.state;
@ -21,7 +21,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jacadacmicrophoneonevent block="jacdac %microphone on loud sound"
//% blockId=jacadacmicrophoneonevent block="%microphone on loud sound"
//% group="Microphone"
onLoudSound(handler: () => void) {
this.registerEvent(DAL.SENSOR_THRESHOLD_HIGH, handler);
@ -32,7 +32,7 @@ namespace modules {
* @param level
* @param value
*/
//% blockId=jacdacmicrophonesetthreshold block="jacdac %microphone set loud sound threshold to %value"
//% blockId=jacdacmicrophonesetthreshold block="%microphone set loud sound threshold to %value"
//% group="Microphone"
setLoudSoundThreshold(value: number) {
this.setThreshold(false, value);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -48,7 +48,7 @@ namespace jacdac {
* Run code when a specific even is detected in input data.
*/
//% group="Machine Learning"
//% blockId=jacadacmrundetect block="jacdac %client on ML class %classId detected"
//% blockId=jacadacmrundetect block="%client on ML class %classId detected"
onDetection(classId: number, handler: () => void) {
this.autoStart()
this.registerEvent(classId + 1000, handler);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -13,17 +13,10 @@ namespace modules {
export const blink = new MonoLightAnimation(hex`ffff f401 ffff 0100 0000 fd01`)
}
enum PwmReg {
CurrIteration = 0x80,
MaxIterations = 0x81,
Steps = 0x82,
MaxSteps = 0x180,
}
//% fixedInstances
export class MonoLightClient extends jacdac.Client {
constructor(requiredDevice: string = null) {
super("pwml", jacdac.SRV_PWM_LIGHT, requiredDevice);
super("pwml", jacdac.SRV_MONO_LIGHT, requiredDevice);
}
// set to negative for infinity
@ -31,11 +24,11 @@ namespace modules {
numIters |= 0
if (numIters < 0 || numIters >= 0xffff) numIters = 0xffffffff
else if (numIters) numIters--
this.setRegInt(PwmReg.MaxIterations, numIters)
this.setRegInt(jacdac.MonoLightReg.MaxIterations, numIters)
}
setBrightness(brightness: number): void {
this.setRegInt(jacdac.SystemReg.Intensity, brightness << 8)
this.setRegInt(jacdac.MonoLightReg.Brightness, brightness << 8)
}
showAnimation(animation: MonoLightAnimation, speed = 100) {
@ -48,7 +41,7 @@ namespace modules {
anim.setNumber(NumberFormat.UInt16LE, i + 2, adj)
}
}
this.setRegBuffer(PwmReg.Steps, anim)
this.setRegBuffer(jacdac.MonoLightReg.Steps, anim)
}
}

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

@ -1,7 +1,7 @@
namespace jacdac {
// Service: PWM Light
export const SRV_PWM_LIGHT = 0x1fb57453
export const enum PwmLightReg {
// Service: Mono Light
export const SRV_MONO_LIGHT = 0x1fb57453
export const enum MonoLightReg {
/**
* Read-write ratio uint16_t. Set the luminosity of the strip. The value is used to scale `start_intensity` in `steps` register.
* At `0` the power to the strip is completely shut down.

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -15,7 +15,7 @@ namespace modules {
*/
//% group="Servos"
//% weight=99
//% blockId=jdmotorrun block="jacdac motor %motor run at %speed=speedPicker \\%"
//% blockId=jdmotorrun block="%motor run at %speed=speedPicker \\%"
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
//% servo.fieldOptions.columns=2

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -10,7 +10,7 @@ namespace modules {
/**
* Reads the current capacitance
*/
//% blockId=jdmultitouchvalue block="jacdac %button value"
//% blockId=jdmultitouchvalue block="%button value"
//% group="Touch"
value(index: number): number {
const s = this.state;
@ -23,7 +23,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jdmulittouchevent block="jacdac %client on %event"
//% blockId=jdmulittouchevent block="%client on %event"
//% group="Touch"
onEvent(event: jacdac.MultitouchEvent, handler: (idx: number) => void) {
this.registerHandler(event, handler);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

10
pack.ts
Просмотреть файл

@ -299,4 +299,14 @@ namespace jacdac {
jdpackCore(res, fmt, data, 0)
return res
}
export function jdpackEqual<T extends any[]>(fmt: string, left: T, right: T) {
if ((!left) !== (!right))
return false;
if (!left) return true;
const leftBuffer = jdpack<T>(fmt, left);
const rightBuffer = jdpack<T>(fmt, right);
return leftBuffer.equals(rightBuffer);
}
}

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

@ -22,7 +22,7 @@ namespace modules {
/**
* Gets the position of the rotary encoder
*/
//% blockId=jacdacrotaryencoderposition block="jacdac %encoder position"
//% blockId=jacdacrotaryencoderposition block="%encoder position"
//% group="Rotary Encoder"
get position(): number {
const st = this.state;
@ -46,7 +46,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jacadacrotaryencoderonevent block="jacdac %client on %event"
//% blockId=jacadacrotaryencoderonevent block="%client on %event"
//% group="Light sensor"
onEvent(event: jacdac.RoleManagerEvent, handler: () => void) {
this.registerEvent(event, handler);

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -129,8 +129,30 @@ namespace jacdac {
return current
}
protected handleRegFormat<T extends any[]>(pkt: JDPacket, register: number, fmt: string, current: T): T {
const getset = pkt.service_command >> 12
if (getset == 0 || getset > 2)
return current
const reg = pkt.service_command & 0xfff
if (reg != register)
return current
if (getset == 1) {
this.sendReport(JDPacket.jdpacked(pkt.service_command, fmt, current))
} else {
if (register >> 8 == 0x1)
return current // read-only
const v = pkt.jdunpack<T>(fmt)
if (!jdpackEqual<T>(fmt, v, current)) {
this.stateUpdated = true
current = v
}
}
return current
}
protected handleRegBool(pkt: JDPacket, register: number, current: boolean): boolean {
return this.handleRegInt(pkt, register, current ? 1 : 0) != 0
const [res] = this.handleRegFormat(pkt, register, "u8", [current ? 1 : 0]);
return !!res;
}
protected handleRegInt(pkt: JDPacket, register: number, current: number): number {

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

@ -6,6 +6,11 @@
"constants.ts",
"host.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -44,7 +44,7 @@ namespace modules {
*/
//% group="Servos"
//% weight=100
//% blockId=jdservoservosetangle block="jacdac set %servo angle to %degrees=protractorPicker °"
//% blockId=jdservoservosetangle block="set %servo angle to %degrees=protractorPicker °"
//% degrees.defl=90
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
@ -65,7 +65,7 @@ namespace modules {
*/
//% group="Servos"
//% weight=99
//% blockId=jdservoservorun block="jacdac continuous %servo run at %speed=speedPicker \\%"
//% blockId=jdservoservorun block="continuous %servo run at %speed=speedPicker \\%"
//% servo.fieldEditor="gridpicker"
//% servo.fieldOptions.width=220
//% servo.fieldOptions.columns=2
@ -78,7 +78,7 @@ namespace modules {
*/
//% group="Servos"
//% weight=10 help=servos/set-pulse
//% blockId=jdservoservosetpulse block="jacdac set %servo pulse to %micros μs"
//% blockId=jdservoservosetpulse block="set %servo pulse to %micros μs"
//% micros.min=500 micros.max=2500
//% micros.defl=1500
//% servo.fieldEditor="gridpicker"

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -5,6 +5,11 @@
"files": [
"constants.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -8,7 +8,7 @@ namespace modules {
/**
* Gets the position of the slider
*/
//% blockId=jacdacsliderposition block="jacdac %slider position"
//% blockId=jacdacsliderposition block="%slider position"
//% group="Slider"
get position(): number {
if (!this.started) {

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

@ -18,7 +18,9 @@
"targetId": "maker"
},
"supportedTargets": [
"maker"
"arcade",
"maker",
"microbit"
],
"preferredEditor": "tsprj"
}

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"net": "*",

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

@ -41,7 +41,7 @@ namespace modules {
* @param gesture
* @param handler
*/
//% blockId=jacadacthermoonevent block="jacdac %lightsensor on %lightCondition"
//% blockId=jacadacthermoonevent block="$client on $condition at $temperature $unit"
//% group="Thermometer"
onTemperatureConditionChanged(condition: JDTemperatureCondition, temperature: number, unit: JDTemperatureUnit, handler: () => void): void {
if (unit == JDTemperatureUnit.Fahrenheit)

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac"

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

@ -6,6 +6,11 @@
"constants.ts",
"client.ts"
],
"supportedTargets": [
"arcade",
"maker",
"microbit"
],
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac",