Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
36 changes: 24 additions & 12 deletions cpp/jddisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -215,23 +223,22 @@ 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);

target_disable_irq();
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);
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions cpp/jddisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};

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
50 changes: 27 additions & 23 deletions test.ts
Original file line number Diff line number Diff line change
@@ -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
}
}