A more general purpose RFM69 library?

Started by DeKay, December 29, 2013, 04:12:37 PM

DeKay

The RFM69 is a pretty cool chip that seems to have the flexibility to talk to other devices like the RFM12B.  I'm playing with this library right now to see if I can get it talking to the CC1021 in my weather station.  What I am finding is that the RFM69 library is specific to Moteino <-> Moteino communications e.g. the initialize routine.  Could this be restructured somewhat so that the register initializations could be DEFINED based on specific applications to keep the code stuffed into the AVR chip as lean and mean as possible?  What would be the best way to approach this?

And I'm quite new to Arduino stuff, but it doesn't make sense to me that there is this...
/* 0x2f */ { REG_SYNCVALUE1, 0x2D },      //attempt to make this compatible with sync1 byte of R
FM12B lib


Followed by both of these lines in RFM69.cpp (and why a do / while loop?)

  do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa);
  do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55);


Felix

You can always inherit from the RFM69 class or extend it and overwrite/overload the initialize function and do whatever you'd like with it. The given code is a working example.
The write/read to REG_SYNCVALUE1 is done that way to ensure the radio is active and working. The following for loop writes all the wanted values to all the registers including REG_SYNCVALUE1:

  for (byte i = 0; CONFIG
  • != 255; i++)
        writeReg(CONFIG
    • , CONFIG[1]);

DeKay

Quote from: Felix on December 29, 2013, 04:42:03 PM
You can always inherit from the RFM69 class or extend it and overwrite/overload the initialize function and do whatever you'd like with it.

I did, and it works!!!  I'm now able to monitor the wireless transmissions from my weather station and pick them up on a Moteino.  See this blog post.

Felix, I've sent you a pull request on Github with a few extra register definitions to your library and a very minor cleanup or two that you can hopefully incorporate.  Otherwise, my library just rides on top of yours.  There is a weird bug or two lurking in my reception of the data that I will need to dig into but that is a separate issue.

Gotta love it when it works   8)

Felix

I just merged your changes, thanks for all your contributions!
I think inheriting from my lib and adding your specific functionality or overriding my function is ideal since if there's a bug in MY library then that will automatically be fixed when you get latest code. Otherwise every time I make an update that the user would want, then the user has to go dig their own code and fix all the instances of that patch.