-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
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> | ||
|