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