pxt-microbit 4.1.13 → 4.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/sim.d.ts CHANGED
@@ -232,6 +232,7 @@ declare namespace pxsim {
232
232
  function getPin(id: number): Pin;
233
233
  }
234
234
  declare namespace pxsim.pins {
235
+ let edgeConnectorSoundDisabled: boolean;
235
236
  function digitalReadPin(pinId: number): number;
236
237
  function digitalWritePin(pinId: number, value: number): void;
237
238
  function setPull(pinId: number, pull: number): void;
@@ -254,6 +255,7 @@ declare namespace pxsim.music {
254
255
  }
255
256
  declare namespace pxsim.pins {
256
257
  function setAudioPin(pinId: number): void;
258
+ function setAudioPinEnabled(enabled: boolean): void;
257
259
  }
258
260
  declare namespace pxsim {
259
261
  enum PinFlags {
package/built/sim.js CHANGED
@@ -849,6 +849,7 @@ var pxsim;
849
849
  (function (pxsim) {
850
850
  var pins;
851
851
  (function (pins_1) {
852
+ pins_1.edgeConnectorSoundDisabled = false;
852
853
  function digitalReadPin(pinId) {
853
854
  let pin = pxsim.getPin(pinId);
854
855
  if (!pin)
@@ -961,7 +962,7 @@ var pxsim;
961
962
  const pins = ec.pins;
962
963
  const pin = ec.pitchEnabled && (pins.filter(pin => !!pin && pin.pitch)[0] || pins[0]);
963
964
  const pitchVolume = ec.pitchVolume | 0;
964
- if (pin) {
965
+ if (pin && !pins_1.edgeConnectorSoundDisabled) {
965
966
  pin.mode = pxsim.PinFlags.Analog | pxsim.PinFlags.Output;
966
967
  if (frequency <= 0 || pitchVolume <= 0) {
967
968
  pin.value = 0;
@@ -984,7 +985,7 @@ var pxsim;
984
985
  else {
985
986
  setTimeout(() => {
986
987
  pxsim.AudioContextManager.stop();
987
- if (pin) {
988
+ if (pin && !pins_1.edgeConnectorSoundDisabled) {
988
989
  pin.value = 0;
989
990
  pin.period = 0;
990
991
  pin.mode = pxsim.PinFlags.Unused;
@@ -1025,6 +1026,38 @@ var pxsim;
1025
1026
  pxsim.pins.analogSetPitchPin(pinId);
1026
1027
  }
1027
1028
  pins.setAudioPin = setAudioPin;
1029
+ const disabledSVG = `
1030
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
1031
+ <clipPath id="bounds" clipPathUnits="userSpaceOnUse">
1032
+ <circle cx="50" cy="50" r="45" />
1033
+ </clipPath>
1034
+ <circle cx="50" cy="50" r="40" stroke-width="10" stroke="red" fill="none" clip-path="url(#bounds)" />
1035
+ <line x1="100" y1="0" x2="0" y2="100" stroke="red" stroke-width="10" clip-path="url(#bounds)" />
1036
+ </svg>
1037
+ `;
1038
+ function setAudioPinEnabled(enabled) {
1039
+ pins.edgeConnectorSoundDisabled = !enabled;
1040
+ const headphone = pxsim.board().viewHost.getView().querySelector("g.sim-headphone-cmp");
1041
+ if (headphone) {
1042
+ const existing = headphone.querySelector("#headphone-disabled");
1043
+ if (existing) {
1044
+ if (enabled) {
1045
+ existing.remove();
1046
+ }
1047
+ else {
1048
+ return;
1049
+ }
1050
+ }
1051
+ if (!enabled) {
1052
+ const img = document.createElementNS("http://www.w3.org/2000/svg", "image");
1053
+ img.setAttribute("href", "data:image/svg+xml;utf8," + encodeURIComponent(disabledSVG));
1054
+ img.setAttribute("id", "headphone-disabled");
1055
+ img.style.transform = "scale(1.5) translate(-10px, -10px)";
1056
+ headphone.appendChild(img);
1057
+ }
1058
+ }
1059
+ }
1060
+ pins.setAudioPinEnabled = setAudioPinEnabled;
1028
1061
  })(pins = pxsim.pins || (pxsim.pins = {}));
1029
1062
  })(pxsim || (pxsim = {}));
1030
1063
  var pxsim;