Make scroll work

This commit is contained in:
Michal Moskal 2017-07-05 19:17:26 +01:00
parent ddc53df7f8
commit 3e9a94d35f
2 changed files with 32 additions and 6 deletions

View File

@ -23,6 +23,18 @@ enum class ScreenFont {
// We only support up to 4 arguments for C++ functions - need to pack them on the TS side
namespace screen {
extern "C" {
void DisplaySetPixel(byte X, byte Y);
void DisplayClrPixel(byte X, byte Y);
void DisplayXorPixel(byte X, byte Y);
}
void pokeScreen() {
DisplayXorPixel(0, 0);
DisplayXorPixel(0, 0);
}
//%
void _drawLine(uint32_t p0, uint32_t p1, Draw mode) {
DMESG("line %x %x %x", p0, p1, mode);
@ -57,6 +69,8 @@ void clear() {
//%
void scroll(int v) {
LcdScroll(v);
pokeScreen(); // missing in ev3-api
//LcdUpdate();
}
/** Set font for drawText() */
@ -64,5 +78,4 @@ void scroll(int v) {
void setFont(ScreenFont font) {
LcdSelectFont((uint8_t)font);
}
}

View File

@ -1,23 +1,36 @@
screen.clear()
screen.setFont(ScreenFont.Large)
screen.drawText(10, 30, "Hello PXT!")
screen.drawRect(10, 70, 20, 10, Draw.Fill)
screen.drawEllipse(40, 40, 20, 10)
output.setLights(LightsPattern.GreenPulse)
screen.drawEllipse(40, 40, 20, 10, Draw.Fill)
output.setLights(LightsPattern.Orange)
input.buttonEnter.onEvent(ButtonEvent.Click, () => {
screen.clear()
})
input.buttonLeft.onEvent(ButtonEvent.Click, () => {
screen.drawRect(10, 70, 20, 10, Draw.Fill)
})
input.buttonRight.onEvent(ButtonEvent.Click, () => {
screen.setFont(ScreenFont.Normal)
screen.drawText(10, 60, "Bang!")
})
input.buttonDown.onEvent(ButtonEvent.Click, () => {
screen.scroll(10)
screen.scroll(-10)
})
input.buttonUp.onEvent(ButtonEvent.Click, () => {
screen.scroll(-10)
screen.scroll(10)
})
for (let i = 0; i < 3; ++i) {
loops.forever(() => {
let r = Math.randomRange(0, 100)
serial.writeValue("R", r)
//screen.drawText(10, 10, `R=${r}`)
loops.pause(1000)
})
loops.pause(300)