pull/9/head 0.9
Ondřej Hruška 8 years ago
parent 61c82b614b
commit 4f5c4d69f7
  1. 16
      README.md

@ -77,28 +77,32 @@ One (not too pretty) way to do this is using a global variable - pseudocode:
```c ```c
#define MSG_PING 42 #define MSG_PING 42
volatile bool onResponse_done = false;
static volatile bool got_response = false;
/** ID listener */ /** ID listener */
bool onResponse(TF_ID frame_id, TF_TYPE type, const uint8_t *data, TF_LEN len) static bool onResponse(TF_ID frame_id, TF_TYPE type, const uint8_t *data, TF_LEN len)
{ {
// ... Do something ... // ... Do something ...
// (eg. copy data to a global variable) // (eg. copy data to a global variable)
onResponse_done = true; got_response = true;
return true; return true;
} }
bool syncQuery(void) bool syncQuery(void)
{ {
TF_ID id; TF_ID id;
// Send our request // Send our request, and bind an ID listener
got_response = false;
TF_Send0(MSG_PING, onResponse, &id); // Send0 sends zero bytes of data, just TYPE TF_Send0(MSG_PING, onResponse, &id); // Send0 sends zero bytes of data, just TYPE
// the ID is now in `id` so we can remove the listener after a timeout
// Wait for the response // Wait for the response
bool suc = true; bool suc = true;
while (!onResponse_done) { while (!got_response) {
//delay //delay()
if (/*timeout*/) { if (/*timeout*/) {
TF_RemoveIdListener(id); // free the listener slot TF_RemoveIdListener(id); // free the listener slot
return false; return false;

Loading…
Cancel
Save