From 6e44f7a0e883c9d71a0a9b080d54d796ed2f71fc Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 11:42:17 +0000 Subject: [PATCH 01/27] parameterize step function --- cpp/jddisplay.cpp | 4 +++- cpp/jddisplay.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 607e5a0..886d60e 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -220,7 +220,7 @@ void JDDisplay::handleIncoming(jd_packet_t *pkt) { } } -void JDDisplay::step() { +void JDDisplay::step(bool sendImage = true) { if (cs) cs->setDigitalValue(1); @@ -250,6 +250,8 @@ void JDDisplay::step() { if (!jd_shift_frame(&recvFrame)) break; } + if (!sendImage) + return } if (displayServiceNum == 0) { diff --git a/cpp/jddisplay.h b/cpp/jddisplay.h index d1ed7df..ad307bd 100644 --- a/cpp/jddisplay.h +++ b/cpp/jddisplay.h @@ -44,7 +44,7 @@ class JDDisplay { void *queuePkt(uint32_t service_num, uint32_t service_cmd, uint32_t size); void flushSend(); - void step(); + void step(bool sendImage = true); void sendDone(JDDisplay* jdd); static void stepStatic(void *); void onFlowHi(Event); From bcd49b74103289a0463d7b790e8d6cf1ade1c734 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 11:51:19 +0000 Subject: [PATCH 02/27] plumbing set up --- cpp/jddisplay.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 886d60e..d842639 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -95,8 +95,16 @@ 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, + &JDDisplat::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } +void JDDisplay::pollButtons() { + // TODO: need to be sure we don't conflict with other calls to step + step(false); +} /** * Deprecated; no longer neccessary. sendIndexedImage handles this. @@ -215,7 +223,7 @@ void JDDisplay::handleIncoming(jd_packet_t *pkt) { buttonState = state; } } else { - // TODO remove later + // TODO remove latering VLOG("JDA: unknown packet for %d (cmd=%x)", pkt->service_number, pkt->service_command); } } From 38e78aab3684ca8d21f236aac935904c73491bf5 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 11:52:45 +0000 Subject: [PATCH 03/27] remove comment --- cpp/jddisplay.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index d842639..4121b08 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -223,7 +223,6 @@ void JDDisplay::handleIncoming(jd_packet_t *pkt) { buttonState = state; } } else { - // TODO remove latering VLOG("JDA: unknown packet for %d (cmd=%x)", pkt->service_number, pkt->service_command); } } From c0ca8e51ed6ffb6017570b3b6ec5876364451f35 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 12:32:15 +0000 Subject: [PATCH 04/27] fix errors --- cpp/jddisplay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 4121b08..17a1f95 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -98,7 +98,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow // set up polling for buttons EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, - &JDDisplat::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); + &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } void JDDisplay::pollButtons() { @@ -227,7 +227,7 @@ void JDDisplay::handleIncoming(jd_packet_t *pkt) { } } -void JDDisplay::step(bool sendImage = true) { +void JDDisplay::step(bool sendImage) { if (cs) cs->setDigitalValue(1); From 5740fb9cc029b2a8300793436cc21f622220f2bc Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 12:35:02 +0000 Subject: [PATCH 05/27] fix typo --- cpp/jddisplay.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 17a1f95..99590ea 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -257,8 +257,9 @@ void JDDisplay::step(bool sendImage) { if (!jd_shift_frame(&recvFrame)) break; } - if (!sendImage) - return + if (!sendImage) { + return; + } } if (displayServiceNum == 0) { From 7a53f24d51ca3aabc81faab9df3d5394c044cc40 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 12:39:07 +0000 Subject: [PATCH 06/27] oops, forgot to add pollButtons to .h --- cpp/jddisplay.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/jddisplay.h b/cpp/jddisplay.h index ad307bd..d616fd3 100644 --- a/cpp/jddisplay.h +++ b/cpp/jddisplay.h @@ -59,6 +59,7 @@ class JDDisplay { addr.width = w; addr.height = h; } + void pollButtons(); void waitForSendDone(); int sendIndexedImage(const uint8_t *src, unsigned width, unsigned height, uint32_t *palette); From c03cb90b6f9111ebce9497740b2e17dacf210cb2 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 12:42:17 +0000 Subject: [PATCH 07/27] forgot this param --- cpp/jddisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 99590ea..598bf07 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,7 +97,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow flow->eventOn(DEVICE_PIN_EVT_RISE); // set up polling for buttons - EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } From 792bf5fcfaf31dddc835b42ca32cf00c6b5ca873 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:26:15 +0000 Subject: [PATCH 08/27] eliminate race on step proc --- cpp/jddisplay.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 598bf07..ff6b5d7 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -102,7 +102,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow } void JDDisplay::pollButtons() { - // TODO: need to be sure we don't conflict with other calls to step + inProgressLock.wait(); step(false); } @@ -258,6 +258,7 @@ void JDDisplay::step(bool sendImage) { break; } if (!sendImage) { + sendDone(this); return; } } From cdd7d50b8193d15162f1ff220661d652baacd5cd Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:27:22 +0000 Subject: [PATCH 09/27] remove waitForSendDone --- cpp/jddisplay.cpp | 4 ---- cpp/jddisplay.h | 2 -- cpp/screen.cpp | 9 --------- 3 files changed, 15 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index ff6b5d7..1fa92c9 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -106,10 +106,6 @@ void JDDisplay::pollButtons() { step(false); } -/** -* Deprecated; no longer neccessary. sendIndexedImage handles this. -*/ -void JDDisplay::waitForSendDone() {} void JDDisplay::sendDone(JDDisplay* jdd) { inProgressLock.notify(); diff --git a/cpp/jddisplay.h b/cpp/jddisplay.h index d616fd3..556df4d 100644 --- a/cpp/jddisplay.h +++ b/cpp/jddisplay.h @@ -60,8 +60,6 @@ class JDDisplay { addr.height = h; } void pollButtons(); - 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) { From 9132a8ac424af0f4a88b6e9924f8d4571dcd5ccf Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:41:48 +0000 Subject: [PATCH 10/27] fix types --- cpp/jddisplay.cpp | 2 +- cpp/jddisplay.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 1fa92c9..8810424 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -101,7 +101,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } -void JDDisplay::pollButtons() { +void JDDisplay::pollButtons(Event) { inProgressLock.wait(); step(false); } diff --git a/cpp/jddisplay.h b/cpp/jddisplay.h index 556df4d..a1b701e 100644 --- a/cpp/jddisplay.h +++ b/cpp/jddisplay.h @@ -49,7 +49,7 @@ class JDDisplay { 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,7 +59,6 @@ class JDDisplay { addr.width = w; addr.height = h; } - void pollButtons(); int sendIndexedImage(const uint8_t *src, unsigned width, unsigned height, uint32_t *palette); }; From a237e699b083dccfb62bcfbd93c02e034604c1a5 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:58:30 +0000 Subject: [PATCH 11/27] remove listener --- cpp/jddisplay.cpp | 4 ++-- test.ts | 39 ++++++++++++--------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 8810424..f6fdaed 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,8 +97,8 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow 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); + // EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, + // &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } void JDDisplay::pollButtons(Event) { diff --git a/test.ts b/test.ts index 56a105f..8c1da1f 100644 --- a/test.ts +++ b/test.ts @@ -1,27 +1,12 @@ -// namespace config { -// export const DISPLAY_CFG0 = 0x02030180 // allow execution without shield plugged in -// } - -// tests go here; this will not be compiled when this package is used as an extension. - -const present = shieldhelpers.shieldPresent(); - -basic.showNumber(present ? 1 : 0) - -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 - } -} +controller.B.onEvent(ControllerButtonEvent.Pressed, function () { + screen().fill(8) + screen().drawLine(0, 0, 160, 120, 1) + screen().drawLine(160, 0, 0, 120, 1) +}) +controller.A.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) +}) From 06fc25b41981a35fc573855e1be42b839d121b9c Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:06:12 +0000 Subject: [PATCH 12/27] no immediate --- cpp/jddisplay.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index f6fdaed..607e5a0 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -95,17 +95,13 @@ 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); } -void JDDisplay::pollButtons(Event) { - inProgressLock.wait(); - step(false); -} +/** +* Deprecated; no longer neccessary. sendIndexedImage handles this. +*/ +void JDDisplay::waitForSendDone() {} void JDDisplay::sendDone(JDDisplay* jdd) { inProgressLock.notify(); @@ -219,11 +215,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 sendImage) { +void JDDisplay::step() { if (cs) cs->setDigitalValue(1); @@ -253,10 +250,6 @@ void JDDisplay::step(bool sendImage) { if (!jd_shift_frame(&recvFrame)) break; } - if (!sendImage) { - sendDone(this); - return; - } } if (displayServiceNum == 0) { From cf657e79d7ac8de6d966ddefed596fd1f0885095 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:06:23 +0000 Subject: [PATCH 13/27] no immediate --- cpp/jddisplay.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 607e5a0..6b190ae 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -95,6 +95,9 @@ 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) } From 02837284ff9cdea0a352060eb01a483835a9b4d6 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:10:31 +0000 Subject: [PATCH 14/27] forgot ; --- cpp/jddisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 6b190ae..21e6ae4 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,7 +97,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow 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) + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons); } From f2bf9e764fabc1ad2df8e688ac577314e0326fa7 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:18:19 +0000 Subject: [PATCH 15/27] Revert "forgot ;" This reverts commit 02837284ff9cdea0a352060eb01a483835a9b4d6. --- cpp/jddisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 21e6ae4..6b190ae 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,7 +97,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow 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); + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons) } From a1d62a50dc4dac25393c19961b3bdb5b5d13c935 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:20:46 +0000 Subject: [PATCH 16/27] Revert "no immediate" This reverts commit 06fc25b41981a35fc573855e1be42b839d121b9c. --- cpp/jddisplay.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 6b190ae..5bcbd0b 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -218,12 +218,11 @@ 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() { +void JDDisplay::step(bool sendImage) { if (cs) cs->setDigitalValue(1); @@ -253,6 +252,10 @@ void JDDisplay::step() { if (!jd_shift_frame(&recvFrame)) break; } + if (!sendImage) { + sendDone(this); + return; + } } if (displayServiceNum == 0) { From 7997a6be001440b74108712c11c1d6ee79fa0d2a Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:23:18 +0000 Subject: [PATCH 17/27] more changes --- cpp/jddisplay.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 5bcbd0b..80f8454 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -100,12 +100,6 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons) } - -/** -* Deprecated; no longer neccessary. sendIndexedImage handles this. -*/ -void JDDisplay::waitForSendDone() {} - void JDDisplay::sendDone(JDDisplay* jdd) { inProgressLock.notify(); } From 9bb786d8f7237363d9ab28ec1cee7df5488f83e4 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:25:56 +0000 Subject: [PATCH 18/27] replay reverted change --- cpp/jddisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 80f8454..7131065 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,7 +97,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow 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) + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons); } void JDDisplay::sendDone(JDDisplay* jdd) { From d5b670772fe0c20b2d474173e392be4e09d92a4f Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:31:09 +0000 Subject: [PATCH 19/27] replay some more --- cpp/jddisplay.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 7131065..49373c3 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -100,6 +100,11 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, &JDDisplay::pollButtons); } +void JDDisplay::pollButtons(Event) { + inProgressLock.wait(); + step(false) +} + void JDDisplay::sendDone(JDDisplay* jdd) { inProgressLock.notify(); } From 0598b1c3c2a18ae1cc09f13122f3459dea97408d Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:34:32 +0000 Subject: [PATCH 20/27] oops --- cpp/jddisplay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 49373c3..a6850d5 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -102,7 +102,7 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow void JDDisplay::pollButtons(Event) { inProgressLock.wait(); - step(false) + step(false); } void JDDisplay::sendDone(JDDisplay* jdd) { From 290c97d20d4b25c300ad95efa539a69e44194da6 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:44:11 +0000 Subject: [PATCH 21/27] try this hack --- cpp/jddisplay.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index a6850d5..00c797e 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -251,13 +251,9 @@ void JDDisplay::step(bool sendImage) { if (!jd_shift_frame(&recvFrame)) break; } - if (!sendImage) { - sendDone(this); - return; - } } - if (displayServiceNum == 0) { + if (displayServiceNum == 0 || !sendImage) { // poke the control service to enumerate queuePkt(JD_SERVICE_NUMBER_CTRL, JD_CMD_ADVERTISEMENT_DATA, 0); flushSend(); From 939cf8b6deeda2767454ad1844b6be02692424e0 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 16:48:08 +0000 Subject: [PATCH 22/27] try this instead --- cpp/jddisplay.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index 00c797e..d51e6f3 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -253,13 +253,18 @@ void JDDisplay::step(bool sendImage) { } } - if (displayServiceNum == 0 || !sendImage) { + if (displayServiceNum == 0) { // poke the control service to enumerate queuePkt(JD_SERVICE_NUMBER_CTRL, JD_CMD_ADVERTISEMENT_DATA, 0); flushSend(); return; } + if (!sendImage) { + flushSend(); + return; + } + if (palette) { { #define PALETTE_SIZE (16 * 4) From 85ee1ee94a4ceab496bd906b6abe79a97f967bdd Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 17:14:15 +0000 Subject: [PATCH 23/27] another attempt --- cpp/jddisplay.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/jddisplay.cpp b/cpp/jddisplay.cpp index d51e6f3..b23a4e6 100644 --- a/cpp/jddisplay.cpp +++ b/cpp/jddisplay.cpp @@ -97,12 +97,13 @@ JDDisplay::JDDisplay(SPI *spi, Pin *cs, Pin *flow) : spi(spi), cs(cs), flow(flow 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); + EventModel::defaultEventBus->listen(DEVICE_ID_COMPONENT, DEVICE_COMPONENT_EVT_SYSTEM_TICK, this, + &JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE); } void JDDisplay::pollButtons(Event) { - inProgressLock.wait(); - step(false); + if (stepWaiting) + step(false); } void JDDisplay::sendDone(JDDisplay* jdd) { @@ -261,7 +262,7 @@ void JDDisplay::step(bool sendImage) { } if (!sendImage) { - flushSend(); + sendDone(this); return; } From 27cd6735583fdd338b15de64f410242248214ea6 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 17:50:50 +0000 Subject: [PATCH 24/27] button press test --- test.ts | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/test.ts b/test.ts index 8c1da1f..5fc9d68 100644 --- a/test.ts +++ b/test.ts @@ -1,12 +1,30 @@ -controller.B.onEvent(ControllerButtonEvent.Pressed, function () { - screen().fill(8) - screen().drawLine(0, 0, 160, 120, 1) - screen().drawLine(160, 0, 0, 120, 1) +// controller.B.onEvent(ControllerButtonEvent.Pressed, function () { +// screen().fill(8) +// screen().drawLine(0, 0, 160, 120, 1) +// screen().drawLine(160, 0, 0, 120, 1) +// }) +// controller.A.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) +// }) + +let presses = 0; +controller.A.onEvent( + ControllerButtonEvent.Pressed, + () => { + presses += 1 }) -controller.A.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) + +controller.B.onEvent( + ControllerButtonEvent.Pressed, + () => { + presses = 0 + }) + +input.onButtonPressed(Button.A, () => { + basic.showNumber(presses) }) + From 794cd9f9257f600a1fc568f02b440932dad924f2 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Mon, 17 Nov 2025 16:18:01 +0000 Subject: [PATCH 25/27] rename registerFrameCallbacks to startFrameWorker --- eventcontext.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/eventcontext.ts b/eventcontext.ts index 8ba7b09..fa873ff 100644 --- a/eventcontext.ts +++ b/eventcontext.ts @@ -34,8 +34,6 @@ namespace context { function doNothing() { } - - export class EventContext { private handlers: EventHandler[]; private frameCallbacks: FrameCallback[]; @@ -100,7 +98,7 @@ namespace context { } private runningCallbacks: boolean; - private registerFrameCallbacks() { + private startFrameWorker() { if (!this.frameCallbacks) return; const worker = this.frameWorker; @@ -129,7 +127,7 @@ namespace context { register() { for (const h of this.handlers) h.register(); - this.registerFrameCallbacks(); + this.startFrameWorker(); } unregister() { @@ -141,7 +139,7 @@ namespace context { registerFrameHandler(order: number, handler: () => void): FrameCallback { if (!this.frameCallbacks) { this.frameCallbacks = []; - this.registerFrameCallbacks(); + this.startFrameWorker(); } const fn = new FrameCallback() From 57ce8b47c0500ecf48ed6d4898e58ebe7d76d08e Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Tue, 18 Nov 2025 09:19:36 +0000 Subject: [PATCH 26/27] try new shims --- eventcontext.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/eventcontext.ts b/eventcontext.ts index fa873ff..c28afb5 100644 --- a/eventcontext.ts +++ b/eventcontext.ts @@ -21,14 +21,17 @@ namespace context { public flags: number ) { } + private myHandler: () => void = undefined + register() { - control.onEvent(this.src, this.value, () => { + this.myHandler = () => { if (this.handler) this.handler(); - }, this.flags) + } + control.rawOnEvent(this.src, this.value, this.myHandler, this.flags) } unregister() { - control.onEvent(this.src, this.value, doNothing, this.flags); + control.rawUnregisterEvent(this.src, this.value); } } From f4afc829e474e8c856b25e3b5e7c90d01f0b0855 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Wed, 19 Nov 2025 10:52:48 +0000 Subject: [PATCH 27/27] add screen painting --- test.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test.ts b/test.ts index 5fc9d68..47894b7 100644 --- a/test.ts +++ b/test.ts @@ -1,15 +1,15 @@ -// controller.B.onEvent(ControllerButtonEvent.Pressed, function () { -// screen().fill(8) -// screen().drawLine(0, 0, 160, 120, 1) -// screen().drawLine(160, 0, 0, 120, 1) -// }) -// controller.A.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) -// }) +controller.left.onEvent(ControllerButtonEvent.Pressed, function () { + screen().fill(8) + screen().drawLine(0, 0, 160, 120, 1) + screen().drawLine(160, 0, 0, 120, 1) +}) +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) +}) let presses = 0; controller.A.onEvent(