PlatformIO 的范围问题(?)

Scope problems(?) with PlatformIO

我一直在寻找其他开发平台来处理基于 Atmel (Arduino/ATTiny) 和 Espressif (ESP8266) 的设备。最近,我安装了 PlatformIO。但是我在似乎是对全球范围的认可方面遇到了麻烦。不确定...

我有一个头文件,其中包含配置结构的 typedef:

typedef struct {
        char idPrefix[8];
        char defPass[16];
        char targetSSID[32];
        char targetPass[64];
        uint8_t beepInRange;
        uint8_t beepOutofRange;
} devConfig;

我想在我的 ino 文件中分配一个配置变量:

devConfig myConfig;

但是当我尝试在我的设置或循环中访问它时,例如:

void setup() {
  strncpy(myConfig.defPass, "somepass", 16);
}

当我尝试平台 运行

时它吐出 "error: 'myConfig' was not declared in this scope"

这个东西是不是和arduino一样不支持全局变量?我究竟做错了什么?感谢任何帮助。

我想你一定是忘记在主代码中添加#include "Arduino.h"头文件了。另外,请注意 Platform IO 编译的是 cpp 文件而不是 ino 文件。

main.cpp

// Without Arduino.h this code will not compile
#include "Arduino.h"
#include "demo.h"

devConfig myConfig;

void setup() {
  strncpy(myConfig.defPass, "somepass", 16);
}

void loop() {

}

demo.h

typedef struct {
        char idPrefix[8];
        char defPass[16];
        char targetSSID[32];
        char targetPass[64];
        uint8_t beepInRange;
        uint8_t beepOutofRange;
} devConfig;