From 4f5c4d69f7103bc01dcf557fc84b6475552de934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 16 Apr 2017 16:54:09 +0200 Subject: [PATCH] readme fix --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99b054f..23a74df 100644 --- a/README.md +++ b/README.md @@ -77,28 +77,32 @@ One (not too pretty) way to do this is using a global variable - pseudocode: ```c #define MSG_PING 42 -volatile bool onResponse_done = false; + +static volatile bool got_response = false; /** 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 ... // (eg. copy data to a global variable) - onResponse_done = true; + got_response = true; return true; } bool syncQuery(void) { 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 + // the ID is now in `id` so we can remove the listener after a timeout + // Wait for the response bool suc = true; - while (!onResponse_done) { - //delay + while (!got_response) { + //delay() if (/*timeout*/) { TF_RemoveIdListener(id); // free the listener slot return false;