简体   繁体   中英

How to access enum variable in arduino library

Now, I'm working on RH-RF22 library which i need to change frequency and modulation

#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);
}

There is an error about enum on the this line

driver.setModemConfig(ModemConfigChoice GFSK_Rb9_6Fd45);

but

driver.setFrequency(433,0.5);

is ok. Here is the library link

RH_RF22.cpp

RH_RF22.h

as you could see on the link RH_RF22.hcontains typedef enum ModemConfigChoice which I want to use it to assign to

setModemConfig() 

function. You can see the

setModemConfig() 

function in RH_RF22.cpp

Note: The error from arduino ide look like this

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

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

driver.setModemConfig(RH_RF22::GFSK_Rb9_6Fd45);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM