Skip to content
Merged
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
23 changes: 13 additions & 10 deletions code-mirror-experiment.code-workspace
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"folders": [
{
"path": "."
},
{
"path": "../../codemirror/codemirror.next"
}
],
"settings": {}
}
"folders": [
{
"path": "."
},
{
"path": "../../codemirror/codemirror.next"
},
{
"path": "../python/python-editor"
}
],
"settings": {}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<noscript
>You need to enable JavaScript to run the Python Editor in your
browser.</noscript
>
<div id="root"></div>
</body>
</html>
6 changes: 4 additions & 2 deletions src/common/use-action-feedback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { ReactNode } from "react";
import { Link, useToast } from "@chakra-ui/react";
import { useMemo } from "react";
import config from "../config";
Expand All @@ -14,7 +14,7 @@ export class ActionFeedback {
description,
}: {
title: string;
description: string;
description: ReactNode;
}) {
this.toast({
title,
Expand All @@ -30,6 +30,8 @@ export class ActionFeedback {
* @param error the error thrown.
*/
unexpectedError(error: Error) {
// For now at least.
console.error(error);
this.toast({
title: "An unexpected error occurred",
status: "error",
Expand Down
47 changes: 47 additions & 0 deletions src/device/board-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Validates micro:bit board IDs.
*/
export class BoardId {
private static v1Normalized = new BoardId(0x9900);
private static v2Normalized = new BoardId(0x9903);

constructor(public id: number) {
if (!this.isV1() && !this.isV2()) {
throw new Error(`Could not recognise the Board ID ${id.toString(16)}`);
}
}

isV1(): boolean {
return this.id === 0x9900 || this.id === 0x9901;
}

isV2(): boolean {
return this.id === 0x9903 || this.id === 0x9904;
}

/**
* Return the board ID using the default ID for the board type.
* Used to integrate with MicropythonFsHex.
*/
normalize() {
return this.isV1() ? BoardId.v1Normalized : BoardId.v2Normalized;
}

/**
* toString matches the input to parse.
*
* @returns the ID as a string.
*/
toString() {
return this.id.toString(16);
}

/**
* @param value The ID as a hex string with no 0x prefix (e.g. 9900).
* @returns the valid board ID
* @throws if the ID isn't known.
*/
static parse(value: string): BoardId {
return new BoardId(parseInt(value, 16));
}
}
Loading