Skip to content

Commit

Permalink
Add faux French for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Nov 22, 2024
1 parent 62ab8f9 commit 3628304
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 41 deletions.
96 changes: 96 additions & 0 deletions _locales/fr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Microsoft MakeCode extension for use with micro:bit CreateAI

FR - This extension is leveraged by micro:bit CreateAI which creates suitable blocks based on the machine learning model you build in the app. It is not useful separate from micro:bit CreateAI.

## Building locally

Ensure you have the required toolchain to build for V1 and V2
(arm-none-eabi-gcc, python, yotta, cmake, ninja, srec_cat) or docker.

```bash
git clone https://github.com/microbit-foundation/pxt-microbit-ml
cd pxt-microbit-ml
npm install pxt --no-save
npx pxt target microbit --no-save
npx pxt install
PXT_FORCE_LOCAL=1 PXT_NODOCKER=1 npx pxt
```

For the V1 build Yotta can hit the GitHub rate limits quite easily if the
project is built from a clean state more than once.
A V2-only build can be performed with the `PXT_COMPILE_SWITCHES=csv---mbcodal`
environmental variable.

```
PXT_FORCE_LOCAL=1 PXT_NODOCKER=1 PXT_COMPILE_SWITCHES=csv---mbcodal npx pxt
```

## Build flags

### Model predictions per second

By default the model will run every 250 ms, to change this value the
`ML_INFERENCE_PERIOD_MS` config can be modified.

```json
{
"yotta": {
"config": {
"ML_INFERENCE_PERIOD_MS": 250
}
}
}
```

### Model events

By default this extension configures the Model prediction events to not be
queued for the same event.
So if an event raised when its handler is still running it will be dropped.

```json
{
"yotta": {
"config": {
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
}
}
}
```

