OOKwiz
on/off-keying for ESP32 and a variety of supported radio modules
OOKwiz.h
Go to the documentation of this file.
1 #ifndef _OOKWIZ_H_
2 #define _OOKWIZ_H_
3 
4 #include <Arduino.h>
5 
6 #include "config.h"
7 #include "Radio.h"
8 #include "RawTimings.h"
9 #include "Pulsetrain.h"
10 #include "Meaning.h"
11 #include "Settings.h"
12 #include "Device.h"
13 #include "tools.h"
14 #include "serial_output.h"
15 
16 /**
17  * In the loop() handling of packets, we want to operate on sets of RawTimings
18  * and Pulsetrain.
19 */
20 typedef struct BufferPair {
23  void zap() {
24  raw.zap();
25  train.zap();
26  }
27 } BufferPair;
28 
29 /**
30  * In the loop() handling of packets, we want to operate on triplets of RawTimings,
31  * Pulsetrain and Meaning.
32 */
33 typedef struct BufferTriplet {
37  void zap() {
38  raw.zap();
39  train.zap();
40  meaning.zap();
41  }
42 } BufferTriplet;
43 
44 /**
45  * \brief The static functions in the OOKwiz class provide the main controls for OOKwiz' functionality.
46  * Prefix them with `OOKwiz::` to use them from your own code.
47  *
48  * Example use of functions from the OOKwiz class
49  * ```cpp
50  * void setup() {
51  * OOKwiz::setup();
52  * }
53  *
54  * void loop() {
55  * OOKwiz::loop();
56  * }
57  * ```
58 */
59 class OOKwiz {
60 
61 public:
62  static bool setup(bool skip_saved_defaults = false);
63  static bool loop();
64  static bool receive();
65  static bool onReceive(void (*callback_function)(RawTimings, Pulsetrain, Meaning));
66  static bool standby();
67  static bool simulate(String &str);
68  static bool simulate(RawTimings &raw);
69  static bool simulate(Pulsetrain &train);
70  static bool simulate(Meaning &meaning);
71  static bool transmit(String &str);
72  static bool transmit(RawTimings &raw);
73  static bool transmit(Pulsetrain &train);
74  static bool transmit(Meaning &meaning);
75 
76 private:
77  static volatile enum Rx_State{
78  RX_OFF,
79  RX_WAIT_PREAMBLE,
80  RX_RECEIVING_DATA,
81  RX_PROCESSING
82  } rx_state;
83  static bool serial_cli_disable;
84  static int first_pulse_min_len;
85  static int pulse_gap_min_len;
86  static int pulse_gap_len_new_packet;
87  static int min_nr_pulses;
88  static int max_nr_pulses;
89  static int noise_penalty;
90  static int noise_threshold;
91  static int noise_score;
92  static bool no_noise_fix;
93  static int lost_packets;
94  static int64_t last_transition;
95  static hw_timer_t *transitionTimer;
96  static int64_t repeat_time_start;
97  static long repeat_timeout;
98  static bool rx_active_high;
99  static bool tx_active_high;
100  static RawTimings isr_in;
101  static RawTimings isr_out;
102  static BufferPair loop_in;
103  static BufferPair loop_compare;
104  static BufferTriplet loop_ready;
105  static int64_t last_periodic;
106  static void (*callback)(RawTimings, Pulsetrain, Meaning);
107  static void IRAM_ATTR ISR_transition();
108  static void IRAM_ATTR ISR_transitionTimeout();
109  static void IRAM_ATTR process_raw();
110  static bool tryToBeNice(int ms);
111 
112 };
113 
114 #endif