Skip to content

Commit e61145a

Browse files
committed
support v2 microbits
1 parent 36cf218 commit e61145a

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
-->
1616
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1717
package="com.samsung.microbit"
18-
android:versionCode="27"
19-
android:versionName="2.6">
18+
android:versionCode="29"
19+
android:versionName="2.8">
2020

2121
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2222
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

app/src/main/java/com/samsung/microbit/ui/activity/PairingActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ private void startPairingSecureBle(BluetoothDevice device) {
14221422
} else {
14231423
logi("device.createBond returns " + device.createBond());
14241424
}
1425+
device.createBond();
14251426
}
14261427

14271428
@Override

app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,17 @@ protected void startFlashing(int flashingType) {
11301130
String hexAbsolutePath = ret[0];
11311131
int applicationSize = Integer.parseInt(ret[1]);
11321132

1133+
if(applicationSize == -1) {
1134+
// V1 Hex on a V2
1135+
PopUp.show(getString(R.string.v1_hex_v2_hardware),
1136+
"",
1137+
R.drawable.message_face, R.drawable.red_btn,
1138+
PopUp.GIFF_ANIMATION_ERROR,
1139+
TYPE_ALERT,
1140+
null, null);
1141+
return;
1142+
}
1143+
11331144
// If V2 create init packet
11341145
String initPacketAbsolutePath = "-1";
11351146
if(hardwareType == MICROBIT_V2) {
@@ -1143,7 +1154,7 @@ protected void startFlashing(int flashingType) {
11431154
}
11441155
}
11451156

1146-
if(flashingType == FLASH_TYPE_DFU) {
1157+
if(flashingType == FLASH_TYPE_DFU || hardwareType == MICROBIT_V2) {
11471158

11481159
// Start DFU Service
11491160
Log.v(TAG, "Start Full DFU");
@@ -1358,7 +1369,7 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
13581369

13591370
int lower_bound = 0; int upper_bound = 0;
13601371
if(hardwareType == MICROBIT_V1) { lower_bound = 0x18000; upper_bound = 0x38000; }
1361-
if(hardwareType == MICROBIT_V2) { lower_bound = 0x27000; upper_bound = 0x70000; }
1372+
if(hardwareType == MICROBIT_V2) { lower_bound = 0x27000; upper_bound = 0x71FFF; }
13621373

13631374
if ((records_wanted || !is_fat) && b_addr >= lower_bound && b_addr < upper_bound) {
13641375
outputHex.write(bs, b_x, next);
@@ -1386,7 +1397,6 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
13861397
byte[] output = outputHex.toByteArray();
13871398
Log.v(TAG, "Finished parsing HEX. Writing application HEX for flashing");
13881399

1389-
13901400
try {
13911401
File hexToFlash = new File(this.getCacheDir() + "/application.hex");
13921402
if (hexToFlash.exists()) {
@@ -1404,6 +1414,10 @@ private String[] universalHexToDFU(String inputPath, int hardwareType) {
14041414
ret[0] = hexToFlash.getAbsolutePath();
14051415
ret[1] = Integer.toString(application_size);
14061416

1417+
if(hardwareType == MICROBIT_V2 && is_fat == false) {
1418+
ret[1] = Integer.toString(-1); // Invalidate hex file
1419+
}
1420+
14071421
return ret;
14081422
} catch (IOException e) {
14091423
e.printStackTrace();

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
<string name="init_connection">Connecting to micro:bit</string>
249249
<string name="disconnecting">Disconnecting from micro:bit</string>
250250
<string name="dfu_status_starting_msg">Initializing flashing process&#8230;</string>
251+
<string name="v1_hex_v2_hardware">This hex file is not compatible with V2 hardware\nPlease re-download it from MakeCode</string>
251252
<string name="multple_flashing_session_msg">A project is currently being flashed. Wait for it to complete!</string>
252253
<string name="internal_error_msg">Internal error. Please try again</string>
253254
<string name="no_device_paired">Cannot connect. No micro:bit paired</string>

0 commit comments

Comments
 (0)