Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions cpp/jddisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +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, this,
&JDDisplay::pollButtons, MESSAGE_BUS_LISTENER_IMMEDIATE);
}

/**
* Deprecated; no longer neccessary. sendIndexedImage handles this.
*/
void JDDisplay::waitForSendDone() {}
void JDDisplay::pollButtons(Event) {
if (stepWaiting)
step(false);
}

void JDDisplay::sendDone(JDDisplay* jdd) {
inProgressLock.notify();
Expand Down Expand Up @@ -215,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);

Expand Down Expand Up @@ -259,6 +261,11 @@ void JDDisplay::step() {
return;
}

if (!sendImage) {
sendDone(this);
return;
}

if (palette) {
{
#define PALETTE_SIZE (16 * 4)
Expand Down
6 changes: 2 additions & 4 deletions cpp/jddisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ 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);
void handleIncoming(jd_packet_t *pkt);

void pollButtons(Event);
public:
uint8_t brightness;
JDDisplay(SPI *spi, Pin *cs, Pin *flow);
Expand All @@ -59,8 +59,6 @@ class JDDisplay {
addr.width = w;
addr.height = h;
}
void waitForSendDone();

int sendIndexedImage(const uint8_t *src, unsigned width, unsigned height, uint32_t *palette);
};

Expand Down
9 changes: 0 additions & 9 deletions cpp/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 9 additions & 8 deletions eventcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ 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);
}
}

function doNothing() { }



export class EventContext {
private handlers: EventHandler[];
private frameCallbacks: FrameCallback[];
Expand Down Expand Up @@ -100,7 +101,7 @@ namespace context {
}

private runningCallbacks: boolean;
private registerFrameCallbacks() {
private startFrameWorker() {
if (!this.frameCallbacks) return;

const worker = this.frameWorker;
Expand Down Expand Up @@ -129,7 +130,7 @@ namespace context {
register() {
for (const h of this.handlers)
h.register();
this.registerFrameCallbacks();
this.startFrameWorker();
}

unregister() {
Expand All @@ -141,7 +142,7 @@ namespace context {
registerFrameHandler(order: number, handler: () => void): FrameCallback {
if (!this.frameCallbacks) {
this.frameCallbacks = [];
this.registerFrameCallbacks();
this.startFrameWorker();
}

const fn = new FrameCallback()
Expand Down
49 changes: 26 additions & 23 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
// 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)
})
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)
})

// tests go here; this will not be compiled when this package is used as an extension.
let presses = 0;
controller.A.onEvent(
ControllerButtonEvent.Pressed,
() => {
presses += 1
})

const present = shieldhelpers.shieldPresent();
controller.B.onEvent(
ControllerButtonEvent.Pressed,
() => {
presses = 0
})

basic.showNumber(present ? 1 : 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
}
}
Loading