【问题标题】:Using config.json file with BBC Micro:bit Mbed online compiler使用 config.json 文件和 BBC Micro:bit Mbed 在线编译器
【发布时间】:2018-05-14 18:44:24
【问题描述】:

有没有人获得在线 Mbed C/C++ 编译器以将 config.json 文件与 BBC Micro:bit 一起使用?如果是这样,您将 config.json 文件放在文件系统的哪个位置?

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

在我看来,Mbed 在线编译器忽略了 config.json 文件。该文件的内容会关闭蓝牙,因为 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);       
    }
}

【问题讨论】:

  • C != C++。仅使用您正在使用的语言进行标记,除非两者都实际相关。

标签: c++ c mbed bbc-microbit


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-28
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    相关资源
    最近更新 更多