various fixes around rendering of pin values

This commit is contained in:
Peli de Halleux 2016-03-14 09:10:13 -07:00
parent d31c5360ed
commit 7f57eda606
3 changed files with 10 additions and 4 deletions

View File

@ -387,12 +387,14 @@ namespace ks.rt.micro_bit {
} }
export function enablePitch(pin: Pin) { export function enablePitch(pin: Pin) {
pin.mode = PinMode.Analog | PinMode.Output | PinMode.Pitch; board().pins.filter(p => !!p).forEach(p => p.pitch = false);
pin.pitch = true;
} }
export function pitch(frequency: number, ms: number) { export function pitch(frequency: number, ms: number) {
// update analog output // update analog output
let pin = board().pins.filter(pin => !!pin && (pin.mode & PinMode.Pitch) != 0)[0] || board().pins[0]; let pin = board().pins.filter(pin => !!pin && pin.pitch)[0] || board().pins[0];
pin.mode = PinMode.Analog | PinMode.Output;
if (frequency <= 0) { if (frequency <= 0) {
pin.value = 0; pin.value = 0;
pin.period = 0; pin.period = 0;
@ -410,6 +412,7 @@ namespace ks.rt.micro_bit {
AudioContextManager.stop(); AudioContextManager.stop();
pin.value = 0; pin.value = 0;
pin.period = 0; pin.period = 0;
pin.mode = PinMode.Unused;
board().updateView(); board().updateView();
cb() cb()
}, ms); }, ms);

View File

@ -228,6 +228,9 @@ namespace ks.rt.micro_bit {
else if (pin.mode & PinMode.Touch) { else if (pin.mode & PinMode.Touch) {
v = pin.touched ? '0%' : '100%'; v = pin.touched ? '0%' : '100%';
if (text) text.textContent = ""; if (text) text.textContent = "";
} else {
v = '100%';
if(text) text.textContent = '';
} }
if (v) Svg.setGradientValue(this.pinGradients[index], v); if (v) Svg.setGradientValue(this.pinGradients[index], v);
} }

View File

@ -14,8 +14,7 @@ namespace ks.rt.micro_bit {
Analog = 0x0002, Analog = 0x0002,
Input = 0x0004, Input = 0x0004,
Output = 0x0008, Output = 0x0008,
Touch = 0x0010, Touch = 0x0010
Pitch = 0x0020
} }
export class Pin { export class Pin {
@ -24,6 +23,7 @@ namespace ks.rt.micro_bit {
value = 0; value = 0;
period = 0; period = 0;
mode = PinMode.Unused; mode = PinMode.Unused;
pitch = false;
isTouched(): boolean { isTouched(): boolean {
this.mode = PinMode.Touch; this.mode = PinMode.Touch;