diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 607e5a0..a4d4196 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -95,13 +95,21 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow EventModel::defaultEventBus->listen(flow->id, DEVICE_PIN_EVENT_ON_EDGE, this, &JDDisplay::onFlowHi, MESSAGE_BUS_LISTENER_IMMEDIATE); flow->eventOn(DEVICE_PIN_EVT_RISE); -} + // set up polling for buttons + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, + &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); +} -/** -* Deprecated; no longer neccessary. sendIndexedImage handles this. -*/ -void JDDisplay::waitForSendDone() {} +void JDDisplay::pollButtons(Event) { + if (stepWaiting) { + if (stepPrefix()) + return; + // stepWaiting == false + flushSend(); + sendDone(this); + } +} void JDDisplay::sendDone(JDDisplay* jdd) { inProgressLock.notify(); @@ -215,12 +223,12 @@ void JDDisplay::handleIncoming(jd_packet_t *pkt) { buttonState = state; } } else { - // TODO remove later VLOG("JDA: unknown packet for %d (cmd=%x)", pkt->service_number, pkt->service_command); } } -void JDDisplay::step() { + +bool JDDisplay::stepPrefix() { if (cs) cs->setDigitalValue(1); @@ -228,10 +236,9 @@ void JDDisplay::step() { if (!flow->getDigitalValue()) { stepWaiting = true; target_enable_irq(); - return; - } else { - stepWaiting = false; + return true; } + stepWaiting = false; target_enable_irq(); memset(&sendFrame, 0, JD_SERIAL_FULL_HEADER_SIZE); @@ -251,14 +258,19 @@ void JDDisplay::step() { break; } } - if (displayServiceNum == 0) { // poke the control service to enumerate queuePkt(JD_SERVICE_NUMBER_CTRL, JD_CMD_ADVERTISEMENT_DATA, 0); flushSend(); - return; + return true; } + return false; +} +void JDDisplay::step() { + if (stepPrefix()) + return; + // stepWaiting == false if (palette) { { #define PALETTE_SIZE (16 * 4) diff --git a/cpp/jddisplay.h b/cpp/jddisplay.h index d1ed7df..de63b87 100644 --- a/cpp/jddisplay.h +++ b/cpp/jddisplay.h @@ -44,12 +44,13 @@ class JDDisplay { void *queuePkt(uint32_t service_num, uint32_t service_cmd, uint32_t size); void flushSend(); + bool stepPrefix(); void step(); void sendDone(JDDisplay* jdd); static void stepStatic(void *); void onFlowHi(Event); void handleIncoming(jd_packet_t *pkt); - + void pollButtons(Event); public: uint8_t brightness; JDDisplay(SPI *spi, Pin *cs, Pin *flow); @@ -59,8 +60,6 @@ class JDDisplay { addr.width = w; addr.height = h; } - void waitForSendDone(); - int sendIndexedImage(const uint8_t *src, unsigned width, unsigned height, uint32_t *palette); }; diff --git a/cpp/screen.cpp b/cpp/screen.cpp index 7621106..f057cac 100644 --- a/cpp/screen.cpp +++ b/cpp/screen.cpp @@ -197,12 +197,6 @@ class WDisplay { else smart->setAddrWindow(offX, offY, width, displayHeight); } - void waitForSendDone() { - if (lcd) - lcd->waitForSendDone(); - else - smart->waitForSendDone(); - } int sendIndexedImage(const uint8_t *src, unsigned width, unsigned height, uint32_t *palette) { if (lcd) @@ -323,9 +317,6 @@ void updateScreen(Bitmap_ img) { img->height() * mult != display->displayHeight) target_panic(131); // PANIC_SCREEN_ERROR - // DMESG("wait for done"); - display->waitForSendDone(); - auto palette = display->currPalette; if (display->newPalette) { diff --git a/test.ts b/test.ts index 56a105f..7b2cce5 100644 --- a/test.ts +++ b/test.ts @@ -1,27 +1,31 @@ -// namespace config { -// export const DISPLAY_CFG0 = 0x02030180 // allow execution without shield plugged in -// } +controller.left.onEvent(ControllerButtonEvent.Pressed, function () { + screen().fill(8) + screen().drawLine(0, 0, 160, 120, 1) + screen().drawLine(160, 0, 0, 120, 1) +}) -// tests go here; this will not be compiled when this package is used as an extension. +controller.right.onEvent(ControllerButtonEvent.Pressed, function () { + screen().fill(0) + screen().fillCircle(0, 0, 20, 3) + screen().fillCircle(160, 0, 20, 9) + screen().fillCircle(160, 120, 20, 7) + screen().fillCircle(0, 120, 20, 5) +}) -const present = shieldhelpers.shieldPresent(); +let presses = 0; +controller.A.onEvent( + ControllerButtonEvent.Pressed, + () => { + presses += 1 +}) -basic.showNumber(present ? 1 : 0) +controller.B.onEvent( + ControllerButtonEvent.Pressed, + () => { + presses = 0 + }) + +input.onButtonPressed(Button.A, () => { + basic.showNumber(presses) +}) -while (true) { - let x = 0 - let my = theScreen.height -1 - theScreen.fill(0) - theScreen.print((my+1).toString(), 60, 60) - while (x < 160) { - theScreen.setPixel(x, 0, 9) - theScreen.setPixel(x, 2, 10) - theScreen.setPixel(x, 4, 11) - theScreen.setPixel(x, my, 9) - theScreen.setPixel(x, my - 2, 10) - theScreen.setPixel(x, my - 4, 11) - x++ - basic.pause(100) - // pause - } -}