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

标签 c++ c mbed bbc-microbit

有人获得了在线 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 编译相同示例并加载十六进制文件时,这些示例确实运行正确。

在我看来,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/

相关文章:

c++ - 在 C++ 中将 if、else if、else 语句转换为 switch 语句

使用 C 与 mbed 通信

objective-c - CoreMIDI:坚如磐石的 MIDI 同步

http - 如何判断 HTTP 响应是否在 C 中终止

c++ - 是否允许在 std::string 的实现中进行这种优化?

c++ - Dev-C++ 为 Makefile.win 和 g++ 停止提供错误

c++ - 将指针作为内存地址传递并使其永久化

c++ - boost 测试链接

c - 将数据输出到文本文件的问题

c - Gnu Scientific Library 的曲线拟合示例代码无法运行。