-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aktualisiere pxt.json, main.blocks, main.ts, jacdacmotors.ts
- Loading branch information
Showing
4 changed files
with
62 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters