Skip to content

fix: Omit program slot ID when not specified. #2343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/ble-pybricks-service/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021-2024 The Pybricks Authors
// Copyright (c) 2021-2025 The Pybricks Authors
//
// Actions for Bluetooth Low Energy Pybricks service

Expand Down Expand Up @@ -85,11 +85,13 @@ export const sendLegacyStartReplCommand = createAction((id: number) => ({
*
* @since Pybricks Profile v1.4.0
*/
export const sendStartUserProgramCommand = createAction((id: number, slot: number) => ({
type: 'blePybricksServiceCommand.action.sendStartUserProgram',
id,
slot,
}));
export const sendStartUserProgramCommand = createAction(
(id: number, slot: number | null) => ({
type: 'blePybricksServiceCommand.action.sendStartUserProgram',
id,
slot,
}),
);

/**
* Action that requests to write user program metadata.
Expand Down
12 changes: 10 additions & 2 deletions src/ble-pybricks-service/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2024 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors
//
// Definitions related to the Pybricks Bluetooth low energy GATT service.

Expand Down Expand Up @@ -114,12 +114,20 @@ export function createStopUserProgramCommand(): Uint8Array {
* Parameters:
* - slot: Program identifier (one byte). Slots 0--127 are reserved for
* downloaded user programs. Slots 128--255 are for builtin user programs.
* If null, the hub will start the program slot selected on the hub.
*
* @since Pybricks Profile v1.4.0
*/
export function createStartUserProgramCommand(
slot: number | BuiltinProgramId,
slot: number | BuiltinProgramId | null,
): Uint8Array {
// Omit optional slot id to start currently active slot.
if (slot === null) {
const msg = new Uint8Array(1);
msg[0] = CommandType.StartUserProgram;
return msg;
}

const msg = new Uint8Array(2);
msg[0] = CommandType.StartUserProgram;
msg[1] = slot;
Expand Down
4 changes: 2 additions & 2 deletions src/hub/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2024 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

import { createAction } from '../actions';
import { FileFormat } from '../ble-pybricks-service/protocol';
Expand All @@ -26,7 +26,7 @@ export const downloadAndRun = createAction(
fileFormat: FileFormat | null,
useLegacyDownload: boolean,
useLegacyStartUserProgram: boolean,
slot: number,
slot: number | null,
) => ({
type: 'hub.action.downloadAndRun',
fileFormat,
Expand Down
4 changes: 2 additions & 2 deletions src/hub/sagas.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2024 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

import { AsyncSaga } from '../../test';
import { alertsShowAlert } from '../alerts/actions';
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('downloadAndRun', () => {

saga.updateState({ editor: { isReady: true } });

saga.put(downloadAndRun(FileFormat.Mpy5, true, true, 0));
saga.put(downloadAndRun(FileFormat.Mpy5, true, true, null));

// first, it gets the value from the current editor
const editorValueAction = await saga.take();
Expand Down
4 changes: 2 additions & 2 deletions src/toolbar/buttons/run/RunButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2024 The Pybricks Authors
// Copyright (c) 2022-2025 The Pybricks Authors

import { act, cleanup } from '@testing-library/react';
import React from 'react';
Expand Down Expand Up @@ -43,7 +43,7 @@ test.each([
FileFormat.MultiMpy6,
legacyDownload,
legacyStartUserProgram,
0,
null,
),
);
},
Expand Down
4 changes: 2 additions & 2 deletions src/toolbar/buttons/run/RunButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2024 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

import React from 'react';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -48,7 +48,7 @@ const RunButton: React.FunctionComponent<RunButtonProps> = ({ id }) => {
preferredFileFormat,
useLegacyDownload,
useLegacyStartUserProgram,
0, // No slot UI yet
null, // No slot UI yet, downloading to active hub slot
),
)
}
Expand Down
Loading