Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
leedstyh authored Aug 1, 2018
1 parent f454a25 commit fe222f2
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>React App</title><link href="/static/css/main.65027555.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.e2cb7851.js"></script></body></html>

<html>
<body>
<textarea id="printContent"></textarea>
<input type="submit" onclick="connectAndPrint()" value="Print"/>
<P>Type text into box and click on submit button.
<script>
var device;

function setup(device) {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
}

function print() {
var string = document.getElementById("printContent").value + "\n";
var encoder = new TextEncoder();
var data = encoder.encode(string);
device.transferOut(1, data)
.catch(error => { console.log(error); })
}

function connectAndPrint() {
if (device == null) {
navigator.usb.requestDevice({ filters: [{ vendorId: 4070 }] })
.then(selectedDevice => {
device = selectedDevice;
console.log(device);
return setup(device);
})
.then(() => print())
.catch(error => { console.log(error); })
}
else
print();
}

navigator.usb.getDevices()
.then(devices => {
if (devices.length > 0) {
device = devices[0];
return setup(device);
}
})
.catch(error => { console.log(error); });

</script>
</body>
</html>

0 comments on commit fe222f2

Please sign in to comment.