mirror of https://github.com/sebmillet/RF433any
Reorganizes examples
- The first example, 01_main.ino, is the one displaying output meant to be used by the RF433recv library.
This commit is contained in:
parent
a0e07369fa
commit
d84700411b
25
README.md
25
README.md
|
@ -31,22 +31,24 @@ receiver plugged on D2.
|
|||
Usage
|
||||
-----
|
||||
|
||||
See [examples/01_output-received-code/01_output-received-code.ino](examples/01_output-received-code/01_output-received-code.ino)
|
||||
for an example.
|
||||
See [examples/01_main/01_main.ino](examples/01_main/01_main.ino)
|
||||
for an example. This main example will output information in a way that is
|
||||
ready to be used by the RF433recv library, see below why this can be
|
||||
interesting.
|
||||
|
||||
See [examples/02_output-signal-timings/02_output-signal-timings.ino](examples/02_output-signal-timings/02_output-signal-timings.ino)
|
||||
See [examples/02_output-received-code/02_output-received-code.ino](examples/02_output-received-code/02_output-received-code.ino)
|
||||
for another example.
|
||||
|
||||
See [examples/03_react_on_code/03_react_on_code.ino](examples/03_react_on_code/03_react_on_code.ino)
|
||||
See [examples/03_output-signal-timings/03_output-signal-timings.ino](examples/03_output-signal-timings/03_output-signal-timings.ino)
|
||||
for another example, with detailed signal timing information.
|
||||
|
||||
See [examples/04_react_on_code/04_react_on_code.ino](examples/04_react_on_code/04_react_on_code.ino)
|
||||
for an example with code check.
|
||||
|
||||
See [examples/04_callback/04_callback.ino](examples/04_callback/04_callback.ino)
|
||||
See [examples/05_callback/05_callback.ino](examples/05_callback/05_callback.ino)
|
||||
for an example with callback functions registered to be called when specific
|
||||
codes are received.
|
||||
|
||||
Use [examples/05_print_code_for_RF433recv_lib/05_print_code_for_RF433recv_lib.ino](examples/05_print_code_for_RF433recv_lib/05_print_code_for_RF433recv_lib.ino)
|
||||
to display code characteristics in a way that is usable by the library RF433recv.
|
||||
|
||||
More details
|
||||
------------
|
||||
|
||||
|
@ -117,7 +119,8 @@ characteristics.
|
|||
**Then what is RF433recv good for?**
|
||||
|
||||
Actually RF433any, while being 'easy and universal', consumes *a lot* of
|
||||
memory, and this can be problematic.
|
||||
memory, and this can be problematic. RF433recv consumes much less memory,
|
||||
allowing to do something else!
|
||||
|
||||
**How to get the best of the two worlds**
|
||||
|
||||
|
@ -125,7 +128,7 @@ You can use RF433any to get the exact code characteristics and re-use it with
|
|||
RF433recv library.
|
||||
|
||||
This is the goal of
|
||||
[examples/05_print_code_for_RF433recv_lib/05_print_code_for_RF433recv_lib.ino](examples/05_print_code_for_RF433recv_lib/05_print_code_for_RF433recv_lib.ino)
|
||||
[examples/01_main/01_main.ino](examples/01_main/01_main.ino)
|
||||
|
||||
You can copy-paste the output of this sketch to call RF433recv library.
|
||||
You can copy-paste the output of `01_main.ino` to call RF433recv library.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// 05_print_code_for_RF433recv_lib.ino
|
||||
// 01_main.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Displays the signal shape in a way that is ready to use with the library
|
||||
|
@ -23,7 +23,9 @@
|
|||
*/
|
||||
|
||||
//
|
||||
// Schematic: Radio Frequencies RECEIVER plugged on D2
|
||||
// Schematic: Radio Frequencies RECEIVER plugged on D2.
|
||||
// You can change it by updating PIN_RFINPUT below.
|
||||
// Since the library RF433any uses interruptions, the pin MUST BE either 2 or 3.
|
||||
//
|
||||
|
||||
#include "RF433any.h"
|
||||
|
@ -31,6 +33,11 @@
|
|||
|
||||
#define PIN_RFINPUT 2
|
||||
|
||||
// Comment the below macro if you wish to output everything.
|
||||
// As most codes are repeated, this'll likely result in the output of the
|
||||
// same thing multiple times.
|
||||
#define OUTPUT_FIRST_DECODED_ONLY
|
||||
|
||||
char serial_printf_buffer[100];
|
||||
void serial_printf(const char* msg, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
@ -56,54 +63,48 @@ void setup() {
|
|||
Track track(PIN_RFINPUT);
|
||||
|
||||
const char *encoding_names[] = {
|
||||
"RFMOD_TRIBIT",
|
||||
"RFMOD_TRIBIT_INVERTED",
|
||||
"RFMOD_MANCHESTER",
|
||||
"<unmanaged encoding>"
|
||||
"RFMOD_TRIBIT", // T
|
||||
"RFMOD_TRIBIT_INVERTED", // N
|
||||
"RFMOD_MANCHESTER", // M
|
||||
"<unmanaged encoding>" // Anything else
|
||||
};
|
||||
|
||||
const char *id_letter_to_encoding_name(char c) {
|
||||
if (c == 'T')
|
||||
return encoding_names[0];
|
||||
else if (c == 'N')
|
||||
return encoding_names[1];
|
||||
else if (c == 'M')
|
||||
return encoding_names[2];
|
||||
|
||||
return encoding_names[3];
|
||||
}
|
||||
|
||||
void output_timings(Decoder *pdec, byte nb_bits) {
|
||||
TimingsExt tsext;
|
||||
if (!pdec)
|
||||
return;
|
||||
pdec->get_tsext(&tsext);
|
||||
|
||||
if (!tsext.initseq)
|
||||
return;
|
||||
const char *enc_name = id_letter_to_encoding_name(pdec->get_id_letter());
|
||||
|
||||
// serial_printf(" I=%u, LS=%u, LL=%u, HS=%u, HL=%u, S=%u, U=%u, "
|
||||
// "V=%u, Y=%u, Z=%u\n", tsext.initseq, tsext.low_short,
|
||||
// tsext.low_long, tsext.high_short, tsext.high_long, tsext.sep,
|
||||
// tsext.first_low, tsext.first_high, tsext.first_low_ignored,
|
||||
// tsext.last_low);
|
||||
|
||||
const char *enc;
|
||||
if (pdec->get_id_letter() == 'T')
|
||||
enc = encoding_names[0];
|
||||
else if (pdec->get_id_letter() == 'N')
|
||||
enc = encoding_names[1];
|
||||
else if (pdec->get_id_letter() == 'M')
|
||||
enc = encoding_names[2];
|
||||
else
|
||||
enc = encoding_names[3];
|
||||
|
||||
serial_printf("\n// -----CODE START-----\n");
|
||||
serial_printf(" // [WRITE THE DEVICE NAME HERE]\n"
|
||||
serial_printf("\n-----CODE START-----\n");
|
||||
serial_printf("// [WRITE THE DEVICE NAME HERE]\n"
|
||||
"rf.register_Receiver(\n");
|
||||
serial_printf("%s, // mod\n", enc);
|
||||
serial_printf("%5u, // initseq\n", tsext.initseq);
|
||||
serial_printf("%5u, // lo_prefix\n", tsext.first_low);
|
||||
serial_printf("%5u, // hi_prefix\n", tsext.first_high);
|
||||
serial_printf("%5u, // first_lo_ign\n", tsext.first_low_ignored);
|
||||
serial_printf("%5u, // lo_short\n", tsext.low_short);
|
||||
serial_printf("%5u, // lo_long\n", tsext.low_long);
|
||||
serial_printf("%5u, // hi_short (0 => take lo_short)\n", tsext.high_short);
|
||||
serial_printf("%5u, // hi_long (0 => take lo_long)\n", tsext.high_long);
|
||||
serial_printf("%5u, // lo_last\n", tsext.last_low);
|
||||
serial_printf("%5u, // sep\n", tsext.sep);
|
||||
serial_printf("%5u // nb_bits\n", nb_bits);
|
||||
serial_printf("\t%s, // mod\n", enc_name);
|
||||
serial_printf("\t%u, // initseq\n", tsext.initseq);
|
||||
serial_printf("\t%u, // lo_prefix\n", tsext.first_low);
|
||||
serial_printf("\t%u, // hi_prefix\n", tsext.first_high);
|
||||
serial_printf("\t%u, // first_lo_ign\n", tsext.first_low_ignored);
|
||||
serial_printf("\t%u, // lo_short\n", tsext.low_short);
|
||||
serial_printf("\t%u, // lo_long\n", tsext.low_long);
|
||||
serial_printf("\t%u, // hi_short (0 => take lo_short)\n", tsext.high_short);
|
||||
serial_printf("\t%u, // hi_long (0 => take lo_long)\n", tsext.high_long);
|
||||
serial_printf("\t%u, // lo_last\n", tsext.last_low);
|
||||
serial_printf("\t%u, // sep\n", tsext.sep);
|
||||
serial_printf("\t%u // nb_bits\n", nb_bits);
|
||||
serial_printf(");\n");
|
||||
serial_printf("// -----CODE END-----\n\n");
|
||||
serial_printf("-----CODE END-----\n\n");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -116,16 +117,10 @@ void loop() {
|
|||
Decoder *pdec = pdec0;
|
||||
while (pdec) {
|
||||
int nb_bits = pdec->get_nb_bits();
|
||||
bool got_data = pdec->data_got_decoded();
|
||||
BitVector *pdata = pdec->take_away_data();
|
||||
|
||||
serial_printf("Decoded: %s, err: %d, code: %c, "
|
||||
"rep: %d, bits: %2d", (got_data ? "yes" : "no "),
|
||||
pdec->get_nb_errors(), pdec->get_id_letter(),
|
||||
pdec->get_repeats() + 1, nb_bits);
|
||||
|
||||
if (pdata) {
|
||||
Serial.print(", data: ");
|
||||
Serial.print("Data: ");
|
||||
char *buf = pdata->to_str();
|
||||
if (buf) {
|
||||
Serial.print(buf);
|
||||
|
@ -135,7 +130,14 @@ void loop() {
|
|||
}
|
||||
Serial.print("\n");
|
||||
output_timings(pdec, nb_bits);
|
||||
|
||||
#ifdef OUTPUT_FIRST_DECODED_ONLY
|
||||
pdec = nullptr;
|
||||
delay(1000);
|
||||
#else
|
||||
pdec = pdec->get_next();
|
||||
#endif
|
||||
|
||||
}
|
||||
delete pdec0;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
// 01_output-received-code.ino
|
||||
// 02_output-received-code.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Simply displays received codes
|
|
@ -1,4 +1,4 @@
|
|||
// 02_output-signal-timings.ino
|
||||
// 03_output-signal-timings.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Displays all signals details (incl. non-coding sequences) along with their
|
|
@ -1,4 +1,4 @@
|
|||
// 03_react_on_code.ino
|
||||
// 04_react_on_code.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Shows how to trigger different actions depending on code received.
|
|
@ -1,4 +1,4 @@
|
|||
// 04_callback.ino
|
||||
// 05_callback.ino
|
||||
|
||||
// Example sketch that comes along with RF433any library
|
||||
// Shows how to trigger different actions depending on code received, by
|
||||
|
@ -35,6 +35,9 @@ Track track(PIN_RFINPUT);
|
|||
|
||||
byte dummy;
|
||||
|
||||
void on_call_anycode(void *data) {
|
||||
}
|
||||
|
||||
void on_call(void *data) {
|
||||
byte n = (byte *)data - &dummy;
|
||||
Serial.print("Received code number ");
|
||||
|
@ -46,11 +49,11 @@ void setup() {
|
|||
pinMode(PIN_RFINPUT, INPUT);
|
||||
Serial.begin(115200);
|
||||
track.setopt_wait_free_433_before_calling_callbacks(true);
|
||||
track.register_callback(RF433ANY_ID_TRIBIT,
|
||||
new BitVector(32, 4, 0xb9, 0x35, 0x6d, 0x00),
|
||||
track.register_callback(RF433ANY_ID_TRIBIT_INV,
|
||||
new BitVector(12, 2, 0x04, 0xf0),
|
||||
(void *)(&dummy + 1), on_call, 2000);
|
||||
track.register_callback(RF433ANY_ID_TRIBIT,
|
||||
new BitVector(32, 4, 0xb5, 0x35, 0x6d, 0x00),
|
||||
track.register_callback(RF433ANY_ID_TRIBIT_INV,
|
||||
new BitVector(12, 2, 0x04, 0xf1),
|
||||
(void *)(&dummy + 2), on_call, 2000);
|
||||
}
|
||||
|
Loading…
Reference in New Issue