Skip to content

Commit

Permalink
Add device.getDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
commandblockguy committed Sep 17, 2021
1 parent 48d72b9 commit 0bb14dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dusb/magic-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = {
// https://github.com/debrouxl/tilibs/blob/master/libticalcs/trunk/src/dusb_cmd.h

attributes: {
DUSB_AID_VAR_SIZE: 0x01,
DUSB_AID_VAR_TYPE: 0x02,
DUSB_AID_ARCHIVED: 0x03,
DUSB_AID_VAR_VERSION: 0x08,
Expand Down
31 changes: 31 additions & 0 deletions src/dusb/ti84series.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ module.exports = class Ti84series {
};
}

async getDirectory() {
await this._d.send({
type: v.virtualPacketTypes.DUSB_VPKT_DIR_REQ,
data: [
0, 0, 0, 3, // attribute count
0, 1, // size
0, 2, // type
0, 3, // archived
0, 1, 0, 1, 0, 1, 1 // ???
]
});
const result = [];
while ( true ) {
const packet = await this._d.expectAny();
if ( packet.type == v.virtualPacketTypes.DUSB_VPKT_EOT )
break;
if ( packet.type != v.virtualPacketTypes.DUSB_VPKT_VAR_HDR )
throw `Expected virtual packet type ${v.virtualPacketTypes.DUSB_VPKT_VAR_HDR}, but got ${packet.type} instead`;
const nameLength = b.bytesToInt(packet.data.slice(0, 2));
const name = b.bytesToAscii(packet.data.slice(2, 2 + nameLength));
const attributes = b.destructParameters(packet.data.slice(2 + nameLength + 1));

const size = b.bytesToInt(attributes[v.attributes.DUSB_AID_VAR_SIZE]);
const type = b.bytesToInt(attributes[v.attributes.DUSB_AID_VAR_TYPE].slice(2));
const archived = attributes[v.attributes.DUSB_AID_ARCHIVED][0] == 1;

result.push({name, size, type, archived});
}
return result;
}

// Send a TI file to the calculator
async sendFile(file) {
for ( let i = 0; i < file.entries.length; i++ ) {
Expand Down

0 comments on commit 0bb14dc

Please sign in to comment.