This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| device.transferOut(1, data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function printText(text) { | |
| return new Uint8Array(text.split('').map(char => char.charCodeAt(0))) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ESC_INIT = [0x1b, 0x40]; | |
| const ESC_BIT_IMAGE = [0x1b, 0x2a] | |
| const DOTS_DENSITY = 24 | |
| const LUMINANCE = { | |
| RED: 0.299, | |
| GREEN: 0.587, | |
| BLUE: 0.114 | |
| } | |
| const LINE_FEED = 0x0a; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| navigator.usb.addEventListener('connect', event => { | |
| // event.device will bring the connected device | |
| }); | |
| navigator.usb.addEventListener('disconnect', event => { | |
| // event.device will bring the disconnected device | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let receivedData = await data.transferIn(1, 6);// Waiting for 6 bytes of data from endpoint #1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| await device.controlTransferOut({ | |
| requestType: 'vendor', | |
| recipient: 'interface', | |
| request: 0x01, // vendor-specific request: enable channels | |
| value: 0x0013, // 0b00010011 (channels 1, 2 and 5) | |
| index: 0x0001 // Interface 1 is the recipient | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| await device.transferOut(1, data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| device.open() | |
| .then(() => device.selectConfiguration(1)) | |
| .then(() => device.claimInterface(0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let button = document.getElementById('request-device'); | |
| button.addEventListener('click', async () => { | |
| let device; | |
| let usbDeviceProperties = { name: "Bixolon", vendorId: 5380, productId: 31 }; | |
| try { | |
| device = await navigator.usb.requestDevice({ filters: usbDeviceProperties }); | |
| } catch (error) { | |
| alert('Error: ' + error.message); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let devices = await navigator.usb.getDevices(); | |
| devices.forEach(device => { | |
| // You can list or choose your device in this block | |
| }); |