Implement button mmap

This commit is contained in:
Michal Moskal
2017-07-11 11:40:40 +02:00
parent 46c18af461
commit 4f6941e6cf
3 changed files with 128 additions and 9 deletions

View File

@ -1,6 +1,6 @@
namespace pxsim {
export class EV3ButtonState extends CommonButtonState{
export class EV3ButtonState extends CommonButtonState {
constructor() {
super();
@ -13,6 +13,24 @@ namespace pxsim {
new CommonButton(DAL.BUTTON_ID_ESCAPE),
new CommonButton(DAL.BUTTON_ID_ALL)
];
let data = new Uint8Array(this.buttons.length)
MMapMethods.register("/dev/lms_ui", {
data,
beforeMemRead: () => {
for (let i = 0; i < this.buttons.length; ++i)
data[i] = this.buttons[i].isPressed() ? 1 : 0
},
read: buf => {
let v = "vSIM"
for (let i = 0; i < buf.data.length; ++i)
buf.data[i] = v.charCodeAt(i) || 0
return buf.data.length
},
write: buf => {
pxsim.output.setLights(buf.data[0] - 48)
return 2
}
})
}
}
}