Skip to content

Commit

Permalink
修正json擴充積木和上傳microbit v2韌體
Browse files Browse the repository at this point in the history
  • Loading branch information
estea8968 committed Oct 24, 2023
1 parent 62a270c commit 4c4bde2
Show file tree
Hide file tree
Showing 9 changed files with 4,873 additions and 1,884 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 1121017</title>
<title>OSEP_scratch 1121024</title>

</head>
<body>
Expand Down
46 changes: 44 additions & 2 deletions app/lib.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -401474,6 +401474,24 @@ var gasoJSON = /*#__PURE__*/function () {
},
text: msg.jsonFormNum[theLocale]
}, "---", {
opcode: "useTextSearchGetData2",
blockType: BlockType.REPORTER,
arguments: {
data: {
type: ArgumentType.STRING,
defaultValue: 'data'
},
column: {
type: ArgumentType.STRING,
defaultValue: 'column'
},
value: {
type: ArgumentType.STRING,
defaultValue: 'value'
}
},
text: msg.useTextSearchGetData2[theLocale]
}, {
opcode: "useTextSearchGetData",
blockType: BlockType.REPORTER,
arguments: {
Expand Down Expand Up @@ -401951,7 +401969,8 @@ var gasoJSON = /*#__PURE__*/function () {
}, {
key: "useTextSearchGetData",
value: function useTextSearchGetData(args) {
var data = args.data;
var data = args.data; //

var column = args.column;
var column2 = args.column2;
var value = args.value;
Expand All @@ -401971,6 +401990,24 @@ var gasoJSON = /*#__PURE__*/function () {
return "Error: ".concat(err);
}
}
}, {
key: "useTextSearchGetData2",
value: function useTextSearchGetData2(args) {
var data = args.data; //

var column = args.column;
var value = args.value;
var parsed = JSON.parse(data);
var size = parsed.length;
var getData = [];

for (var i = 0; i < size; i++) {
var d = parsed[i][column];
if (d.includes(value)) getData.push(parsed[i]);
}

return JSON.stringify(getData);
}
}, {
key: "useNumberCompareGetData",
value: function useNumberCompareGetData(args) {
Expand Down Expand Up @@ -402021,7 +402058,7 @@ module.exports = gasoJSON;
/*!*****************************************************************************!*\
!*** ./node_modules/scratch-vm/src/extensions/scratch3_json/translation.js ***!
\*****************************************************************************/
/*! exports provided: fetchJSON, corsfetchJSON, fetchCSV, readerror, fetchTXT, fetchXML, openCORS, clearJSONData, onJSONReceived, readFromJSON, readFromJSONErr, readEntryFromJSON, readAttrFromJSON, getJsonCol, jsonFormNum, useTextSearchGetData, useNumberCompareGetData, data, attr, number, Column_name, value, splitString */
/*! exports provided: fetchJSON, corsfetchJSON, fetchCSV, readerror, fetchTXT, fetchXML, openCORS, clearJSONData, onJSONReceived, readFromJSON, readFromJSONErr, readEntryFromJSON, readAttrFromJSON, getJsonCol, jsonFormNum, useTextSearchGetData, useNumberCompareGetData, useTextSearchGetData2, data, attr, number, Column_name, value, splitString */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Expand All @@ -402043,6 +402080,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "jsonFormNum", function() { return jsonFormNum; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "useTextSearchGetData", function() { return useTextSearchGetData; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "useNumberCompareGetData", function() { return useNumberCompareGetData; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "useTextSearchGetData2", function() { return useTextSearchGetData2; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "data", function() { return data; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "attr", function() { return attr; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "number", function() { return number; });
Expand Down Expand Up @@ -402117,6 +402155,10 @@ var useNumberCompareGetData = {
'en': 'in JSON data [data] get all the values of the column [column2], when the column [column] [symbol] [number]',
'zh-tw': '查詢資料[data]的欄位[column]數值是否[symbol][number],取得欄位[column2]的值'
};
var useTextSearchGetData2 = {
'en': 'Retrieve all data in the data [data] where the field [column] contains the value [value].',
'zh-tw': '查詢資料[data]中欄位[column]包含特定值[value]的所有資料'
};
var data = {
'en': 'data',
'zh-tw': '資料'
Expand Down
2 changes: 1 addition & 1 deletion app/lib.min.js.map

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion source/scratch-vm/src/extensions/scratch3_json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ class gasoJSON {
text: msg.jsonFormNum[theLocale]
},
"---",
{
opcode: "useTextSearchGetData2",
blockType: BlockType.REPORTER,
arguments: {
data: {
type: ArgumentType.STRING,
defaultValue: 'data',
},
column: {
type: ArgumentType.STRING,
defaultValue: 'column',
},
value: {
type: ArgumentType.STRING,
defaultValue: 'value',
},
},
text: msg.useTextSearchGetData2[theLocale],
},
{
opcode: "useTextSearchGetData",
blockType: BlockType.REPORTER,
Expand Down Expand Up @@ -584,7 +603,7 @@ class gasoJSON {
}

useTextSearchGetData(args) {
const data = args.data;
const data = args.data; //
const column = args.column;
const column2 = args.column2;
const value = args.value;
Expand All @@ -603,6 +622,21 @@ class gasoJSON {
}
}

useTextSearchGetData2(args){
const data = args.data; //
const column = args.column;
const value = args.value;

const parsed = JSON.parse(data);
const size = parsed.length;
var getData = [];
for (var i = 0; i < size; i++) {
const d = parsed[i][column];
if (d.includes(value)) getData.push(parsed[i]);
}
return JSON.stringify(getData);
}

useNumberCompareGetData(args) {
const data = args.data;
const column = args.column;
Expand Down
5 changes: 5 additions & 0 deletions source/scratch-vm/src/extensions/scratch3_json/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export const useNumberCompareGetData = {
'zh-tw': '查詢資料[data]的欄位[column]數值是否[symbol][number],取得欄位[column2]的值'
};

export const useTextSearchGetData2 = {
'en': 'Retrieve all data in the data [data] where the field [column] contains the value [value].',
'zh-tw': '查詢資料[data]中欄位[column]包含特定值[value]的所有資料'
};

export const data = {
'en': 'data',
'zh-tw': '資料'
Expand Down
67 changes: 26 additions & 41 deletions src/firmware/microbit_webserial/microbit_webserial.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//版本日期 112 10 18
//版本日期 112 10 17
#include "Wire.h"
#include <Adafruit_Microbit.h>
#include "MMA8653.h"
Expand All @@ -24,18 +24,19 @@ const uint8_t sad_bmp[] =
B01110,
B10001, };

//MMA8653 accel;
String inputData;

void setup() {
Serial.begin(115200);
Serial.setTimeout(5);
pinMode(PIN_BUTTON_A, INPUT);
pinMode(PIN_BUTTON_B, INPUT);
microbit.begin();
//microbit.begin();
Serial.println("micro:bit");
// Start I2C at 400khz (fast mode)
Wire.begin();
Wire.setClock(400000);

// Setup accelerometer at 2G range, 10bit res, 50hz update rate and HighRes mode
accel.init(MMA8653_2G_RANGE, MMA8653_10BIT_RES, MMA8653_ODR_50);
accel.setMODS(MMA8653_MODS_HIGH_RES);
Expand All @@ -61,9 +62,9 @@ void config(void)
Wire.endTransmission(); // stop transmitting
}
void loop() {
inputData =Serial.readString();
inputData =Serial.readString();
// Serial.println(inputData);
int str_len = inputData.length() + 1;
int str_len = inputData.length()+ 1;
char char_str[str_len];
inputData.toCharArray(char_str, str_len);
char_str[str_len]='\0';
Expand All @@ -73,6 +74,19 @@ void loop() {
char *commandString = strtok(char_str, "#");
char *b_String = strtok(NULL, "#");
char *c_String = strtok(NULL, "#");

//光線
if(strcmp(commandString, "light") == 0){
pinMode(23, OUTPUT);
pinMode(26, OUTPUT);
pinMode(3,INPUT);
int lightValue = 1023 - analogRead(3);
//Serial.println(analogRead(COL));
//int average = calculateAverage(sensorValue);
Serial.print("l:");
Serial.println(lightValue);

}
//button
if(strcmp(commandString, "b") == 0){
Serial.print("b:");
Expand All @@ -82,6 +96,7 @@ void loop() {
}
//led
if(strcmp(commandString, "led") == 0){
microbit.begin();
if(strcmp(b_String, "led_on") == 0){
microbit.fillScreen(LED_ON);
}else if(strcmp(b_String, "heart") == 0){
Expand All @@ -99,7 +114,8 @@ void loop() {
}else if(strcmp(b_String, "drawPixel") == 0){
char *a0 = strtok(c_String, ",");
char *a1 = strtok(NULL, ",");
microbit.drawPixel(atoi(a0), atoi(a1), LED_ON);
char *a2 = strtok(NULL, ",");
microbit.drawPixel(atoi(a0), atoi(a1), atoi(a2));
}else if(strcmp(b_String, "drawLine") == 0){
char* a0 = strtok(c_String, ",");
char *a1 = strtok(NULL, ",");
Expand All @@ -116,37 +132,15 @@ void loop() {
i++;
}
}
}
/*else if(strcmp(b_String, "analogWrite")==0){
//pinMode(26, OUTPUT);
//Serial.println(analogRead(3));
digitalWrite(3,HIGH);
delay(500);
digitalWrite(3,LOW);
//analogWrite(3,0);
}*/else {
}else {
microbit.print(b_String);
}

}
//光線
if(strcmp(commandString, "light") == 0){
float v=0;
//for(int i=0;i<10;i++){
v+=analogRead(3);
delay(1);
v+=analogRead(4);
delay(1);
v+=analogRead(10);
//}
Serial.print("l:");
Serial.println(v/3);
}
//MMA8653 xyz
if(strcmp(commandString, "mma") == 0){
accel.readSensor(&x, &y, &z);
//delay(100);

//accel.getOffsets(&offset_x, &offset_y, &offset_z);
Serial.print("mma:");
Serial.print(x);
Expand All @@ -171,6 +165,7 @@ void loop() {
}
//數位讀取
if(strcmp(commandString, "d_read") == 0){
pinMode(atoi(b_String),INPUT);
Serial.print("d");
Serial.print(b_String);
Serial.print(":");
Expand All @@ -185,6 +180,7 @@ void loop() {
}
//數位寫入
if(strcmp(commandString, "d_write") == 0){
pinMode(atoi(b_String),OUTPUT);
digitalWrite(atoi(b_String),atoi(c_String));
}
//類比寫入
Expand All @@ -193,17 +189,6 @@ void loop() {
}
//delay(1);
}

/*Serial.print("b:");
Serial.print(digitalRead(PIN_BUTTON_A));
Serial.print(",");
Serial.println(digitalRead(PIN_BUTTON_B));*/
/*if (! digitalRead(PIN_BUTTON_A)) {
Serial.println("Button A pressed");
}
if (! digitalRead(PIN_BUTTON_B)) {
Serial.println("Button B pressed");
}*/
}

int mag_read_register(int reg)
Expand Down
Loading

0 comments on commit 4c4bde2

Please sign in to comment.