mBed RFM12B module library

Dependents:   _EXAMPLE_RFM12B

Fork of RF12B by Sukkin Pang

RFM12B Library

The main purpose of this library was to implement the RFM12B module in order to be able to establish communication with the Moteino (arduino clone that uses the RFM12B).

In order to achieve my goal I was highly inspired by RF12B library from pangsk https://mbed.org/users/pangsk/ and by RFM12B arduino library made by Felix Rusu (http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/)

Who/What is Moteino? (http://lowpowerlab.com/moteino/)

Files at this revision

API Documentation at this revision

Comitter:
hajesusrodrigues
Date:
Fri May 31 16:34:12 2013 +0000
Parent:
7:19d9da22271a
Commit message:
Implementation of Sleep/WakeUp/LowBattery methods.

Changed in this revision

RFM12B.cpp Show annotated file Show diff for this revision Revisions of this file
RFM12B.h Show annotated file Show diff for this revision Revisions of this file
diff -r 19d9da22271a -r 7d282360721a RFM12B.cpp
--- a/RFM12B.cpp	Thu May 30 22:11:42 2013 +0000
+++ b/RFM12B.cpp	Fri May 31 16:34:12 2013 +0000
@@ -1,13 +1,14 @@
 /*
  RFM12B Library. Based on work done by JeeLabs.org ported to mBed by SK Pang.
  http://jeelabs.net/projects/cafe/wiki/RF12
+ Jan 2012 skpang.co.uk
+
+ RFM12B Library (Moteino Comunication Protocol). Based on work done by Felix Rusu ported to mBed by Hugo Rodrigues
+ http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/
+ May 2013 Hugo Rodrigues
 
  http://opensource.org/licenses/mit-license.php
 
- Jan 2012 skpang.co.uk
-
- Modified by Hugo Rodrigues (May 2013)
-
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
@@ -392,3 +393,29 @@
     } else
         useEncryption = false;
 }
+
+void RFM12B::Sleep(int n)
+{
+    if (n < 0)
+        xfer(RF_IDLE_MODE);
+    else {
+        xfer(RF_WAKEUP_TIMER | 0x0500 | n);
+        xfer(RF_SLEEP_MODE);
+        if (n > 0)
+            xfer(RF_WAKEUP_MODE);
+    }
+    rxstate = TXIDLE;
+}
+void RFM12B::Sleep()
+{
+    Sleep(0);
+}
+void RFM12B::Wakeup()
+{
+    Sleep(-1);
+}
+
+bool RFM12B::LowBattery()
+{
+    return (xfer(0x0000) & RF_LBD_BIT) != 0;
+}
\ No newline at end of file
diff -r 19d9da22271a -r 7d282360721a RFM12B.h
--- a/RFM12B.h	Thu May 30 22:11:42 2013 +0000
+++ b/RFM12B.h	Fri May 31 16:34:12 2013 +0000
@@ -1,13 +1,14 @@
 /*
  RFM12B Library. Based on work done by JeeLabs.org ported to mBed by SK Pang.
  http://jeelabs.net/projects/cafe/wiki/RF12
+ Jan 2012 skpang.co.uk
+
+ RFM12B Library (Moteino Comunication Protocol). Based on work done by Felix Rusu ported to mBed by Hugo Rodrigues
+ http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/
+ May 2013 Hugo Rodrigues
 
  http://opensource.org/licenses/mit-license.php
 
- Jan 2012 skpang.co.uk
-
- Modified by Hugo Rodrigues (May 2013)
-
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
@@ -102,6 +103,11 @@
     void SendACK(const void* sendBuf = "", uint8_t sendLen = 0);
     void Send(uint8_t toNodeId, const void* sendBuf, uint8_t sendLen, bool requestACK = false);
 
+    void Sleep(int n);
+    void Sleep();
+    void Wakeup();
+    bool LowBattery();
+
     volatile uint8_t * GetData();
     uint8_t GetDataLen(void);                   // how many bytes were received
     uint8_t GetSender(void);