Skip to content

Commit

Permalink
Aktualisiere pxt.json, main.blocks, main.ts, jacdacmotors.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
MKleinSB committed Mar 28, 2024
1 parent f2205e0 commit 0ea3d17
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
46 changes: 46 additions & 0 deletions jacdacmotors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

namespace modules {
/**
* Calliope mini motor M0
*/
//% fixedInstance whenUsed block="calliope motor M0"
export const calliopeMotorM0 = new MotorClient("calliope motor M0?dev=self&srvo=0&name=M0")
/**
* Calliope mini motor M1
*/
//% fixedInstance whenUsed block="calliope motor M1"
export const calliopeMotorM1 = new MotorClient("calliope motor M1?dev=self&srvo=1&name=M1")
}
namespace servers {
function sync(server: jacdac.Server, motor: Motor) {
const speed = server.value
const enabled = !!server.intensity
if (speed === 0 || isNaN(speed) || !enabled) {
motors.dualMotorPower(motor, 0)
} else {
motors.dualMotorPower(motor, Math.abs(speed) * 100)
}
}

function start() {
jacdac.productIdentifier = 0x3347a2d2 // Calliope mini
jacdac.deviceDescription = "Calliope mini Motor"
jacdac.startSelfServers(() => [
jacdac.createActuatorServer(
jacdac.SRV_MOTOR,
(server) => sync(server, Motor.M0), {
instanceName: "M0",
valuePackFormat: jacdac.MotorRegPack.Speed,
intensityPackFormat: jacdac.MotorRegPack.Enabled,
}),
jacdac.createActuatorServer(
jacdac.SRV_MOTOR,
(server) => sync(server, Motor.M1), {
instanceName: "M1",
valuePackFormat: jacdac.MotorRegPack.Speed,
intensityPackFormat: jacdac.MotorRegPack.Enabled,
}),
])
}
start()
}
2 changes: 1 addition & 1 deletion main.blocks
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<xml xmlns="https://developers.google.com/blockly/xml"><block type="pxt-on-start" id=")unWn_Aaa)+HIpWYai%u" x="0" y="0"></block><block type="device_forever" id="v(p^,DW4XdFsjKbo}Wp6" x="45" y="0"></block></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><block type="pxt-on-start" id="xRRgvHNlG#rZ^u`HECiY" x="0" y="0"><statement name="HANDLER"><block type="jacdac_motor_enabled___set" id="QXXq@+a{25z:rv8}yRi#"><field name="motor">modules.calliopeMotorM0</field><value name="value"><shadow type="toggleOnOff" id="ESU!vjVk1V(^0*U7$37M"><field name="on">true</field></shadow></value><next><block type="jacdac_motor_enabled___set" id="n+].RP]LlzSj^xYCm^;j"><field name="motor">modules.calliopeMotorM1</field><value name="value"><shadow type="toggleOnOff" id="FXWsTQr@wcBx9bggbT(j"><field name="on">true</field></shadow></value></block></next></block></statement></block><block type="device_button_selected_event" id="68=a}NtI2KGLKD6Tc5.X" x="-15" y="212"><field name="NAME">Button.A</field><value name="eventType"><shadow type="control_button_event_click" id="Nn#iAoN_[Tk%J]SKNsq)"></shadow></value><statement name="HANDLER"><block type="jdmotorrun" id="w1-Li`r@UgVEWF2uhENw"><field name="motor">modules.calliopeMotorM0</field><value name="speed"><shadow type="speedPicker" id="tN*[$nY?YYLVBkh4;/#i"><field name="speed">50</field></shadow></value><next><block type="jdmotorrun" id="t[[h3E05vT5j!L9onK)I"><field name="motor">modules.calliopeMotorM1</field><value name="speed"><shadow type="speedPicker" id="|S}DHW/z/Asc|~%aFy(s"><field name="speed">100</field></shadow></value></block></next></block></statement></block><block type="device_button_selected_event" id="yU!Kl,d+L4xC_{IMyg!n" x="10" y="424"><field name="NAME">Button.B</field><value name="eventType"><shadow type="control_button_event_click" id="V#qMMJRG+@^Cqr;0(j~j"></shadow></value><statement name="HANDLER"><block type="jdmotorrun" id="h/`=2;%Rzdw%P+hu2yoA"><field name="motor">modules.calliopeMotorM0</field><value name="speed"><shadow type="speedPicker" id="zQi0uQT^FLl]n~1`@DFU"><field name="speed">100</field></shadow></value><next><block type="jdmotorrun" id="pw.IcNSw4QQR%D%`K|Av"><field name="motor">modules.calliopeMotorM1</field><value name="speed"><shadow type="speedPicker" id="}DBOCY#RF#-BTg}V}s4Y"><field name="speed">100</field></shadow></value></block></next></block></statement></block></xml>
58 changes: 10 additions & 48 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
//% deprecated
namespace motors { }

