fixing various lint violations
This commit is contained in:
parent
29b28e7f0d
commit
04a60a5b47
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Place your settings in this file to overwrite default and user settings.
|
||||||
|
{
|
||||||
|
"tslint.enable": true,
|
||||||
|
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
|
||||||
|
}
|
@ -46,7 +46,7 @@ namespace i2c_fram {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeBuffer(addr:number, buf: Buffer) {
|
export function writeBuffer(addr: number, buf: Buffer) {
|
||||||
if (addr < 0 || (addr + buf.length) > memend)
|
if (addr < 0 || (addr + buf.length) > memend)
|
||||||
die();
|
die();
|
||||||
for (let i = 0; i < buf.length; ++i)
|
for (let i = 0; i < buf.length; ++i)
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
namespace pxsim {
|
namespace pxsim {
|
||||||
pxsim.initCurrentRuntime = () => {
|
pxsim.initCurrentRuntime = () => {
|
||||||
U.assert(!runtime.board)
|
U.assert(!runtime.board);
|
||||||
runtime.board = new Board()
|
runtime.board = new Board();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function board() {
|
export function board() {
|
||||||
return runtime.board as Board
|
return runtime.board as Board;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AnimationOptions {
|
export interface AnimationOptions {
|
||||||
@ -125,9 +125,9 @@ namespace pxsim {
|
|||||||
|
|
||||||
|
|
||||||
export namespace AudioContextManager {
|
export namespace AudioContextManager {
|
||||||
var _context: any; // AudioContext
|
let _context: any; // AudioContext
|
||||||
var _vco: any; //OscillatorNode;
|
let _vco: any; // OscillatorNode;
|
||||||
var _vca: any; // GainNode;
|
let _vca: any; // GainNode;
|
||||||
|
|
||||||
function context(): any {
|
function context(): any {
|
||||||
if (!_context) _context = freshContext();
|
if (!_context) _context = freshContext();
|
||||||
@ -152,7 +152,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
export function tone(frequency: number, gain: number) {
|
export function tone(frequency: number, gain: number) {
|
||||||
if (frequency <= 0) return;
|
if (frequency <= 0) return;
|
||||||
var ctx = context();
|
let ctx = context();
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
|
|
||||||
gain = Math.max(0, Math.min(1, gain));
|
gain = Math.max(0, Math.min(1, gain));
|
||||||
@ -198,7 +198,7 @@ namespace pxsim.basic {
|
|||||||
pause(interval * 5);
|
pause(interval * 5);
|
||||||
} else {
|
} else {
|
||||||
if (s.length == 1) showLeds(createImageFromString(s), interval * 5)
|
if (s.length == 1) showLeds(createImageFromString(s), interval * 5)
|
||||||
else ImageMethods.scrollImage(createImageFromString(s + ' '), interval, 1);
|
else ImageMethods.scrollImage(createImageFromString(s + " "), interval, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,18 +227,18 @@ namespace pxsim.control {
|
|||||||
U.userError("reset not implemented in simulator yet")
|
U.userError("reset not implemented in simulator yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deviceName() : string {
|
export function deviceName(): string {
|
||||||
let b = board();
|
let b = board();
|
||||||
return b && b.id
|
return b && b.id
|
||||||
? b.id.slice(0, 4)
|
? b.id.slice(0, 4)
|
||||||
: 'abcd';
|
: "abcd";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deviceSerialNumber(): number {
|
export function deviceSerialNumber(): number {
|
||||||
let b = board();
|
let b = board();
|
||||||
return parseInt(b && b.id
|
return parseInt(b && b.id
|
||||||
? b.id.slice(1)
|
? b.id.slice(1)
|
||||||
: '42');
|
: "42");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onEvent(id: number, evid: number, handler: RefAction) {
|
export function onEvent(id: number, evid: number, handler: RefAction) {
|
||||||
@ -306,7 +306,7 @@ namespace pxsim.input {
|
|||||||
|
|
||||||
|
|
||||||
export function compassHeading(): number {
|
export function compassHeading(): number {
|
||||||
var b = board();
|
let b = board();
|
||||||
if (!b.usesHeading) {
|
if (!b.usesHeading) {
|
||||||
b.usesHeading = true;
|
b.usesHeading = true;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
@ -315,7 +315,7 @@ namespace pxsim.input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function temperature(): number {
|
export function temperature(): number {
|
||||||
var b = board();
|
let b = board();
|
||||||
if (!b.usesTemperature) {
|
if (!b.usesTemperature) {
|
||||||
b.usesTemperature = true;
|
b.usesTemperature = true;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
@ -578,12 +578,12 @@ namespace pxsim.ImageMethods {
|
|||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function height(leds: Image) : number {
|
export function height(leds: Image): number {
|
||||||
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
||||||
return Image.height;
|
return Image.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function width(leds: Image) : number {
|
export function width(leds: Image): number {
|
||||||
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
||||||
return leds.width;
|
return leds.width;
|
||||||
}
|
}
|
||||||
@ -596,14 +596,14 @@ namespace pxsim.ImageMethods {
|
|||||||
ImageMethods.showImage(leds, frame * Image.height);
|
ImageMethods.showImage(leds, frame * Image.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pixel(leds: Image, x: number, y: number) : number {
|
export function pixel(leds: Image, x: number, y: number): number {
|
||||||
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
||||||
return leds.get(x,y);
|
return leds.get(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setPixel(leds: Image, x: number, y: number, v:number) {
|
export function setPixel(leds: Image, x: number, y: number, v: number) {
|
||||||
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
|
||||||
leds.set(x,y,v);
|
leds.set(x, y, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clear(leds: Image) {
|
export function clear(leds: Image) {
|
||||||
|
264
sim/simsvg.ts
264
sim/simsvg.ts
@ -15,7 +15,7 @@ namespace pxsim.micro_bit {
|
|||||||
virtualButtonOuter?: string;
|
virtualButtonOuter?: string;
|
||||||
virtualButtonUp?: string;
|
virtualButtonUp?: string;
|
||||||
virtualButtonDown?: string;
|
virtualButtonDown?: string;
|
||||||
lightLevelOn?:string;
|
lightLevelOn?: string;
|
||||||
lightLevelOff?: string;
|
lightLevelOff?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ namespace pxsim.micro_bit {
|
|||||||
display: "#000",
|
display: "#000",
|
||||||
pin: "#D4AF37",
|
pin: "#D4AF37",
|
||||||
pinTouched: "#FFA500",
|
pinTouched: "#FFA500",
|
||||||
pinActive:"#FF5500",
|
pinActive: "#FF5500",
|
||||||
ledOn: "#ff7f7f",
|
ledOn: "#ff7f7f",
|
||||||
ledOff: "#202020",
|
ledOff: "#202020",
|
||||||
buttonOuter: "#979797",
|
buttonOuter: "#979797",
|
||||||
@ -35,16 +35,17 @@ namespace pxsim.micro_bit {
|
|||||||
virtualButtonUp: "#fff",
|
virtualButtonUp: "#fff",
|
||||||
lightLevelOn: "yellow",
|
lightLevelOn: "yellow",
|
||||||
lightLevelOff: "#555"
|
lightLevelOff: "#555"
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export function randomTheme() : IBoardTheme {
|
export function randomTheme(): IBoardTheme {
|
||||||
return themes[Math.floor(Math.random() * themes.length)];
|
return themes[Math.floor(Math.random() * themes.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBoardProps {
|
export interface IBoardProps {
|
||||||
runtime: pxsim.Runtime;
|
runtime: pxsim.Runtime;
|
||||||
theme?: IBoardTheme;
|
theme?: IBoardTheme;
|
||||||
disableTilt?:boolean;
|
disableTilt?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pointerEvents = !!(window as any).PointerEvent ? {
|
const pointerEvents = !!(window as any).PointerEvent ? {
|
||||||
@ -53,17 +54,16 @@ namespace pxsim.micro_bit {
|
|||||||
move: "pointermove",
|
move: "pointermove",
|
||||||
leave: "pointerleave"
|
leave: "pointerleave"
|
||||||
} : {
|
} : {
|
||||||
up: "mouseup",
|
up: "mouseup",
|
||||||
down: "mousedown",
|
down: "mousedown",
|
||||||
move: "mousemove",
|
move: "mousemove",
|
||||||
leave: "mouseleave"
|
leave: "mouseleave"
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MicrobitBoardSvg
|
export class MicrobitBoardSvg {
|
||||||
{
|
public element: SVGSVGElement;
|
||||||
public element : SVGSVGElement;
|
|
||||||
private style: SVGStyleElement;
|
private style: SVGStyleElement;
|
||||||
private defs : SVGDefsElement;
|
private defs: SVGDefsElement;
|
||||||
private g: SVGElement;
|
private g: SVGElement;
|
||||||
|
|
||||||
private logos: SVGElement[];
|
private logos: SVGElement[];
|
||||||
@ -72,7 +72,7 @@ namespace pxsim.micro_bit {
|
|||||||
private display: SVGElement;
|
private display: SVGElement;
|
||||||
private buttons: SVGElement[];
|
private buttons: SVGElement[];
|
||||||
private buttonsOuter: SVGElement[];
|
private buttonsOuter: SVGElement[];
|
||||||
private buttonABText:SVGTextElement;
|
private buttonABText: SVGTextElement;
|
||||||
private pins: SVGElement[];
|
private pins: SVGElement[];
|
||||||
private pinGradients: SVGLinearGradientElement[];
|
private pinGradients: SVGLinearGradientElement[];
|
||||||
private pinTexts: SVGTextElement[];
|
private pinTexts: SVGTextElement[];
|
||||||
@ -81,9 +81,9 @@ namespace pxsim.micro_bit {
|
|||||||
private systemLed: SVGCircleElement;
|
private systemLed: SVGCircleElement;
|
||||||
private antenna: SVGPolylineElement;
|
private antenna: SVGPolylineElement;
|
||||||
private lightLevelButton: SVGCircleElement;
|
private lightLevelButton: SVGCircleElement;
|
||||||
private lightLevelGradient : SVGLinearGradientElement;
|
private lightLevelGradient: SVGLinearGradientElement;
|
||||||
private lightLevelText: SVGTextElement;
|
private lightLevelText: SVGTextElement;
|
||||||
private thermometerGradient : SVGLinearGradientElement;
|
private thermometerGradient: SVGLinearGradientElement;
|
||||||
private thermometer: SVGRectElement;
|
private thermometer: SVGRectElement;
|
||||||
private thermometerText: SVGTextElement;
|
private thermometerText: SVGTextElement;
|
||||||
private shakeButton: SVGCircleElement;
|
private shakeButton: SVGCircleElement;
|
||||||
@ -127,10 +127,10 @@ namespace pxsim.micro_bit {
|
|||||||
Svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
|
Svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
|
||||||
});
|
});
|
||||||
|
|
||||||
var bw = state.displayMode == pxsim.DisplayMode.bw
|
let bw = state.displayMode == pxsim.DisplayMode.bw
|
||||||
var img = state.image;
|
let img = state.image;
|
||||||
this.leds.forEach((led,i) => {
|
this.leds.forEach((led, i) => {
|
||||||
var sel = (<SVGStylable><any>led)
|
let sel = (<SVGStylable><any>led)
|
||||||
sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + "";
|
sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + "";
|
||||||
})
|
})
|
||||||
this.updatePins();
|
this.updatePins();
|
||||||
@ -148,7 +148,7 @@ namespace pxsim.micro_bit {
|
|||||||
private updateGestures() {
|
private updateGestures() {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
if (state.useShake && !this.shakeButton) {
|
if (state.useShake && !this.shakeButton) {
|
||||||
this.shakeButton = Svg.child(this.g, "circle", {cx:380, cy:100, r:16.5}) as SVGCircleElement;
|
this.shakeButton = Svg.child(this.g, "circle", { cx: 380, cy: 100, r: 16.5 }) as SVGCircleElement;
|
||||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp)
|
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp)
|
||||||
this.shakeButton.addEventListener(pointerEvents.down, ev => {
|
this.shakeButton.addEventListener(pointerEvents.down, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
@ -163,7 +163,7 @@ namespace pxsim.micro_bit {
|
|||||||
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
|
||||||
this.board.bus.queue(DAL.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
|
this.board.bus.queue(DAL.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
|
||||||
})
|
})
|
||||||
this.shakeText = Svg.child(this.g, "text", {x:400, y:110, class:'sim-text'}) as SVGTextElement;
|
this.shakeText = Svg.child(this.g, "text", { x: 400, y: 110, class: "sim-text" }) as SVGTextElement;
|
||||||
this.shakeText.textContent = "SHAKE"
|
this.shakeText.textContent = "SHAKE"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,21 +171,21 @@ namespace pxsim.micro_bit {
|
|||||||
private updateButtonAB() {
|
private updateButtonAB() {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
if (state.usesButtonAB && !this.buttonABText) {
|
if (state.usesButtonAB && !this.buttonABText) {
|
||||||
(<any>this.buttonsOuter[2]).style.visibility = 'visible';
|
(<any>this.buttonsOuter[2]).style.visibility = "visible";
|
||||||
(<any>this.buttons[2]).style.visibility = 'visible';
|
(<any>this.buttons[2]).style.visibility = "visible";
|
||||||
this.buttonABText = Svg.child(this.g, "text", {class: 'sim-text', x:370, y:272 }) as SVGTextElement;
|
this.buttonABText = Svg.child(this.g, "text", { class: "sim-text", x: 370, y: 272 }) as SVGTextElement;
|
||||||
this.buttonABText.textContent = "A+B";
|
this.buttonABText.textContent = "A+B";
|
||||||
this.updateTheme();
|
this.updateTheme();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private updatePin(pin : Pin, index: number) {
|
private updatePin(pin: Pin, index: number) {
|
||||||
if (!pin) return;
|
if (!pin) return;
|
||||||
let text = this.pinTexts[index];
|
let text = this.pinTexts[index];
|
||||||
let v = '';
|
let v = "";
|
||||||
if (pin.mode & PinMode.Analog) {
|
if (pin.mode & PinMode.Analog) {
|
||||||
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + '%';
|
v = Math.floor(100 - (pin.value || 0) / 1023 * 100) + "%";
|
||||||
if(text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
|
if (text) text.textContent = (pin.period ? "~" : "") + (pin.value || 0) + "";
|
||||||
}
|
}
|
||||||
else if (pin.mode & PinMode.Digital) {
|
else if (pin.mode & PinMode.Digital) {
|
||||||
v = pin.value > 0 ? '0%' : '100%';
|
v = pin.value > 0 ? '0%' : '100%';
|
||||||
@ -196,7 +196,7 @@ namespace pxsim.micro_bit {
|
|||||||
if (text) text.textContent = "";
|
if (text) text.textContent = "";
|
||||||
} else {
|
} else {
|
||||||
v = '100%';
|
v = '100%';
|
||||||
if(text) text.textContent = '';
|
if (text) text.textContent = '';
|
||||||
}
|
}
|
||||||
if (v) Svg.setGradientValue(this.pinGradients[index], v);
|
if (v) Svg.setGradientValue(this.pinGradients[index], v);
|
||||||
}
|
}
|
||||||
@ -210,16 +210,16 @@ namespace pxsim.micro_bit {
|
|||||||
if (!this.thermometer) {
|
if (!this.thermometer) {
|
||||||
let gid = "gradient-thermometer";
|
let gid = "gradient-thermometer";
|
||||||
this.thermometerGradient = Svg.linearGradient(this.defs, gid);
|
this.thermometerGradient = Svg.linearGradient(this.defs, gid);
|
||||||
this.thermometer = <SVGRectElement> Svg.child(this.g, "rect", {
|
this.thermometer = <SVGRectElement>Svg.child(this.g, "rect", {
|
||||||
class: "sim-thermometer",
|
class: "sim-thermometer",
|
||||||
x:120,
|
x: 120,
|
||||||
y:110,
|
y: 110,
|
||||||
width:20,
|
width: 20,
|
||||||
height:160,
|
height: 160,
|
||||||
rx:5, ry:5,
|
rx: 5, ry: 5,
|
||||||
fill:`url(#${gid})`
|
fill: `url(#${gid})`
|
||||||
});
|
});
|
||||||
this.thermometerText = Svg.child(this.g, "text", { class:'sim-text', x:58, y:130}) as SVGTextElement;
|
this.thermometerText = Svg.child(this.g, "text", { class: 'sim-text', x: 58, y: 130 }) as SVGTextElement;
|
||||||
this.updateTheme();
|
this.updateTheme();
|
||||||
|
|
||||||
let pt = this.element.createSVGPoint();
|
let pt = this.element.createSVGPoint();
|
||||||
@ -227,13 +227,13 @@ namespace pxsim.micro_bit {
|
|||||||
(ev) => {
|
(ev) => {
|
||||||
let cur = Svg.cursorPoint(pt, this.element, ev);
|
let cur = Svg.cursorPoint(pt, this.element, ev);
|
||||||
let t = Math.max(0, Math.min(1, (260 - cur.y) / 140))
|
let t = Math.max(0, Math.min(1, (260 - cur.y) / 140))
|
||||||
state.temperature = Math.floor(tmin + t * (tmax-tmin));
|
state.temperature = Math.floor(tmin + t * (tmax - tmin));
|
||||||
this.updateTemperature();
|
this.updateTemperature();
|
||||||
}, ev => {}, ev => {})
|
}, ev => { }, ev => { })
|
||||||
}
|
}
|
||||||
|
|
||||||
let t = Math.max(tmin, Math.min(tmax, state.temperature))
|
let t = Math.max(tmin, Math.min(tmax, state.temperature))
|
||||||
let per = Math.floor((state.temperature - tmin) / (tmax-tmin)*100)
|
let per = Math.floor((state.temperature - tmin) / (tmax - tmin) * 100)
|
||||||
Svg.setGradientValue(this.thermometerGradient, 100 - per + '%');
|
Svg.setGradientValue(this.thermometerGradient, 100 - per + '%');
|
||||||
this.thermometerText.textContent = t + '°C';
|
this.thermometerText.textContent = t + '°C';
|
||||||
}
|
}
|
||||||
@ -249,27 +249,27 @@ namespace pxsim.micro_bit {
|
|||||||
let pt = this.element.createSVGPoint();
|
let pt = this.element.createSVGPoint();
|
||||||
Svg.buttonEvents(
|
Svg.buttonEvents(
|
||||||
this.head,
|
this.head,
|
||||||
(ev : MouseEvent) => {
|
(ev: MouseEvent) => {
|
||||||
let cur = Svg.cursorPoint(pt, this.element, ev);
|
let cur = Svg.cursorPoint(pt, this.element, ev);
|
||||||
state.heading = Math.floor(Math.atan2(cur.y - yc, cur.x - xc) * 180 / Math.PI+90);
|
state.heading = Math.floor(Math.atan2(cur.y - yc, cur.x - xc) * 180 / Math.PI + 90);
|
||||||
if (state.heading < 0) state.heading += 360;
|
if (state.heading < 0) state.heading += 360;
|
||||||
console.log('heading: ' + state.heading)
|
console.log('heading: ' + state.heading)
|
||||||
this.updateHeading();
|
this.updateHeading();
|
||||||
});
|
});
|
||||||
this.headInitialized = true;
|
this.headInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let txt = state.heading.toString() + '°';
|
let txt = state.heading.toString() + '°';
|
||||||
if (txt != this.headText.textContent) {
|
if (txt != this.headText.textContent) {
|
||||||
Svg.rotateElement(this.head, xc, yc, state.heading+180);
|
Svg.rotateElement(this.head, xc, yc, state.heading + 180);
|
||||||
this.headText.textContent = txt;
|
this.headText.textContent = txt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lastFlashTime : number = 0;
|
private lastFlashTime: number = 0;
|
||||||
public flashSystemLed() {
|
public flashSystemLed() {
|
||||||
if (!this.systemLed)
|
if (!this.systemLed)
|
||||||
this.systemLed = <SVGCircleElement>Svg.child(this.g, "circle", {class:"sim-systemled", cx:300, cy:20, r:5})
|
this.systemLed = <SVGCircleElement>Svg.child(this.g, "circle", { class: "sim-systemled", cx: 300, cy: 20, r: 5 })
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
if (now - this.lastFlashTime > 150) {
|
if (now - this.lastFlashTime > 150) {
|
||||||
this.lastFlashTime = now;
|
this.lastFlashTime = now;
|
||||||
@ -277,14 +277,14 @@ namespace pxsim.micro_bit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lastAntennaFlash : number = 0;
|
private lastAntennaFlash: number = 0;
|
||||||
public flashAntenna() {
|
public flashAntenna() {
|
||||||
if (!this.antenna) {
|
if (!this.antenna) {
|
||||||
let ax = 380;
|
let ax = 380;
|
||||||
let dax = 18;
|
let dax = 18;
|
||||||
let ayt = 10;
|
let ayt = 10;
|
||||||
let ayb = 40;
|
let ayb = 40;
|
||||||
this.antenna = <SVGPolylineElement>Svg.child(this.g, "polyline", { class:"sim-antenna", points: `${ax},${ayb} ${ax},${ayt} ${ax+=dax},${ayt} ${ax},${ayb} ${ax+=dax},${ayb} ${ax},${ayt} ${ax+=dax},${ayt} ${ax},${ayb} ${ax+=dax},${ayb} ${ax},${ayt} ${ax+=dax},${ayt}`})
|
this.antenna = <SVGPolylineElement>Svg.child(this.g, "polyline", { class: "sim-antenna", points: `${ax},${ayb} ${ax},${ayt} ${ax += dax},${ayt} ${ax},${ayb} ${ax += dax},${ayb} ${ax},${ayt} ${ax += dax},${ayt} ${ax},${ayb} ${ax += dax},${ayb} ${ax},${ayt} ${ax += dax},${ayt}` })
|
||||||
}
|
}
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
if (now - this.lastAntennaFlash > 200) {
|
if (now - this.lastAntennaFlash > 200) {
|
||||||
@ -297,7 +297,7 @@ namespace pxsim.micro_bit {
|
|||||||
let state = this.board;
|
let state = this.board;
|
||||||
if (!state) return;
|
if (!state) return;
|
||||||
|
|
||||||
state.pins.forEach((pin,i) => this.updatePin(pin,i));
|
state.pins.forEach((pin, i) => this.updatePin(pin, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateLightLevel() {
|
private updateLightLevel() {
|
||||||
@ -305,37 +305,38 @@ namespace pxsim.micro_bit {
|
|||||||
if (!state || !state.usesLightLevel) return;
|
if (!state || !state.usesLightLevel) return;
|
||||||
|
|
||||||
if (!this.lightLevelButton) {
|
if (!this.lightLevelButton) {
|
||||||
let gid= "gradient-light-level";
|
let gid = "gradient-light-level";
|
||||||
this.lightLevelGradient = Svg.linearGradient(this.defs, gid)
|
this.lightLevelGradient = Svg.linearGradient(this.defs, gid)
|
||||||
let cy = 50;
|
let cy = 50;
|
||||||
let r = 35;
|
let r = 35;
|
||||||
this.lightLevelButton = Svg.child(this.g, "circle", {
|
this.lightLevelButton = Svg.child(this.g, "circle", {
|
||||||
cx: `50px`, cy: `${cy}px`, r: `${r}px`,
|
cx: `50px`, cy: `${cy}px`, r: `${r}px`,
|
||||||
class:'sim-light-level-button',
|
class: 'sim-light-level-button',
|
||||||
fill: `url(#${gid})` }) as SVGCircleElement;
|
fill: `url(#${gid})`
|
||||||
|
}) as SVGCircleElement;
|
||||||
let pt = this.element.createSVGPoint();
|
let pt = this.element.createSVGPoint();
|
||||||
Svg.buttonEvents(this.lightLevelButton,
|
Svg.buttonEvents(this.lightLevelButton,
|
||||||
(ev) => {
|
(ev) => {
|
||||||
let pos = Svg.cursorPoint(pt, this.element, ev);
|
let pos = Svg.cursorPoint(pt, this.element, ev);
|
||||||
let rs = r/2;
|
let rs = r / 2;
|
||||||
let level = Math.max(0, Math.min(255, Math.floor((pos.y - (cy-rs)) / (2*rs) * 255)));
|
let level = Math.max(0, Math.min(255, Math.floor((pos.y - (cy - rs)) / (2 * rs) * 255)));
|
||||||
if (level != this.board.lightLevel) {
|
if (level != this.board.lightLevel) {
|
||||||
this.board.lightLevel = level;
|
this.board.lightLevel = level;
|
||||||
this.applyLightLevel();
|
this.applyLightLevel();
|
||||||
}
|
}
|
||||||
}, ev => {},
|
}, ev => { },
|
||||||
ev => {})
|
ev => { })
|
||||||
this.lightLevelText = Svg.child(this.g, "text", { x:85, y:cy+r-5, text:'', class:'sim-text'}) as SVGTextElement;
|
this.lightLevelText = Svg.child(this.g, "text", { x: 85, y: cy + r - 5, text: '', class: 'sim-text' }) as SVGTextElement;
|
||||||
this.updateTheme();
|
this.updateTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
Svg.setGradientValue(this.lightLevelGradient, Math.min(100, Math.max(0, Math.floor(state.lightLevel * 100 / 255))) + '%')
|
Svg.setGradientValue(this.lightLevelGradient, Math.min(100, Math.max(0, Math.floor(state.lightLevel * 100 / 255))) + '%')
|
||||||
this.lightLevelText.textContent = state.lightLevel.toString();
|
this.lightLevelText.textContent = state.lightLevel.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private applyLightLevel() {
|
private applyLightLevel() {
|
||||||
let lv = this.board.lightLevel;
|
let lv = this.board.lightLevel;
|
||||||
Svg.setGradientValue(this.lightLevelGradient, Math.min(100, Math.max(0, Math.floor(lv * 100 / 255))) + '%')
|
Svg.setGradientValue(this.lightLevelGradient, Math.min(100, Math.max(0, Math.floor(lv * 100 / 255))) + '%')
|
||||||
this.lightLevelText.textContent = lv.toString();
|
this.lightLevelText.textContent = lv.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +349,7 @@ namespace pxsim.micro_bit {
|
|||||||
let y = state.accelerometer.getY();
|
let y = state.accelerometer.getY();
|
||||||
let af = 8 / 1023;
|
let af = 8 / 1023;
|
||||||
|
|
||||||
this.element.style.transform = "perspective(30em) rotateX(" + y*af + "deg) rotateY(" + x*af +"deg)"
|
this.element.style.transform = "perspective(30em) rotateX(" + y * af + "deg) rotateY(" + x * af + "deg)"
|
||||||
this.element.style.perspectiveOrigin = "50% 50% 50%";
|
this.element.style.perspectiveOrigin = "50% 50% 50%";
|
||||||
this.element.style.perspective = "30em";
|
this.element.style.perspective = "30em";
|
||||||
}
|
}
|
||||||
@ -359,9 +360,10 @@ namespace pxsim.micro_bit {
|
|||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"viewBox": "0 0 498 406",
|
"viewBox": "0 0 498 406",
|
||||||
"enable-background": "new 0 0 498 406",
|
"enable-background": "new 0 0 498 406",
|
||||||
"class":"sim",
|
"class": "sim",
|
||||||
"x": "0px",
|
"x": "0px",
|
||||||
"y": "0px"});
|
"y": "0px"
|
||||||
|
});
|
||||||
this.style = <SVGStyleElement>Svg.child(this.element, "style", {});
|
this.style = <SVGStyleElement>Svg.child(this.element, "style", {});
|
||||||
this.style.textContent = `
|
this.style.textContent = `
|
||||||
svg.sim {
|
svg.sim {
|
||||||
@ -464,10 +466,10 @@ svg.sim.grayscale {
|
|||||||
this.element.appendChild(this.g);
|
this.element.appendChild(this.g);
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
let glow = Svg.child(this.defs, "filter", {id:"filterglow", x:"-5%", y:"-5%", width:"120%", height:"120%"});
|
let glow = Svg.child(this.defs, "filter", { id: "filterglow", x: "-5%", y: "-5%", width: "120%", height: "120%" });
|
||||||
Svg.child(glow, "feGaussianBlur", {stdDeviation:"5", result: "glow" });
|
Svg.child(glow, "feGaussianBlur", { stdDeviation: "5", result: "glow" });
|
||||||
let merge = Svg.child(glow, "feMerge", {});
|
let merge = Svg.child(glow, "feMerge", {});
|
||||||
for(let i=0;i<3;++i) Svg.child(merge, "feMergeNode", {in:"glow"})
|
for (let i = 0; i < 3; ++i) Svg.child(merge, "feMergeNode", { in: "glow" })
|
||||||
|
|
||||||
// outline
|
// outline
|
||||||
Svg.path(this.g, "sim-board", "M498,31.9C498,14.3,483.7,0,466.1,0H31.9C14.3,0,0,14.3,0,31.9v342.2C0,391.7,14.3,406,31.9,406h434.2c17.6,0,31.9-14.3,31.9-31.9V31.9z M14.3,206.7c-2.7,0-4.8-2.2-4.8-4.8c0-2.7,2.2-4.8,4.8-4.8c2.7,0,4.8,2.2,4.8,4.8C19.2,204.6,17,206.7,14.3,206.7z M486.2,206.7c-2.7,0-4.8-2.2-4.8-4.8c0-2.72.2-4.8,4.8-4.8c2.7,0,4.8,2.2,4.8,4.8C491,204.6,488.8,206.7,486.2,206.7z");
|
Svg.path(this.g, "sim-board", "M498,31.9C498,14.3,483.7,0,466.1,0H31.9C14.3,0,0,14.3,0,31.9v342.2C0,391.7,14.3,406,31.9,406h434.2c17.6,0,31.9-14.3,31.9-31.9V31.9z M14.3,206.7c-2.7,0-4.8-2.2-4.8-4.8c0-2.7,2.2-4.8,4.8-4.8c2.7,0,4.8,2.2,4.8,4.8C19.2,204.6,17,206.7,14.3,206.7z M486.2,206.7c-2.7,0-4.8-2.2-4.8-4.8c0-2.72.2-4.8,4.8-4.8c2.7,0,4.8,2.2,4.8,4.8C491,204.6,488.8,206.7,486.2,206.7z");
|
||||||
@ -476,33 +478,33 @@ svg.sim.grayscale {
|
|||||||
this.display = Svg.path(this.g, "sim-display", "M333.8,310.3H165.9c-8.3,0-15-6.7-15-15V127.5c0-8.3,6.7-15,15-15h167.8c8.3,0,15,6.7,15,15v167.8C348.8,303.6,342.1,310.3,333.8,310.3z");
|
this.display = Svg.path(this.g, "sim-display", "M333.8,310.3H165.9c-8.3,0-15-6.7-15-15V127.5c0-8.3,6.7-15,15-15h167.8c8.3,0,15,6.7,15,15v167.8C348.8,303.6,342.1,310.3,333.8,310.3z");
|
||||||
|
|
||||||
this.logos = [];
|
this.logos = [];
|
||||||
this.logos.push(Svg.child(this.g, "polygon", {class:"sim-theme", points:"115,56.7 173.1,0 115,0"}));
|
this.logos.push(Svg.child(this.g, "polygon", { class: "sim-theme", points: "115,56.7 173.1,0 115,0" }));
|
||||||
this.logos.push(Svg.path(this.g, "sim-theme", "M114.2,0H25.9C12.1,2.1,0,13.3,0,27.7v83.9L114.2,0z"));
|
this.logos.push(Svg.path(this.g, "sim-theme", "M114.2,0H25.9C12.1,2.1,0,13.3,0,27.7v83.9L114.2,0z"));
|
||||||
this.logos.push(Svg.child(this.g, "polygon", {class:"sim-theme", points:"173,27.9 202.5,0 173,0"}));
|
this.logos.push(Svg.child(this.g, "polygon", { class: "sim-theme", points: "173,27.9 202.5,0 173,0" }));
|
||||||
this.logos.push(Svg.child(this.g, "polygon", {class:"sim-theme", points:"54.1,242.4 54.1,274.1 22.4,274.1"}));
|
this.logos.push(Svg.child(this.g, "polygon", { class: "sim-theme", points: "54.1,242.4 54.1,274.1 22.4,274.1" }));
|
||||||
this.logos.push(Svg.child(this.g, "polygon", {class:"sim-theme", points:"446.2,164.6 446.2,132.8 477.9,132.8"}));
|
this.logos.push(Svg.child(this.g, "polygon", { class: "sim-theme", points: "446.2,164.6 446.2,132.8 477.9,132.8" }));
|
||||||
|
|
||||||
// leds
|
// leds
|
||||||
this.leds = [];
|
this.leds = [];
|
||||||
this.ledsOuter = [];
|
this.ledsOuter = [];
|
||||||
var left = 154, top = 113, ledoffw = 46, ledoffh = 44;
|
let left = 154, top = 113, ledoffw = 46, ledoffh = 44;
|
||||||
for (var i = 0; i < 5; ++i) {
|
for (let i = 0; i < 5; ++i) {
|
||||||
var ledtop = i * ledoffh + top;
|
let ledtop = i * ledoffh + top;
|
||||||
for (var j = 0; j < 5; ++j) {
|
for (let j = 0; j < 5; ++j) {
|
||||||
var ledleft = j * ledoffw + left;
|
let ledleft = j * ledoffw + left;
|
||||||
var k = i * 5 + j;
|
let k = i * 5 + j;
|
||||||
this.ledsOuter.push(Svg.child(this.g, "rect", { class:"sim-led-back", x:ledleft, y:ledtop, width:10, height:20, rx:2, ry:2 }));
|
this.ledsOuter.push(Svg.child(this.g, "rect", { class: "sim-led-back", x: ledleft, y: ledtop, width: 10, height: 20, rx: 2, ry: 2 }));
|
||||||
this.leds.push(Svg.child(this.g, "rect", { class:"sim-led", x:ledleft-2, y:ledtop-2, width:14, height:24, rx:3, ry:3, title:`(${j},${i})`}));
|
this.leds.push(Svg.child(this.g, "rect", { class: "sim-led", x: ledleft - 2, y: ledtop - 2, width: 14, height: 24, rx: 3, ry: 3, title: `(${j},${i})` }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// head
|
// head
|
||||||
this.head = <SVGGElement>Svg.child(this.g, "g", {});
|
this.head = <SVGGElement>Svg.child(this.g, "g", {});
|
||||||
Svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill:'transparent'})
|
Svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill: "transparent" })
|
||||||
this.logos.push(Svg.path(this.head, "sim-theme","M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
|
this.logos.push(Svg.path(this.head, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
|
||||||
this.logos.push(Svg.path(this.head, "sim-theme","M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
|
this.logos.push(Svg.path(this.head, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
|
||||||
this.logos.push(Svg.path(this.head, "sim-theme","M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
|
this.logos.push(Svg.path(this.head, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
|
||||||
this.headText = <SVGTextElement>Svg.child(this.g, "text", { x: 310, y: 100, class:'sim-text' })
|
this.headText = <SVGTextElement>Svg.child(this.g, "text", { x: 310, y: 100, class: "sim-text" })
|
||||||
|
|
||||||
// https://www.microbit.co.uk/device/pins
|
// https://www.microbit.co.uk/device/pins
|
||||||
// P0, P1, P2
|
// P0, P1, P2
|
||||||
@ -510,13 +512,13 @@ svg.sim.grayscale {
|
|||||||
"M16.5,341.2c0,0.4-0.1,0.9-0.1,1.3v60.7c4.1,1.7,8.6,2.7,12.9,2.7h34.4v-64.7h0.3c0,0,0-0.1,0-0.1c0-13-10.6-23.6-23.7-23.6C27.2,317.6,16.5,328.1,16.5,341.2z M21.2,341.6c0-10.7,8.7-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3c0,10.7-8.6,19.3-19.3,19.3C29.9,360.9,21.2,352.2,21.2,341.6z",
|
"M16.5,341.2c0,0.4-0.1,0.9-0.1,1.3v60.7c4.1,1.7,8.6,2.7,12.9,2.7h34.4v-64.7h0.3c0,0,0-0.1,0-0.1c0-13-10.6-23.6-23.7-23.6C27.2,317.6,16.5,328.1,16.5,341.2z M21.2,341.6c0-10.7,8.7-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3c0,10.7-8.6,19.3-19.3,19.3C29.9,360.9,21.2,352.2,21.2,341.6z",
|
||||||
"M139.1,317.3c-12.8,0-22.1,10.3-23.1,23.1V406h46.2v-65.6C162.2,327.7,151.9,317.3,139.1,317.3zM139.3,360.1c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C158.6,351.5,150,360.1,139.3,360.1z",
|
"M139.1,317.3c-12.8,0-22.1,10.3-23.1,23.1V406h46.2v-65.6C162.2,327.7,151.9,317.3,139.1,317.3zM139.3,360.1c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C158.6,351.5,150,360.1,139.3,360.1z",
|
||||||
"M249,317.3c-12.8,0-22.1,10.3-23.1,23.1V406h46.2v-65.6C272.1,327.7,261.8,317.3,249,317.3z M249.4,360.1c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C268.7,351.5,260.1,360.1,249.4,360.1z"
|
"M249,317.3c-12.8,0-22.1,10.3-23.1,23.1V406h46.2v-65.6C272.1,327.7,261.8,317.3,249,317.3z M249.4,360.1c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C268.7,351.5,260.1,360.1,249.4,360.1z"
|
||||||
].map((p,pi) => Svg.path(this.g, "sim-pin sim-pin-touch", p, `P${pi}, ANALOG IN`));
|
].map((p, pi) => Svg.path(this.g, "sim-pin sim-pin-touch", p, `P${pi}, ANALOG IN`));
|
||||||
|
|
||||||
// P3
|
// P3
|
||||||
this.pins.push(Svg.path(this.g, "sim-pin", "M0,357.7v19.2c0,10.8,6.2,20.2,14.4,25.2v-44.4H0z", "P3, ANALOG IN, LED Col 1"));
|
this.pins.push(Svg.path(this.g, "sim-pin", "M0,357.7v19.2c0,10.8,6.2,20.2,14.4,25.2v-44.4H0z", "P3, ANALOG IN, LED Col 1"));
|
||||||
|
|
||||||
[66.7,79.1,91.4,103.7,164.3,176.6,188.9,201.3,213.6,275.2,287.5,299.8,312.1,324.5,385.1,397.4,409.7,422].forEach(x => {
|
[66.7, 79.1, 91.4, 103.7, 164.3, 176.6, 188.9, 201.3, 213.6, 275.2, 287.5, 299.8, 312.1, 324.5, 385.1, 397.4, 409.7, 422].forEach(x => {
|
||||||
this.pins.push(Svg.child(this.g, "rect", {x:x, y:356.7, width:10, height:50, class:"sim-pin"}));
|
this.pins.push(Svg.child(this.g, "rect", { x: x, y: 356.7, width: 10, height: 50, class: "sim-pin" }));
|
||||||
})
|
})
|
||||||
Svg.title(this.pins[4], "P4, ANALOG IN, LED Col 2")
|
Svg.title(this.pins[4], "P4, ANALOG IN, LED Col 2")
|
||||||
Svg.title(this.pins[5], "P5, BUTTON A")
|
Svg.title(this.pins[5], "P5, BUTTON A")
|
||||||
@ -543,22 +545,22 @@ svg.sim.grayscale {
|
|||||||
this.pins.push(Svg.path(this.g, "sim-pin", "M458,317.6c-13,0-23.6,10.6-23.6,23.6c0,0,0,0.1,0,0.1h0V406H469c4.3,0,8.4-1,12.6-2.7v-60.7c0-0.4,0-0.9,0-1.3C481.6,328.1,471,317.6,458,317.6z M457.8,360.9c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C477.1,352.2,468.4,360.9,457.8,360.9z", "GND"));
|
this.pins.push(Svg.path(this.g, "sim-pin", "M458,317.6c-13,0-23.6,10.6-23.6,23.6c0,0,0,0.1,0,0.1h0V406H469c4.3,0,8.4-1,12.6-2.7v-60.7c0-0.4,0-0.9,0-1.3C481.6,328.1,471,317.6,458,317.6z M457.8,360.9c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C477.1,352.2,468.4,360.9,457.8,360.9z", "GND"));
|
||||||
|
|
||||||
|
|
||||||
this.pinGradients = this.pins.map((pin,i) => {
|
this.pinGradients = this.pins.map((pin, i) => {
|
||||||
let gid= "gradient-pin-" + i
|
let gid = "gradient-pin-" + i
|
||||||
let lg = Svg.linearGradient(this.defs, gid)
|
let lg = Svg.linearGradient(this.defs, gid)
|
||||||
pin.setAttribute("fill", `url(#${gid})`);
|
pin.setAttribute("fill", `url(#${gid})`);
|
||||||
return lg;
|
return lg;
|
||||||
})
|
})
|
||||||
|
|
||||||
this.pinTexts = [67,165,275].map(x => <SVGTextElement>Svg.child(this.g, "text", { class:'sim-text-pin', x:x, y:345}));
|
this.pinTexts = [67, 165, 275].map(x => <SVGTextElement>Svg.child(this.g, "text", { class: 'sim-text-pin', x: x, y: 345 }));
|
||||||
|
|
||||||
this.buttonsOuter = []; this.buttons = [];
|
this.buttonsOuter = []; this.buttons = [];
|
||||||
this.buttonsOuter.push(Svg.path(this.g, "sim-button-outer", "M82.1,232.6H25.9c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C83,232.2,82.6,232.6,82.1,232.6", "A"));
|
this.buttonsOuter.push(Svg.path(this.g, "sim-button-outer", "M82.1,232.6H25.9c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C83,232.2,82.6,232.6,82.1,232.6", "A"));
|
||||||
this.buttons.push(Svg.path(this.g, "sim-button", "M69.7,203.5c0,8.7-7,15.7-15.7,15.7s-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7S69.7,194.9,69.7,203.5"));
|
this.buttons.push(Svg.path(this.g, "sim-button", "M69.7,203.5c0,8.7-7,15.7-15.7,15.7s-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7S69.7,194.9,69.7,203.5"));
|
||||||
this.buttonsOuter.push(Svg.path(this.g, "sim-button-outer", "M474.3,232.6h-56.2c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C475.3,232.2,474.8,232.6,474.3,232.6", "B"));
|
this.buttonsOuter.push(Svg.path(this.g, "sim-button-outer", "M474.3,232.6h-56.2c-0.5,0-1-0.4-1-1v-56.2c0-0.5,0.4-1,1-1h56.2c0.5,0,1,0.4,1,1v56.2C475.3,232.2,474.8,232.6,474.3,232.6", "B"));
|
||||||
this.buttons.push(Svg.path(this.g, "sim-button", "M461.9,203.5c0,8.7-7,15.7-15.7,15.7c-8.7,0-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7C454.9,187.8,461.9,194.9,461.9,203.5"));
|
this.buttons.push(Svg.path(this.g, "sim-button", "M461.9,203.5c0,8.7-7,15.7-15.7,15.7c-8.7,0-15.7-7-15.7-15.7c0-8.7,7-15.7,15.7-15.7C454.9,187.8,461.9,194.9,461.9,203.5"));
|
||||||
this.buttonsOuter.push(Svg.child(this.g, "rect", {class:"sim-button-outer", x:417, y:250, width:58, height:58, rx:1, ry:1, title:"A+B"}));
|
this.buttonsOuter.push(Svg.child(this.g, "rect", { class: "sim-button-outer", x: 417, y: 250, width: 58, height: 58, rx: 1, ry: 1, title: "A+B" }));
|
||||||
this.buttons.push(Svg.child(this.g, "circle", {class:"sim-button", cx:446, cy:278, r:16.5}));
|
this.buttons.push(Svg.child(this.g, "circle", { class: "sim-button", cx: 446, cy: 278, r: 16.5 }));
|
||||||
(<any>this.buttonsOuter[2]).style.visibility = 'hidden';
|
(<any>this.buttonsOuter[2]).style.visibility = 'hidden';
|
||||||
(<any>this.buttons[2]).style.visibility = 'hidden';
|
(<any>this.buttons[2]).style.visibility = 'hidden';
|
||||||
|
|
||||||
@ -577,7 +579,7 @@ svg.sim.grayscale {
|
|||||||
|
|
||||||
private attachEvents() {
|
private attachEvents() {
|
||||||
Runtime.messagePosted = (msg) => {
|
Runtime.messagePosted = (msg) => {
|
||||||
switch(msg.type || '') {
|
switch (msg.type || '') {
|
||||||
case 'serial': this.flashSystemLed(); break;
|
case 'serial': this.flashSystemLed(); break;
|
||||||
case 'radiopacket': this.flashAntenna(); break;
|
case 'radiopacket': this.flashAntenna(); break;
|
||||||
}
|
}
|
||||||
@ -597,10 +599,10 @@ svg.sim.grayscale {
|
|||||||
|
|
||||||
let x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023)));
|
let x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023)));
|
||||||
let y = Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023)));
|
let y = Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023)));
|
||||||
let z2 = 1023*1023 - x * x - y * y;
|
let z2 = 1023 * 1023 - x * x - y * y;
|
||||||
let z = Math.floor((z2 > 0 ? -1 : 1)* Math.sqrt(Math.abs(z2)));
|
let z = Math.floor((z2 > 0 ? -1 : 1) * Math.sqrt(Math.abs(z2)));
|
||||||
|
|
||||||
state.accelerometer.update(x,y,z);
|
state.accelerometer.update(x, y, z);
|
||||||
this.updateTilt();
|
this.updateTilt();
|
||||||
}, false);
|
}, false);
|
||||||
this.element.addEventListener(pointerEvents.leave, (ev: MouseEvent) => {
|
this.element.addEventListener(pointerEvents.leave, (ev: MouseEvent) => {
|
||||||
@ -613,7 +615,7 @@ svg.sim.grayscale {
|
|||||||
accx = Math.floor(Math.abs(accx) * 0.85) * (accx > 0 ? 1 : -1);
|
accx = Math.floor(Math.abs(accx) * 0.85) * (accx > 0 ? 1 : -1);
|
||||||
let accy = state.accelerometer.getY(MicroBitCoordinateSystem.RAW);
|
let accy = state.accelerometer.getY(MicroBitCoordinateSystem.RAW);
|
||||||
accy = Math.floor(Math.abs(accy) * 0.85) * (accy > 0 ? 1 : -1);
|
accy = Math.floor(Math.abs(accy) * 0.85) * (accy > 0 ? 1 : -1);
|
||||||
let accz = -Math.sqrt(Math.max(0, 1023*1023 - accx*accx - accy*accy));
|
let accz = -Math.sqrt(Math.max(0, 1023 * 1023 - accx * accx - accy * accy));
|
||||||
if (Math.abs(accx) <= 24 && Math.abs(accy) <= 24) {
|
if (Math.abs(accx) <= 24 && Math.abs(accy) <= 24) {
|
||||||
clearInterval(tiltDecayer);
|
clearInterval(tiltDecayer);
|
||||||
tiltDecayer = 0;
|
tiltDecayer = 0;
|
||||||
@ -623,7 +625,7 @@ svg.sim.grayscale {
|
|||||||
}
|
}
|
||||||
state.accelerometer.update(accx, accy, accz);
|
state.accelerometer.update(accx, accy, accz);
|
||||||
this.updateTilt();
|
this.updateTilt();
|
||||||
}, 50)
|
}, 50)
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
@ -641,32 +643,32 @@ svg.sim.grayscale {
|
|||||||
let v = (400 - cursor.y) / 40 * 1023
|
let v = (400 - cursor.y) / 40 * 1023
|
||||||
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
||||||
}
|
}
|
||||||
this.updatePin(pin,index);
|
this.updatePin(pin, index);
|
||||||
},
|
},
|
||||||
// start
|
// start
|
||||||
ev => {
|
ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
let pin = state.pins[index];
|
let pin = state.pins[index];
|
||||||
let svgpin = this.pins[index];
|
let svgpin = this.pins[index];
|
||||||
Svg.addClass(svgpin, 'touched');
|
Svg.addClass(svgpin, "touched");
|
||||||
if (pin.mode & PinMode.Input) {
|
if (pin.mode & PinMode.Input) {
|
||||||
let cursor = Svg.cursorPoint(pt, this.element, ev);
|
let cursor = Svg.cursorPoint(pt, this.element, ev);
|
||||||
let v = (400 - cursor.y) / 40 * 1023
|
let v = (400 - cursor.y) / 40 * 1023
|
||||||
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
pin.value = Math.max(0, Math.min(1023, Math.floor(v)));
|
||||||
}
|
}
|
||||||
this.updatePin(pin,index);
|
this.updatePin(pin, index);
|
||||||
},
|
},
|
||||||
// stop
|
// stop
|
||||||
(ev: MouseEvent) => {
|
(ev: MouseEvent) => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
let pin = state.pins[index];
|
let pin = state.pins[index];
|
||||||
let svgpin = this.pins[index];
|
let svgpin = this.pins[index];
|
||||||
Svg.removeClass(svgpin, 'touched');
|
Svg.removeClass(svgpin, "touched");
|
||||||
this.updatePin(pin, index);
|
this.updatePin(pin, index);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
this.pins.slice(0,3).forEach((btn, index) => {
|
this.pins.slice(0, 3).forEach((btn, index) => {
|
||||||
btn.addEventListener(pointerEvents.down, ev => {
|
btn.addEventListener(pointerEvents.down, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
state.pins[index].touched = true;
|
state.pins[index].touched = true;
|
||||||
@ -684,7 +686,7 @@ svg.sim.grayscale {
|
|||||||
this.board.bus.queue(state.pins[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
this.board.bus.queue(state.pins[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.buttonsOuter.slice(0,2).forEach((btn, index) => {
|
this.buttonsOuter.slice(0, 2).forEach((btn, index) => {
|
||||||
btn.addEventListener(pointerEvents.down, ev => {
|
btn.addEventListener(pointerEvents.down, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
state.buttons[index].pressed = true;
|
state.buttons[index].pressed = true;
|
||||||
@ -704,33 +706,33 @@ svg.sim.grayscale {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.buttonsOuter[2].addEventListener(pointerEvents.down, ev => {
|
this.buttonsOuter[2].addEventListener(pointerEvents.down, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
state.buttons[0].pressed = true;
|
state.buttons[0].pressed = true;
|
||||||
state.buttons[1].pressed = true;
|
state.buttons[1].pressed = true;
|
||||||
state.buttons[2].pressed = true;
|
state.buttons[2].pressed = true;
|
||||||
Svg.fill(this.buttons[0], this.props.theme.buttonDown);
|
Svg.fill(this.buttons[0], this.props.theme.buttonDown);
|
||||||
Svg.fill(this.buttons[1], this.props.theme.buttonDown);
|
Svg.fill(this.buttons[1], this.props.theme.buttonDown);
|
||||||
Svg.fill(this.buttons[2], this.props.theme.buttonDown);
|
Svg.fill(this.buttons[2], this.props.theme.buttonDown);
|
||||||
})
|
})
|
||||||
this.buttonsOuter[2].addEventListener(pointerEvents.leave, ev => {
|
this.buttonsOuter[2].addEventListener(pointerEvents.leave, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
state.buttons[0].pressed = false;
|
state.buttons[0].pressed = false;
|
||||||
state.buttons[1].pressed = false;
|
state.buttons[1].pressed = false;
|
||||||
state.buttons[2].pressed = false;
|
state.buttons[2].pressed = false;
|
||||||
Svg.fill(this.buttons[0], this.props.theme.buttonUp);
|
Svg.fill(this.buttons[0], this.props.theme.buttonUp);
|
||||||
Svg.fill(this.buttons[1], this.props.theme.buttonUp);
|
Svg.fill(this.buttons[1], this.props.theme.buttonUp);
|
||||||
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
|
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
|
||||||
})
|
})
|
||||||
this.buttonsOuter[2].addEventListener(pointerEvents.up, ev => {
|
this.buttonsOuter[2].addEventListener(pointerEvents.up, ev => {
|
||||||
let state = this.board;
|
let state = this.board;
|
||||||
state.buttons[0].pressed = false;
|
state.buttons[0].pressed = false;
|
||||||
state.buttons[1].pressed = false;
|
state.buttons[1].pressed = false;
|
||||||
state.buttons[2].pressed = false;
|
state.buttons[2].pressed = false;
|
||||||
Svg.fill(this.buttons[0], this.props.theme.buttonUp);
|
Svg.fill(this.buttons[0], this.props.theme.buttonUp);
|
||||||
Svg.fill(this.buttons[1], this.props.theme.buttonUp);
|
Svg.fill(this.buttons[1], this.props.theme.buttonUp);
|
||||||
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
|
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
|
||||||
|
|
||||||
this.board.bus.queue(state.buttons[2].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
this.board.bus.queue(state.buttons[2].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
tslint.json
Normal file
56
tslint.json
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"semicolon": [
|
||||||
|
false,
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
false,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"typedef-whitespace": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"variable-name": [
|
||||||
|
true,
|
||||||
|
"ban-keywords"
|
||||||
|
],
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user