The values are defined in the
[codal-core/inc/core/CodalListener.h](https://github.com/lancaster-university/codal-core/blob/df05db9e15499bd8906618192a4d482e3836c62f/inc/core/CodalListener.h#L36-L40)
file:

```cpp
#define MESSAGE_BUS_LISTENER_REENTRANT 0x0008
#define MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY 0x0010
#define MESSAGE_BUS_LISTENER_DROP_IF_BUSY 0x0020
#define MESSAGE_BUS_LISTENER_NONBLOCKING 0x0040
#define MESSAGE_BUS_LISTENER_URGENT 0x0080
```

### Debug messages

To enable debug print from this extension, add the following into your
pxt.json file:

```json
{
"yotta": {
"config": {
"ML_DEBUG_PRINT": 1
}
}
}
```

## License

This software made available under the MIT open source license.

[SPDX-License-Identifier: MIT](/LICENSE)

## Code of Conduct

Trust, partnership, simplicity and passion are our core values we live and breathe in our daily work life and within our projects. Our open-source projects are no exception. We have an active community which spans the globe and we welcome and encourage participation and contributions to our projects by everyone. We work to foster a positive, open, inclusive and supportive environment and trust that our community respects the micro:bit code of conduct. Please see our [code of conduct](https://www.microbit.org/safeguarding/) which outlines our expectations for all those that participate in our community and details on how to report any concerns and what would happen should breaches occur.
7 changes: 7 additions & 0 deletions _locales/fr/machine-learning-jsdoc-strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mlrunner.customOnEvent": "FR - Register a TypeScript function to run when an event is raised.\n* This custom version of the MakeCode onEvent function is needed due to:\nhttps://github.com/microsoft/pxt-microbit/issues/5709\n*",
"mlrunner.customOnEvent|param|flags": "FR - The specified event flags are ignored and configured via pxt.json.",
"mlrunner.customOnEvent|param|handler": "FR - The function to call when the event is detected.",
"mlrunner.customOnEvent|param|src": "FR - The ID of the component to listen to.",
"mlrunner.customOnEvent|param|value": "FR - The event value to listen to from that component."
}
13 changes: 13 additions & 0 deletions _locales/fr/machine-learning-strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"ml.event.Unknown|block": "FR - unknown",
"ml.getCertainty|block": "FR - certainty (\\%) ML $event",
"ml.isDetected|block": "FR - is ML $event detected",
"ml.onStart|block": "FR - on ML $event start",
"ml.onStopDetailed|block": "FR - on ML $event stop $duration (ms)",
"ml.onStop|block": "FR - on ML $event stop",
"mlrunner|block": "FR - mlrunner",
"{id:category}Ml": "FR - Ml",
"{id:category}MlEvent": "FR - MlEvent",
"{id:category}Mlrunner": "FR - Mlrunner",
"{id:group}micro:bit (V2)": "FR - micro:bit (V2)"
}
69 changes: 33 additions & 36 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
{
"name": "machine-learning",
"version": "1.0.2",
"description": "Machine learning extension to support micro:bit CreateAI",
"dependencies": {
"core": "*",
"machine-learning-runner": "github:microbit-foundation/pxt-microbit-ml-runner#v0.4.8"
},
"files": [
"README.md",
"shims.d.ts",
"enums.d.ts",
"pxtextension.ts",
"pxtextension.cpp"
],
"testFiles": [
"autogenerated.ts",
"main.ts",
"main.blocks"
],
"targetVersions": {
"branch": "v6.0.26",
"tag": "v6.0.26",
"commits": "https://github.com/microsoft/pxt-microbit/commits/0ba979dd8a8f411c37c20b5fd4faba5b43ef51aa",
"target": "6.0.26",
"targetId": "microbit",
"pxt": "9.0.17"
},
"supportedTargets": [
"microbit"
],
"preferredEditor": "tsprj",
"yotta": {
"config": {
"ML_INFERENCE_PERIOD_MS": 250,
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
}
"name": "machine-learning",
"version": "1.0.2",
"description": "Machine learning extension to support micro:bit CreateAI",
"dependencies": {
"core": "*",
"machine-learning-runner": "github:microbit-foundation/pxt-microbit-ml-runner#v0.4.8"
},
"files": [
"README.md",
"shims.d.ts",
"enums.d.ts",
"pxtextension.ts",
"pxtextension.cpp",
"_locales/fr/machine-learning-jsdoc-strings.json",
"_locales/fr/machine-learning-strings.json",
"_locales/fr/README.md"
],
"testFiles": ["autogenerated.ts", "main.ts", "main.blocks"],
"targetVersions": {
"branch": "v6.0.26",
"tag": "v6.0.26",
"commits": "https://github.com/microsoft/pxt-microbit/commits/0ba979dd8a8f411c37c20b5fd4faba5b43ef51aa",
"target": "6.0.26",
"targetId": "microbit",
"pxt": "9.0.17"
},
"supportedTargets": ["microbit"],
"preferredEditor": "tsprj",
"yotta": {
"config": {
"ML_INFERENCE_PERIOD_MS": 250,
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
}
}
}
5 changes: 0 additions & 5 deletions pxtextension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ namespace ml {
//% weight=50
//% parts="v2"
//% group="micro:bit (V2)"
//% help=none
export function onStart(event: MlEvent, body: () => void): void {
event.onStartHandler = body;
const wrappedBody = () => {
Expand All @@ -80,7 +79,6 @@ namespace ml {
//% weight=40
//% parts="v2"
//% group="micro:bit (V2)"
//% help=none
export function onStop(event: MlEvent, body: () => void): void {
if (!isRunning()) {
startRunning();
Expand All @@ -94,7 +92,6 @@ namespace ml {
//% draggableParameters="reporter"
//% parts="v2"
//% group="micro:bit (V2)"
//% help=none
export function onStopDetailed(
event: MlEvent,
body: (duration: number) => void
Expand All @@ -110,7 +107,6 @@ namespace ml {
//% weight=20
//% parts="v2"
//% group="micro:bit (V2)"
//% help=none
export function isDetected(event: MlEvent): boolean {
if (!isRunning()) {
startRunning();
Expand All @@ -123,7 +119,6 @@ namespace ml {
//% block="certainty (\\%) ML $event"
//% weight=10
//% parts="v2"
//% help=none
export function getCertainty(event: MlEvent): number {
const eventValue = event.eventValue;
if (eventValue <= 1) {
Expand Down

0 comments on commit 3628304

Please sign in to comment.