ESPHome  2024.11.1
LwTx.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
5 
6 #include <vector>
7 
8 namespace esphome {
9 namespace lightwaverf {
10 
11 // LxTx.h
12 //
13 // LightwaveRF 434MHz tx interface for Arduino
14 //
15 // Author: Bob Tidey (robert@tideys.net)
16 
17 // Include basic library header and set default TX pin
18 static const uint8_t TX_PIN_DEFAULT = 13;
19 
20 class LwTx {
21  public:
22  // Sets up basic parameters must be called at least once
23  void lwtx_setup(InternalGPIOPin *pin, uint8_t repeats, bool inverted, int u_sec);
24 
25  // Allows changing basic tick counts from their defaults
26  void lwtx_set_tick_counts(uint8_t low_count, uint8_t high_count, uint8_t trail_count, uint8_t gap_count);
27 
28  // Allws multiplying the gap period for creating very large gaps
29  void lwtx_set_gap_multiplier(uint8_t gap_multiplier);
30 
31  // determines whether incoming data or should be translated from nibble data
32  void lwtx_settranslate(bool txtranslate);
33 
34  // Checks whether tx is free to accept a new message
35  bool lwtx_free();
36 
37  // Basic send of new 10 char message, not normally needed if setaddr and cmd are used.
38  void lwtx_send(const std::vector<uint8_t> &msg);
39 
40  // Sets up 5 char address which will be used to form messages for lwtx_cmd
41  void lwtx_setaddr(const uint8_t *addr);
42 
43  // Send Command
44  void lwtx_cmd(uint8_t command, uint8_t parameter, uint8_t room, uint8_t device);
45 
46  // Allows changing basic tick counts from their defaults
47  void lw_timer_start();
48 
49  // Allws multiplying the gap period for creating very large gaps
50  void lw_timer_stop();
51 
52  // These set the pulse durationlws in ticks. ESP uses 330uSec base tick, else use 140uSec
53  uint8_t tx_low_count = 3; // total number of ticks in a low (990 uSec)
54  uint8_t tx_high_count = 2; // total number of ticks in a high (660 uSec)
55  uint8_t tx_trail_count = 1; // tick count to set line low (330 uSec)
56 
57  uint8_t tx_toggle_count = 3;
58 
59  static const uint8_t TX_MSGLEN = 10; // the expected length of the message
60 
61  // Transmit mode constants and variables
62  uint8_t tx_repeats = 12; // Number of repeats of message sent
63  uint8_t txon = 1;
64  uint8_t txoff = 0;
65  bool tx_msg_active = false; // set true to activate message sending
66  bool tx_translate = true; // Set false to send raw data
67 
68  uint8_t tx_buf[TX_MSGLEN]; // the message buffer during reception
69  uint8_t tx_repeat = 0; // counter for repeats
70  uint8_t tx_state = 0;
71  uint16_t tx_gap_repeat = 0; // unsigned int
72 
73  // Use with low repeat counts
74  uint8_t tx_gap_count = 33; // Inter-message gap count (10.9 msec)
75  uint32_t espPeriod = 0; // Holds interrupt timer0 period
76  uint32_t espNext = 0; // Holds interrupt next count
77 
78  // Gap multiplier byte is used to multiply gap if longer periods are needed for experimentation
79  // If gap is 255 (35msec) then this to give a max of 9 seconds
80  // Used with low repeat counts to find if device times out
81  uint8_t tx_gap_multiplier = 0; // Gap extension byte
82 
83  uint8_t tx_bit_mask = 0; // bit mask in current byte
84  uint8_t tx_num_bytes = 0; // number of bytes sent
85 
87 
88  protected:
89  uint32_t duty_on_;
90  uint32_t duty_off_;
91 };
92 
93 } // namespace lightwaverf
94 } // namespace esphome
uint8_t tx_trail_count
Definition: LwTx.h:55
static const uint8_t TX_MSGLEN
Definition: LwTx.h:59
void lwtx_settranslate(bool txtranslate)
Set translate mode.
Definition: LwTx.cpp:30
void lwtx_set_gap_multiplier(uint8_t gap_multiplier)
Definition: LwTx.cpp:186
void lwtx_set_tick_counts(uint8_t low_count, uint8_t high_count, uint8_t trail_count, uint8_t gap_count)
Definition: LwTx.cpp:179
uint8_t tx_gap_multiplier
Definition: LwTx.h:81
uint8_t tx_buf[TX_MSGLEN]
Definition: LwTx.h:68
void lwtx_setaddr(const uint8_t *addr)
Set 5 char address for future messages.
Definition: LwTx.cpp:126
uint8_t tx_toggle_count
Definition: LwTx.h:57
uint16_t tx_gap_repeat
Definition: LwTx.h:71
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void lwtx_cmd(uint8_t command, uint8_t parameter, uint8_t room, uint8_t device)
Send a LightwaveRF message (10 nibbles in bytes)
Definition: LwTx.cpp:135
void lwtx_setup(InternalGPIOPin *pin, uint8_t repeats, bool inverted, int u_sec)
Set things up to transmit LightWaveRF 434Mhz messages.
Definition: LwTx.cpp:149
InternalGPIOPin * tx_pin
Definition: LwTx.h:86
bool lwtx_free()
Check for send free.
Definition: LwTx.cpp:105
void lwtx_send(const std::vector< uint8_t > &msg)
Send a LightwaveRF message (10 nibbles in bytes)
Definition: LwTx.cpp:110