Skip to content

Instantly share code, notes, and snippets.

View aybarburak's full-sized avatar
🎯
Focusing

aybarburak

🎯
Focusing
  • Delivery Hero SE
View GitHub Profile
device.transferOut(1, data);
function printText(text) {
return new Uint8Array(text.split('').map(char => char.charCodeAt(0)))
}
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;
navigator.usb.addEventListener('connect', event => {
// event.device will bring the connected device
});
navigator.usb.addEventListener('disconnect', event => {
// event.device will bring the disconnected device
});
let receivedData = await data.transferIn(1, 6);// Waiting for 6 bytes of data from endpoint #1.
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
});
await device.transferOut(1, data);
device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0));
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);
}
});
let devices = await navigator.usb.getDevices();
devices.forEach(device => {
// You can list or choose your device in this block
});