gpt4 book ai didi

c++ - 将 config.json 文件与 BBC Micro :bit Mbed online compiler 一起使用

转载 作者:搜寻专家 更新时间:2023-10-31 01:30:36 25 4
gpt4 key购买 nike

有没有人获得在线 Mbed C/C++ 编译器来使用 config.json 文件和 BBC Micro:bit?如果是这样,您将 config.json 文件放在文件系统中的什么位置?

当我使用 Mbed 在线 C/C++ 编译器构建名为 microbit-simple-radio-rx 和 microbit-simple-radio-tx 的示例 radio 程序时,在加载十六进制文件。但是,当我使用离线 yotta 命令行使用相同的 config.json 文件为 Micro:bit 编译相同的示例并加载 hex 文件时,这些示例确实运行正确。

在我看来,Mbed 在线编译器忽略了 config.json 文件。此文件的内容关闭蓝牙,因为 Micro:bit radio 使用自定义堆栈,无法与蓝牙同时运行。我还可以通过将此行添加到 MicroBit.h 库来关闭蓝牙库:

#define MICROBIT_BLE_ENABLED 0

这使得示例能够使用在线 Mbed 编译器正确编译和运行。

config.json 文件:

{ 
microbit-dal:{
bluetooth:{
enabled: 0
}
}
}

microbit_simple_radio_rx:

#include "MicroBit.h"

MicroBit uBit;

void onData(MicroBitEvent)
{
ManagedString s = uBit.radio.datagram.recv();

if (s == "1")
uBit.display.print("A");

if (s == "2")
Bit.display.print("B");
}

int main()
{
// Initialise the micro:bit runtime.
uBit.init();

uBit.messageBus.listen(MICROBIT_ID_RADIO,
MICROBIT_RADIO_EVT_DATAGRAM, onData);
uBit.radio.enable();

while(1)
uBit.sleep(1000);
}

microbit_simple_radio_tx:

#include "MicroBit.h"

MicroBit uBit;

int main()
{
// Initialise the micro:bit runtime.
uBit.init();
uBit.radio.enable();

while(1)
{
uBit.display.print("t");
if (uBit.buttonA.isPressed())
{
uBit.radio.datagram.send("1");
uBit.display.print("1");
}
else if (uBit.buttonB.isPressed())
{
uBit.radio.datagram.send("2");
uBit.display.print("2");
}
uBit.sleep(200);
}
}

最佳答案

Mbed 在线编译器使用 mbed_app.json ,而不是 config.json。您可以通过以下方式执行与现在尝试执行的操作相同的操作:

{
"macros": [ "MICROBIT_BLE_ENABLED=0" ]
}

只需将其放入 mbed_app.json 并放在项目的根目录中即可。

关于c++ - 将 config.json 文件与 BBC Micro :bit Mbed online compiler 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com