From a2e271a1da672e85e827abd3b34537452643787d Mon Sep 17 00:00:00 2001 From: Yrr0r Date: Mon, 18 Jul 2022 22:16:52 +0800 Subject: [PATCH] more are working --- README.md | 27 ++++++++++++++++++++++++--- const.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ script.js | 26 ++++++++++++++++---------- 3 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 const.txt diff --git a/README.md b/README.md index b4e3fba..67bd08a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,32 @@ # WebBLE with Paperang -The only thing this can do right now is print a self-diagnostics page. +Prints redered markdown. Paper not padded after print finishes. Manual pull is required at the moment to get the full print area. + -Connect, then hit print. ## Some useful BLE related constants: - Service ID: `49535343-fe7d-4ae5-8fa9-9fafd205e455` +- Characteristic value to write to: `49535343-6daa-4d02-abf6-19569aca69fe` +- Characteristic value to receive from the printer: `49535343-1e4d-4bd9-ba61-23c647249616` This is a NOTIFY character. + + + +## Some other tips on printing + +- BLE has a max data packet of 512, means 502 bytes of useful data. However, I found out that each packet should not contain unfinished lines otherwise they tear. So I rounded to 480 for 48 bytes per line on P1. + +## Other than just printing + +All send and receive data command byte are in `const.txt`. Send and receive has (almost) same data structure. When a packet is received, its also begin with 0x02 and end with 0x03. + +2nd byte is command byte, then the first 5 and last 5 bytes are not very useful since I don't care about checksums so I discarded them. Then the last 11 bytes of whats remaining seems to be some kind of redundant addon data, so they are disregarded as well. Then only a handful of bytes will remain and they are easier to decode. + +- Reading ASCII stringed values (SN, model, board version...) : Just do the right truncating and decode the rest as ASCII. +- Battery status: Send command 16, only one byte will remain after all the truncating. That byte is the percentage value directly usable. Do not divide it again by 255. +- Get heat density: Send 28, then look at the first byte returned. Same as battery status. Do not divide by 255. +- Feed line: The printer will feed blank paper of a specific length. Send command 26, then immediately followed by the amount of lines(in pixel) to be fed encoded as payload data. + +- Power-down time: Send 31, get a 2 byte integer. Notice it's little endian means reverse their byte order to read them. i.e. `[16,14]` or `0x100E` indicate 3600 seconds, not 4110. -- Characteristic ID: `49535343-6daa-4d02-abf6-19569aca69fe` \ No newline at end of file +> Some commands in the list are not implemented on the P1 model. I do not know whether it works on any other model. \ No newline at end of file diff --git a/const.txt b/const.txt new file mode 100644 index 0000000..03677df --- /dev/null +++ b/const.txt @@ -0,0 +1,49 @@ +PRT_PRINT_DATA = 0 +PRT_PRINT_DATA_COMPRESS = 1 +PRT_FIRMWARE_DATA = 2 +PRT_USB_UPDATE_FIRMWARE = 3 +PRT_GET_VERSION = 4 +PRT_SENT_VERSION = 5 +PRT_GET_MODEL = 6 +PRT_SENT_MODEL = 7 +PRT_GET_BT_MAC = 8 +PRT_SENT_BT_MAC = 9 +PRT_GET_SN = 10 +PRT_SENT_SN = 11 +PRT_GET_STATUS = 12 +PRT_SENT_STATUS = 13 +PRT_GET_VOLTAGE = 14 +PRT_SENT_VOLTAGE = 15 +PRT_GET_BAT_STATUS = 16 +PRT_SENT_BAT_STATUS = 17 +PRT_GET_TEMP = 18 +PRT_SENT_TEMP = 19 +PRT_SET_FACTORY_STATUS = 20 +PRT_GET_FACTORY_STATUS = 21 +PRT_SENT_FACTORY_STATUS = 22 +PRT_SENT_BT_STATUS = 23 +PRT_SET_CRC_KEY = 24 +PRT_SET_HEAT_DENSITY = 25 +PRT_FEED_LINE = 26 +PRT_PRINT_TEST_PAGE = 27 +PRT_GET_HEAT_DENSITY = 28 +PRT_SENT_HEAT_DENSITY = 29 +PRT_SET_POWER_DOWN_TIME = 30 +PRT_GET_POWER_DOWN_TIME = 31 +PRT_SENT_POWER_DOWN_TIME = 32 +PRT_FEED_TO_HEAD_LINE = 33 +PRT_PRINT_DEFAULT_PARA = 34 +PRT_GET_BOARD_VERSION = 35 +PRT_SENT_BOARD_VERSION = 36 +PRT_GET_HW_INFO = 37 +PRT_SENT_HW_INFO = 38 +PRT_SET_MAX_GAP_LENGTH = 39 +PRT_GET_MAX_GAP_LENGTH = 40 +PRT_SENT_MAX_GAP_LENGTH = 41 +PRT_GET_PAPER_TYPE = 42 +PRT_SENT_PAPER_TYPE = 43 +PRT_SET_PAPER_TYPE = 44 +PRT_GET_COUNTRY_NAME = 45 +PRT_SENT_COUNTRY_NAME = 46 +PRT_DISCONNECT_BT_CMD = 47 +PRT_MAX_CMD = 48 \ No newline at end of file diff --git a/script.js b/script.js index 3983cde..6d2e5c7 100644 --- a/script.js +++ b/script.js @@ -18,14 +18,6 @@ var simplemde = new SimpleMDE({ }); -/* -Some useful facts about printers: - service: 49535343-fe7d-4ae5-8fa9-9fafd205e455 -characteristics values are - Write to: 49535343-6daa-4d02-abf6-19569aca69fe - notify: 49535343-1e4d-4bd9-ba61-23c647249616 -On BLE, max size of one pack is 512, means 502 for each data pack. -*/ async function connect() { // Call browser popup to let user select device let printer = await navigator.bluetooth.requestDevice({ @@ -41,11 +33,25 @@ async function connect() { notify.startNotifications().then(() => { notify.addEventListener('characteristicvaluechanged', (event) => { let value = event.target.value; - let a = new DataView(value) // Convert raw data bytes to hex values just for the sake of showing something. // In the "real" world, you'd use data.getUint8, data.getUint16 or even // TextDecoder to process raw data bytes. - console.log('Notify:' , a); + let arr = new Array(); + for(i=0; i