Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tick() {
- if (videoElement.readyState === videoElement.HAVE_ENOUGH_DATA) {
- canvasElement.hidden = false;
- canvasElement.height = videoElement.videoHeight;
- canvasElement.width = videoElement.videoWidth;
- canvas.drawImage(videoElement, 0, 0, canvasElement.width, canvasElement.height);
- var imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
- var code = jsQR(imageData.data, canvasElement.width, canvasElement.height, {
- inversionAttempts: "dontInvert"
- });
- if (code && !scanned) {
- scanned = true;
- console.log(code);
- drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58");
- drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58");
- drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58");
- drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58");
- // console.log(code);
- // search for a macaddress
- var content = code.data;
- var params = content.split('/');
- var macaddr = false, key = false;
- for (var k in params) {
- if (MACRegex.test(params[k])) {
- macaddr = params[k];
- console.log(macaddr)
- }
- if (KEYRegex.test(params[k])) {
- key = params[k];
- console.log(key)
- }
- }
- if (macaddr && key) {
- // Hide the camera
- console.log("initDiGIdotScanner - 7");
- canvasElement.hidden = true;
- console.log("initDiGIdotScanner - 8");
- var alreadyScanned = false;
- $('.macaddress').each(function () {
- console.log($(this).text(), macaddr);
- if ($(this).text() == macaddr) {
- alreadyScanned = true;
- }
- });
- if (!alreadyScanned) {
- videoElement.pause();
- canvasElement.hidden = true;
- $('#registered-devices').before('<div class="scan-loader"><i class="c4-loader"></i><br>Getting information of device: ' + macaddr + ' </div>');
- lookupMyDevice(macaddr, key, function (resultLookup) {
- //console.log('lookup finised')
- console.log("initDiGIdotScanner - 9");
- if (resultLookup.have_products) {
- // if auto register is checked
- console.log("initDiGIdotScanner - 10");
- scannedProduct = resultLookup;
- if ($('[data-id="autoRegisterScanResults"]').is(':checked')) {
- console.log("initDiGIdotScanner - 11");
- saveNewDevice(resultLookup.products, function (result) {
- console.log("initDiGIdotScanner - 12");
- if (result['result'] == "OK") {
- addNewRegisterProduct(result);
- console.log("initDiGIdotScanner - 13");
- digidotScannerStart(); //restart the camera for a new scan
- }
- else {
- $('.scan-loader').remove();
- $('.no-device-registerd').remove();
- digidotScannerStart(); //restart the camera for a new scan
- alert("Failed to save to my devices..");
- console.log("initDiGIdotScanner - 14");
- }
- });
- } else {
- console.log("initDiGIdotScanner - 15");
- resultLookup['macaddr'] = macaddr;
- $('.scan-loader').remove();
- $('.no-device-registerd').remove();
- digidot_devicelist_results(resultLookup); // Show result and the registration button
- }
- }
- });
- } else {
- alert("This product is already scanned");
- stopCamera();
- scannerInit = false;
- digidotScannerStart();//restart the camera for a new scan
- }
- } else {
- console.log("initDiGIdotScanner - 5");
- if (!macaddr) {
- $('.search-device-container').before('<span class="error">No valid mac address found</div>');
- }
- if (!key) {
- $('.search-device-container').before('<span class="error">No valid key found</div>');
- }
- }
- }
- }
- requestAnimationFrame(tick);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement