使用 config.json 文件和 BBC Micro:bit Mbed 在线编译器
Using config.json file with BBC Micro:bit Mbed online compiler
有没有人得到在线 Mbed C/C++ 编译器来使用 BBC Micro:bit 的 config.json 文件?如果是这样,您将 config.json 文件放在文件系统中的什么位置?
当我使用在线 Mbed C/C++ 编译器构建名为 microbit-simple-radio-rx 和 microbit-simple-radio-tx 的示例无线电程序时,我没有从加载十六进制文件后 Micro:bits。但是,当我使用离线 yotta 命令行为具有相同 config.json 文件的 Micro:bit 编译相同示例并加载 hex 文件时,这些示例正确地执行 运行。
在我看来 config.json 文件被 Mbed 在线编译器忽略了。此文件的内容关闭蓝牙,因为 Micro:bit 无线电使用自定义堆栈,不能 运行 与蓝牙同时使用。我还可以通过将此行添加到 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
并放入项目的根目录即可。
有没有人得到在线 Mbed C/C++ 编译器来使用 BBC Micro:bit 的 config.json 文件?如果是这样,您将 config.json 文件放在文件系统中的什么位置?
当我使用在线 Mbed C/C++ 编译器构建名为 microbit-simple-radio-rx 和 microbit-simple-radio-tx 的示例无线电程序时,我没有从加载十六进制文件后 Micro:bits。但是,当我使用离线 yotta 命令行为具有相同 config.json 文件的 Micro:bit 编译相同示例并加载 hex 文件时,这些示例正确地执行 运行。
在我看来 config.json 文件被 Mbed 在线编译器忽略了。此文件的内容关闭蓝牙,因为 Micro:bit 无线电使用自定义堆栈,不能 运行 与蓝牙同时使用。我还可以通过将此行添加到 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
并放入项目的根目录即可。