support for rgb led in simulator

This commit is contained in:
Peli de Halleux
2016-10-11 11:41:51 -07:00
parent cb280af783
commit c4787e1028
5 changed files with 60 additions and 21 deletions

View File

@ -1,5 +1,6 @@
namespace pxsim.basic {
export function setLedColor(c: number) {
board().rgbLedState = c;
runtime.queueDisplayUpdate()
}
}

View File

@ -352,8 +352,16 @@ namespace pxsim.visuals {
let state = this.board;
if (state.rgbLedState) {
if (!this.rgbLed)
this.rgbLed = svg.child(this.g, "circle", { cx: 170, cy: 200 });
svg.fill(this.rgbLed, svg.toHtmlColor(state.rgbLedState));
this.rgbLed = svg.child(this.g, "circle", { cx: 170, cy: 190, r:5 });
const c = state.rgbLedState;
const b = c & 0xFF;
const g = (c >> 8) & 0xFF;
const r = (c >> 16) & 0xFF;
const w = (c >> 24) & 0xFF;
const ch = `rgba(${r}, ${g}, ${b}, 1)`;
svg.fill(this.rgbLed, ch);
} else if (this.rgbLed) {
svg.fill(this.rgbLed, 'white');
}
}