-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const blocksIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAAAsTAAALEwEAmpwYAAADkklEQVR4nNWaz0tVQRTHbxaBUhjhLihBWkWrohaG6zTCMPthRQXmD1AzMDPBnf9CLVw8dFNQWhsrWyRF+Q9Yu35Y7SqTFgW+tPzE0XnxvM68O/Pu+N71u3xvzpnzeWfO3Hl3ThBoBOwA2oHHwCcgTXz9AB4CrUCZYd4KYNxgn1axSExtEqPOR9jhJqAbmGN99Q3oBbZoYtgKvLLw8R24KjGbYMqAsQgns/jVJLBNE0slMG/pYxQo1WUmCkaUAgbwqydAiQbqloOP+6sypZaZjVJqfD9+1akBqnL00ZW9Acy5ACm7Pvzpi9SOBmrawYfUVHmgdjNcgdSEUti+dEYDNOjoozVQazgvIDVpD340qfFd5+jjkRh9jgOkJr4GLBFPv8O7FSu7nYtmAseHphYoa2OJC3Uk5LME+OVgnxYjfACpALpiQt3Q+Hzj4sArkAqgIwbUHY2/qaICqSBagL+464XG19OCAQGHgeMGqCt5QL3X+BkrJFCNOnPVesrUfPiwCYwUGgi1U9YZoJodoXaG7FPFAMo8R+oNUE3AH8s5diUFKArqLLBItKqSBJSBOhEDal/SgEQLOaBOR0AdSCJQVKZy1VR1UoEymWowQJ0yZKomSUBvNb98Lijd8ksU0JCh8AWq0QA1nGigYOXzRg2UZO6cBmgo8UBZUAsaqPPBRgQSAScNUBc2JJANVNKBhrO/t4BqSjrQomzFBqgGA9S7JAOtqZHQ+GMWL2WKClRtGLe8nAxQ9epYlEiggznGCtRFA1RtjkwVFWh/xHiBupQDaj5pQHstbOTv92UHqKIC7ba0k/d07QaooyGoogJVONhKppoNUHVZNVVQoBHNzV/aEaolYvkVFGhUE8iMow9Zfm05lt+hQgJNaIJ4ibuWdNeQBsjUegJNaSa8S34SqI5iA73WTHiT/LX0/7LXI1DaYfxPzbvnqBclNlDdnoDSYvDRMYA9oQlLI85mtur3APQhUL0zLlrzUh54jh/1xAQaD1QjkIsGNZPKHzVf6o0B1JJpvJCmBVtNGxqOvuJPfXkAzS43Xigj6Wpy0aobgqwLY59arikHoM7wEUa6mmx1WwMkV/AT+NWAJdC9NW1mareSriYbyZmrUgO1HXiGX81awKxuLwtlqsuypqYMDUebgeueawqNBFRaCPQNgKGgylUrpbRLyuHT9PCVLb/C4EMaCuXS+IFqz4wriUFikZjE78oGENI/OGAeDDqI5HgAAAAASUVORK5CYII=" | ||
Check failure on line 1 in extensions/nfcwarp.js GitHub Actions / build
|
||
|
||
class NFCWarp { | ||
getInfo() { | ||
return { | ||
id: 'nfcwarp', | ||
name: 'NFCWarp', | ||
color1: '#ff0000', | ||
Check warning on line 8 in extensions/nfcwarp.js GitHub Actions / build
|
||
color2: '#800000', | ||
color3: '#990033', | ||
docsURI: 'https://docs.turbowarp.org/development/extensions/nfcwarp', | ||
Check warning on line 11 in extensions/nfcwarp.js GitHub Actions / build
|
||
menuIconURI: blocksIcon, | ||
Check warning on line 12 in extensions/nfcwarp.js GitHub Actions / build
|
||
blockIconURI: blocksIcon, | ||
blocks: [ | ||
{ | ||
Check warning on line 15 in extensions/nfcwarp.js GitHub Actions / build
Check failure on line 15 in extensions/nfcwarp.js GitHub Actions / build
|
||
blockType: Scratch.BlockType.LABEL, | ||
Check warning on line 16 in extensions/nfcwarp.js GitHub Actions / build
|
||
text: "Read" | ||
Check warning on line 17 in extensions/nfcwarp.js GitHub Actions / build
|
||
}, | ||
|
||
{ | ||
opcode: 'nfcRead', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'Read NFC Tag', | ||
disableMonitor: true | ||
} | ||
] | ||
}; | ||
} | ||
|
||
nfcRead() { | ||
return new Promise((resolve, reject) => { | ||
console.log("Approach NFC Tag"); | ||
const ndef = new NDEFReader(); | ||
ndef.scan() | ||
.then(() => { | ||
ndef.onreadingerror = err => { | ||
console.log("Read failed"); | ||
reject(err); | ||
}; | ||
ndef.onreading = evt => { | ||
const decoder = new TextDecoder(); | ||
for (let record of evt.message.records) { | ||
console.log("Record type: " + record.recordType); | ||
console.log("Record encoding: " + record.encoding); | ||
console.log("Record data: " + decoder.decode(record.data)); | ||
resolve(decoder.decode(record.data)); | ||
return; | ||
} | ||
}; | ||
}) | ||
.catch(err => { | ||
console.log("Read error - " + err.message); | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
Scratch.extensions.register(new NFCWarp()); |