Skip to content

Commit

Permalink
修正arduino nfc讀資料積木
Browse files Browse the repository at this point in the history
  • Loading branch information
estea8968 committed Sep 24, 2024
1 parent 2a55a26 commit 7a55781
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="google" value="notranslate">
<link rel="shortcut icon" href="static/favicon.ico">
<title>OSEP_scratch 1130917</title>
<title>OSEP_scratch 1130924</title>

</head>
<body>
Expand Down
31 changes: 21 additions & 10 deletions app/lib.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -452791,6 +452791,12 @@ var Scratch3ArduinoWebSerial = /*#__PURE__*/function () {
return this.serialSend(sendData);

case 6:
_context23.next = 8;
return new Promise(function (resolve) {
return setTimeout(resolve, 500);
});

case 8:
case "end":
return _context23.stop();
}
Expand All @@ -452813,34 +452819,39 @@ var Scratch3ArduinoWebSerial = /*#__PURE__*/function () {
while (1) {
switch (_context24.prev = _context24.next) {
case 0:
nfc_id = '';
sendData = 'mfr1#';
console.log('sendData=', sendData);
_context24.next = 4;
_context24.next = 5;
return this.serialSend(sendData);

case 4:
_context24.next = 6;
case 5:
_context24.next = 7;
return new Promise(function (resolve) {
return setTimeout(resolve, 500);
});

case 6:
_context24.next = 8;
case 7:
_context24.next = 9;
return this.serialRead();

case 8:
case 9:
serial_data = _context24.sent.split(':');

if (!(serial_data[0] == 'mfr')) {
_context24.next = 13;
_context24.next = 14;
break;
}

console.log('mfr=', serial_data[1]);
nfc_id = serial_data[1];
return _context24.abrupt("return", serial_data[1]);

case 13:
if (serial_data[1].length > 0) {
nfc_id = serial_data[1];
}

return _context24.abrupt("return", nfc_id);

case 14:
case "end":
return _context24.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib.min.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let analog_inputs = new Array(8);
let the_locale = null;
//pms5003
let pms_array =[0,0,0,0,0];

let nfc_id=0; //nfc card id
let theDHTSensorMap = { 0: 'Temperature', 1: 'Humidity' };
let max7219_config = ['','','',''];
const max7219_img={
Expand Down Expand Up @@ -500,7 +500,35 @@ class Scratch3ArduinoWebSerial {
}
}
},
'---',
{
opcode: 'mfr_set',
blockType: BlockType.COMMAND,
text: msg.mfr_set[the_locale],
arguments:{
SDA:{
type: ArgumentType.NUMBER,
defaultValue:'10',
menu:'pwm_pins',
},
RST:{
type: ArgumentType.NUMBER,
defaultValue:'9',
menu:'pwm_pins',
}
}
},
{
opcode: 'mfr_read',
blockType: BlockType.COMMAND,
text: msg.mfr_read[the_locale],
},
{
opcode: 'mfr_id',
blockType: BlockType.REPORTER,
text: msg.mfr_id[the_locale],
},
/*{
opcode: 'hx711_set',
blockType: BlockType.COMMAND,
text: msg.hx711_set[the_locale],
Expand Down Expand Up @@ -532,8 +560,8 @@ class Scratch3ArduinoWebSerial {
defaultValue:'6',
menu:'pwm_pins',
}
}*/
},
}
},*/
/*{
opcode: 'ntc_read',
blockType: BlockType.REPORTER,
Expand All @@ -551,7 +579,7 @@ class Scratch3ArduinoWebSerial {
opcode: 'firmwareversion',
blockType: BlockType.REPORTER,
text: msg.FirmwareVersion[the_locale],
}
},

],
menus: {
Expand Down Expand Up @@ -1108,6 +1136,33 @@ class Scratch3ArduinoWebSerial {
console.log('sendData=',sendData);
await this.serialSend(sendData);
}
//mfr522
async mfr_set(args){
const sda_pin=parseInt(args.SDA);
const rst_pin=parseInt(args.RST);
const sendData = 'mfr0#'+sda_pin+'#'+rst_pin+'#';
console.log('sendData=',sendData);
await this.serialSend(sendData);
await new Promise(resolve => setTimeout(resolve, 500));
}
async mfr_read(args){
nfc_id = '';
const sendData = 'mfr1#';
console.log('sendData=',sendData);
await this.serialSend(sendData);
await new Promise(resolve => setTimeout(resolve, 500));
let serial_data = (await this.serialRead()).split(':');
if (serial_data[0] == 'mfr') {
console.log('mfr=',serial_data[1]);
if(serial_data[1].length>0){
nfc_id = serial_data[1];
}
return nfc_id;
}
}
mfr_id(){
return nfc_id;
}
async hx711_set(args){
const dat_pin = parseInt(args.DAT);
const sck_pin = parseInt(args.SCK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const FormRGB = {
export const FormDisconnect = {
'en': 'Arduino dicconnected',
'zh-tw': 'Arduino已離線',
}
};

export const FormWs2812SetClear = {
'en': "clear WS2812",
Expand Down Expand Up @@ -207,6 +207,18 @@ export const Max7219_matrix ={
'en': "show value: [VALUE]",
'zh-tw':"顯示01值 [VALUE]",
};
export const mfr_set = {
'en': "mfrc522 zero-setting, SDA pin:[SDA] RST pin:[RST]",
'zh-tw': "mfrc522設定,SDA腳位:[SDA] RST腳位:[RST]",
};
export const mfr_read = {
'en': "mfrc522 read card id",
'zh-tw': "mfrc522讀取卡片ID",
};
export const mfr_id = {
'en': "NFC card id",
'zh-tw': "NFC卡片ID",
};
export const hx711_set = {
'en': "hx711 zero-setting, DAT pin:[DAT] SCK pin:[SCK]",
'zh-tw': "hx711歸零,DAT腳位:[DAT] SCK腳位:[SCK]",
Expand Down

0 comments on commit 7a55781

Please sign in to comment.