Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IM920_sample IM920_SDlog IM920_sample IM920_sample3 ... more
Revision 2:0b47f6b25cc4, committed 2015-01-05
- Comitter:
- idealtechlab
- Date:
- Mon Jan 05 03:47:08 2015 +0000
- Parent:
- 1:81b2fd407327
- Child:
- 3:db269462ad1c
- Commit message:
- support attach
Changed in this revision
--- a/IM920.cpp Fri Dec 26 15:51:37 2014 +0000
+++ b/IM920.cpp Mon Jan 05 03:47:08 2015 +0000
@@ -28,10 +28,9 @@
setReset(false);
}
-int IM920::init (int node, void(*func)()) {
+int IM920::init (int node) {
_state.node = node;
- _state.func = func;
cmdRDID();
cmdSTNN(_state.node);
@@ -43,8 +42,8 @@
void IM920::poll () {
if (_state.received && _state.buf != NULL)
- if (_state.func != NULL && !_state.data->isEmpty()) {
- _state.func();
+ if (!_state.data->isEmpty()) {
+ _func.call();
if (_state.data->isEmpty()) {
_state.received = false;
}
--- a/IM920.h Fri Dec 26 15:51:37 2014 +0000
+++ b/IM920.h Mon Jan 05 03:47:08 2015 +0000
@@ -21,6 +21,7 @@
#include "IM920_conf.h"
#include "mbed.h"
+#include "FunctionPointer.h"
#include "CBuffer.h"
#include <ctype.h>
#include <stdlib.h>
@@ -60,7 +61,17 @@
IM920 (PinName tx, PinName rx, PinName busy = NC, PinName reset = NC, int baud = IM920_BAUD);
- int init (int node, void(*func)() = NULL);
+ int init (int node);
+
+ void attach (void(*fptr)() = NULL) {
+ _func.attach(fptr);
+ }
+ template<typename T>
+ void attach (T* tptr, void (T::*mptr)()) {
+ if ((mptr != NULL) && (tptr != NULL)) {
+ _func.attach(tptr, mptr);
+ }
+ }
void poll ();
@@ -81,6 +92,7 @@
DigitalIn *_busy;
DigitalOut *_reset;
int _baud;
+ FunctionPointer _func;
struct STATE {
int id, node, rssi;
@@ -96,7 +108,6 @@
CircBuffer<char> *data;
volatile bool received;
- void(*func)();
} _state;
// ----- IM920_util.cpp -----
--- a/IM920_msg.cpp Fri Dec 26 15:51:37 2014 +0000
+++ b/IM920_msg.cpp Mon Jan 05 03:47:08 2015 +0000
@@ -55,7 +55,7 @@
sub ++;
if (_state.data!= NULL) {
_state.data->queue(chr);
- if (_state.func != NULL && _state.data->available() >= CFG_DATA_SIZE) {
+ if (_state.data->available() >= CFG_DATA_SIZE) {
_state.received = true;
WARN("buf full");
}