namespace modules {
/**
* Calliope mini motor M0
*/
//% fixedInstance whenUsed block="calliope motor M0"
export const calliopeMotorM0 = new MotorClient("calliope motor M0?dev=self&srvo=0&name=M0")
/**
* Calliope mini motor M1
*/
//% fixedInstance whenUsed block="calliope motor M1"
export const calliopeMotorM1 = new MotorClient("calliope motor M1?dev=self&srvo=1&name=M1")
}

namespace servers {
function sync(server: jacdac.Server, motor: Motor) {
const speed = server.value
const enabled = !!server.intensity
if (speed === 0 || isNaN(speed) || !enabled) {
motors.brakeMotor(motor)
} else {
motors.dualMotorPower(motor, Math.abs(speed) * 100)
}
}

function start() {
jacdac.productIdentifier = 0x3cad0000
jacdac.deviceDescription = "Calliope mini Motor"
jacdac.startSelfServers(() => [
jacdac.createActuatorServer(
jacdac.SRV_MOTOR,
(server) => sync(server, Motor.A), {
instanceName: "M0",
valuePackFormat: jacdac.MotorRegPack.Speed,
intensityPackFormat: jacdac.MotorRegPack.Enabled,
}),
jacdac.createActuatorServer(
jacdac.SRV_MOTOR,
(server) => sync(server, Motor.B), {
instanceName: "M0", valuePackFormat: jacdac.MotorRegPack.Speed,
intensityPackFormat: jacdac.MotorRegPack.Enabled,
}),
])
}
start()
}
input.onButtonEvent(Button.A, input.buttonEventClick(), function () {
modules.calliopeMotorM0.run(50)
modules.calliopeMotorM1.run(100)
})
input.onButtonEvent(Button.B, input.buttonEventClick(), function () {
modules.calliopeMotorM0.run(100)
modules.calliopeMotorM1.run(100)
})
modules.calliopeMotorM0.setEnabled(true)
modules.calliopeMotorM1.setEnabled(true)
9 changes: 5 additions & 4 deletions pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
"description": "",
"dependencies": {
"core": "*",
"jacdac": "github:microsoft/pxt-jacdac#v1.9.22",
"jacdac": "github:microsoft/pxt-jacdac#v1.9.27",
"v3": "*",
"jacdac-motor": "github:microsoft/pxt-jacdac/motor#v1.9.22"
"jacdac-motor": "github:microsoft/pxt-jacdac/motor#v1.9.27"
},
"files": [
"README.md",
"main.blocks",
"main.ts",
"jacdac.json",
"jacdac.ts"
"jacdac.ts",
"jacdacmotors.ts"
],
"testFiles": [
"test.ts"
],
"public": true,
"targetVersions": {
"target": "6.0.22",
"target": "6.0.28",
"targetId": "calliopemini"
},
"supportedTargets": [
Expand Down

0 comments on commit 0ea3d17

Please sign in to comment.