gpt4 book ai didi

c++ - 如何访问arduino库中的枚举变量

转载 作者:行者123 更新时间:2023-11-30 05:37:11 26 4
gpt4 key购买 nike

现在,我正在研究 RH-RF22 库,我需要更改频率和调制

#include <RHReliableDatagram.h>
#include <RH_RF22.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
// Singleton instance of the radio driver

RH_RF22 driver;

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
void setup()
{
driver.setFrequency(433,0.5);
driver.setModemConfig(ModemConfigChoice GFSK_Rb9_6Fd45);
Serial.begin(9600);
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
}
uint8_t data[] = "Hello World!";
// Dont put this on the stack:
uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
void loop()
{
Serial.println("Sending to rf22_reliable_datagram_server");

// Send a message to manager_server
if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
{
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is rf22_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");
delay(500);
}

这一行枚举有错误

driver.setModemConfig(ModemConfigChoice GFSK_Rb9_6Fd45);

但是

driver.setFrequency(433,0.5);

没问题。这是图书馆链接

RH_RF22.cpp

RH_RF22.h

正如您在链接 RH_RF22.h 上看到的那样,我想使用它来分配 typedef enum ModemConfigChoice

setModemConfig() 

函数。你可以看到

setModemConfig() 

RH_RF22.cpp 中的函数

注意:arduino ide的报错是这样的

rfm23bp.ino: In function 'void setup()':
rfm23bp:15: error: 'ModemConfigChoice' was not declared in this scope

最佳答案

您需要将代码更改为以下内容才能使其正常工作:

driver.setModemConfig(RH_RF22::GFSK_Rb9_6Fd45);

关于c++ - 如何访问arduino库中的枚举变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33342298/

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