Skip to content

Commit

Permalink
add getConsoleOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
jaames committed Oct 15, 2021
1 parent 0a9716b commit 84b4990
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
16 changes: 13 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (!isUsbSupported) {
}
```

### Connecting a Playdate
### Connecting to a Playdate

Next we want to actually connect to a Playdate. Calling `requestConnectPlaydate()` will prompt the user to select a Playdate device from a menu, and returns a [Promise](https://web.dev/promises/) that will resolve a `PlaydateDevice` object if the connection was successful, or reject if a connection could not be made.

Expand Down Expand Up @@ -160,7 +160,7 @@ These methods are asynchronous and will resolve when a response has been receive

#### `getVersion()`

Returns an object containing version information about the Playdate, such as its OS build info, SDK version, serial number, etc
Returns an object containing version information about the Playdate, such as its OS build info, SDK version, serial number, etc.

```js
const version = await device.getVersion();
Expand All @@ -174,6 +174,16 @@ Returns the Playdate's serial number as a string, useful for if you need the use
const serial = await device.getSerial();
```

#### `getConsoleOutput()`

Get any data that has been printed to the Playdate's console output (e.g. via print() in Lua, playdate->system->logToConsole() in C, etc) as a string.

```js
const consoleOutput = await device.getConsoleOutput();
```

Alternatively, you can use` getRawConsoleOutput()` to get the console output as an Uint8Array of bytes, if for example you have printed binary data to the console.

#### `getScreen()`

Capture a screenshot from the Playdate, and get the raw framebuffer. This will return the 1-bit framebuffer data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) of bytes, where each bit in the byte will represent 1 pixel; `0` for black, `1` for white. The framebuffer is 400 x 240 pixels
Expand Down Expand Up @@ -305,6 +315,6 @@ To build the project, you'll need to have Node and NPM installed. Clone the repo

2021 James Daniel

If you have any questions or just want to say hi, you can reach me on Twitter ([@rakujira](https://twitter.com/rakujira)), on Discord (`@jaames#9860`), or via email (`mail at jamesdaniel dot dev`). I'm interested in joining any groups that are working on Playdate reverse-engineering.
If you have any questions or just want to say hi, you can reach me on Twitter ([@rakujira](https://twitter.com/rakujira)), on Discord (`@jaames#9860`), or via email (`mail at jamesdaniel dot dev`). I'm interested in joining any groups that are working on Playdate reverse-engineering!

Playdate is © [Panic Inc.](https://panic.com/) This project isn't affiliated with or endorsed by them in any way
24 changes: 22 additions & 2 deletions src/PlaydateDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,29 @@ export class PlaydateDevice {
return str.trim();
}

/**
* Get any data that has been printed to the Playdate's console output (e.g. via print() in Lua, playdate->system->logToConsole() in C, etc) as a string
*/
async getConsoleOutput() {
const str = await this.sendCommand('eval');
assert(!str.includes('Lua runtime is not available'), 'Console output cannot be read, the currently loaded PDX may be a system application');
return str.trim();
}

/**
* Get any data that has been printed to the Playdate's console output (e.g. via print() in Lua, playdate->system->logToConsole() in C, etc) as an Uint8Array of bytes
*/
async getRawConsoleOutput() {
await this.serial.writeAscii('eval\n');
const bytes = await this.serial.read();
const str = bytesToString(bytes.subarray(0, 40));
assert(!str.includes('Lua runtime is not available'), 'Console output cannot be read, the currently loaded PDX may be a system application');
return bytes;
}

/**
* Capture a screenshot from the Playdate, and get the raw framebuffer
* This will return the 1-bit framebuffer data as Uint8Array of bytes, where each bit in the byte will represent 1 pixel; `0` for black, `1` for white.
* This will return the 1-bit framebuffer data as an Uint8Array of bytes, where each bit in the byte will represent 1 pixel; `0` for black, `1` for white
* The framebuffer is 400 x 240 pixels
*/
async getScreen() {
Expand All @@ -192,7 +212,7 @@ export class PlaydateDevice {

/**
* Capture a screenshot from the Playdate, and get the unpacked framebuffer
* This will return an 8-bit indexed framebuffer as an Uint8Array. Each element of the array will represent a single pixel; `0x0` for black, `0x1` for white
* This will return an 8-bit indexed framebuffer as an Uint8Array of pixels. Each element of the array will represent a single pixel; `0x0` for black, `0x1` for white
* The framebuffer is 400 x 240 pixels
*/
async getScreenIndexed() {
Expand Down

0 comments on commit 84b4990

Please sign in to comment.