Skip to content

Commit 97d0204

Browse files
Add support for new board IDs.
1 parent 5fa8def commit 97d0204

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

js/fs.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ var microbitFsWrapper = function() {
2828
'size',
2929
'write',
3030
];
31+
var v1BoardIds = ['9900', '9901'];
32+
var v2BoardIds = ['9903', '9904', '9905', '9906'];
33+
// TODO: We need to use ID 9901 for mobile app compatibility, but can soon be changed to 9900 (as per spec)
34+
var hexBoardIdV1 = 0x9901;
35+
var hexBoardIdV2 = microbitFs.microbitBoardId.V2;
3136

3237
/**
3338
* Duplicates some of the methods from the MicropythonFsHex class by
@@ -64,10 +69,9 @@ var microbitFsWrapper = function() {
6469
if (!uPyV1 || !uPyV2) {
6570
console.error('There was an issue loading the MicroPython Hex files.');
6671
}
67-
// TODO: We need to use ID 9901 for app compatibility, but can soon be changed to 9900 (as per spec)
6872
uPyFs = new microbitFs.MicropythonFsHex([
69-
{ hex: uPyV1, boardId: 0x9901 },
70-
{ hex: uPyV2, boardId: 0x9903 },
73+
{ hex: uPyV1, boardId: hexBoardIdV1 },
74+
{ hex: uPyV2, boardId: hexBoardIdV2 },
7175
], {
7276
'maxFsSize': commonFsSize,
7377
});
@@ -80,10 +84,10 @@ var microbitFsWrapper = function() {
8084
* @returns Uint8Array with the data for the given Board ID.
8185
*/
8286
fsWrapper.getBytesForBoardId = function(boardId) {
83-
if (boardId == '9900' || boardId == '9901') {
84-
return uPyFs.getIntelHexBytes(0x9901);
85-
} else if (boardId == '9903' || boardId == '9904') {
86-
return uPyFs.getIntelHexBytes(0x9903);
87+
if (v1BoardIds.indexOf(boardId) >= 0) {
88+
return uPyFs.getIntelHexBytes(hexBoardIdV1);
89+
} else if (v2BoardIds.indexOf(boardId) >= 0) {
90+
return uPyFs.getIntelHexBytes(hexBoardIdV2);
8791
} else {
8892
throw Error('Could not recognise the Board ID ' + boardId);
8993
}
@@ -94,10 +98,10 @@ var microbitFsWrapper = function() {
9498
* @returns ArrayBuffer with the Intel Hex data for the given Board ID.
9599
*/
96100
fsWrapper.getIntelHexForBoardId = function(boardId) {
97-
if (boardId == '9900' || boardId == '9901') {
98-
var hexStr = uPyFs.getIntelHex(0x9901);
99-
} else if (boardId == '9903' || boardId == '9904') {
100-
var hexStr = uPyFs.getIntelHex(0x9903);
101+
if (v1BoardIds.indexOf(boardId) >= 0) {
102+
var hexStr = uPyFs.getIntelHex(hexBoardIdV1);
103+
} else if (v2BoardIds.indexOf(boardId) >= 0) {
104+
var hexStr = uPyFs.getIntelHex(hexBoardIdV2);
101105
} else {
102106
throw Error('Could not recognise the Board ID ' + boardId);
103107
}

js/micropythonapi.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ var microPythonApi = (function () {
141141
* the MicroPython version relevant to the board ID.
142142
*/
143143
var getCompatibleMicroPythonApi = function(boardId) {
144-
if (boardId == '9903' || boardId == '9904') {
145-
return getFullMicroPythonApi();
146-
} else {
144+
if (boardId == '9900' || boardId == '9901') {
147145
return getBaseMicroPythonApi();
146+
} else {
147+
return getFullMicroPythonApi();
148148
}
149149
}
150150

@@ -217,9 +217,9 @@ var microPythonApi = (function () {
217217
};
218218

219219
var isApiUsedCompatible = function(boardId, pyCode) {
220-
if (boardId == '9903' || boardId == '9904') {
220+
if (['9903', '9904', '9905', '9906'].indexOf(boardId) >= 0) {
221221
return true;
222-
} else if (boardId == '9900' || boardId == '9901') {
222+
} else if (['9900', '9901'].indexOf(boardId) >= 0) {
223223
var additionalModules = Object.keys(extraModules)
224224
var includesExtra = false;
225225
var imports = detectImports(pyCode);

0 commit comments

Comments
 (0)