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

时间:2015-10-26 09:26:43

标签: c++ enums arduino

现在,我正在研究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

1 个答案:

答案 0 :(得分:1)

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

driver.setModemConfig(RH_RF22::GFSK_Rb9_6Fd45);