mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
firmware: flash custom hub name
This adds support for customizing the hub name when flashing firmware. Fixes: https://github.com/pybricks/support/issues/52
This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Hub name setting for selecting hub name when flashing firmware ([support#52]).
|
||||
|
||||
[support#52]: https://github.com/pybricks/support/issues/52
|
||||
|
||||
## [1.1.0-beta.6] - 2021-09-21
|
||||
|
||||
### Added
|
||||
|
||||
@@ -63,6 +63,8 @@ describe('flashFirmware', () => {
|
||||
'mpy-abi-version': 5,
|
||||
'mpy-cross-options': ['-mno-unicode'],
|
||||
'user-mpy-offset': 100,
|
||||
'hub-name-offset': 90,
|
||||
'max-hub-name-size': 10,
|
||||
};
|
||||
|
||||
const zip = new JSZip();
|
||||
@@ -79,7 +81,7 @@ describe('flashFirmware', () => {
|
||||
flashFirmware,
|
||||
{
|
||||
bootloader: { connection: BootloaderConnectionState.Disconnected },
|
||||
settings: { flashCurrentProgram: false },
|
||||
settings: { flashCurrentProgram: false, hubName: 'test name' },
|
||||
},
|
||||
{
|
||||
nextMessageId: createCountFunc(),
|
||||
@@ -185,7 +187,7 @@ describe('flashFirmware', () => {
|
||||
|
||||
// hub indicates success
|
||||
|
||||
saga.put(programResponse(0x62, totalFirmwareSize));
|
||||
saga.put(programResponse(0x33, totalFirmwareSize));
|
||||
|
||||
action = await saga.take();
|
||||
expect(action).toEqual(didProgress(1));
|
||||
|
||||
+16
-1
@@ -1,7 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2021 The Pybricks Authors
|
||||
|
||||
import { FirmwareReader, FirmwareReaderError, HubType } from '@pybricks/firmware';
|
||||
import {
|
||||
FirmwareReader,
|
||||
FirmwareReaderError,
|
||||
HubType,
|
||||
encodeHubName,
|
||||
} from '@pybricks/firmware';
|
||||
import cityHubZip from '@pybricks/firmware/build/cityhub.zip';
|
||||
import moveHubZip from '@pybricks/firmware/build/movehub.zip';
|
||||
import technicHubZip from '@pybricks/firmware/build/technichub.zip';
|
||||
@@ -241,6 +246,16 @@ function* loadFirmware(
|
||||
firmwareView.setUint32(metadata['user-mpy-offset'], mpy.data.length, true);
|
||||
firmware.set(mpy.data, metadata['user-mpy-offset'] + 4);
|
||||
|
||||
// if the firmware supports it, we can set a custom hub name
|
||||
if (metadata['max-hub-name-size']) {
|
||||
const hubName = yield* select((s: RootState) => s.settings.hubName);
|
||||
|
||||
// empty string means use default name (don't write over firmware)
|
||||
if (hubName) {
|
||||
firmware.set(encodeHubName(hubName, metadata), metadata['hub-name-offset']);
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata['checksum-type'] !== 'sum') {
|
||||
yield* put(
|
||||
didFailToFinish(
|
||||
|
||||
Reference in New Issue
Block a user