pub struct Transmission {
pub sequence: String,
pub pulse_length: u16,
pub repeats: u8,
pub protocol: ProtocolProperties,
}Expand description
A transmission consists of a sequence of short and long radio pulses. The binary sequence is represented by a string of literal ‘0’ and ‘1’ characters. That way you can compose the signal simply by concatenating multiple strings.
The pulse length is the smallest time unit of the signal.
It will be multiplied by the respective values specified
in the ProtocolProperties struct. The pulse length is
given in microseconds. Usually, a lot of fine tuning is
required.
Usually, sending the signal once is not enough, so we need to specify the number of repeats.
Fields§
§sequence: String§pulse_length: u16§repeats: u8§protocol: ProtocolPropertiesImplementations§
Source§impl Transmission
impl Transmission
Sourcepub fn send_to(&self, gpio_dev: &str, gpio_pin: u8) -> Result<(), Error>
pub fn send_to(&self, gpio_dev: &str, gpio_pin: u8) -> Result<(), Error>
Output the signal on a gpio pin on the specified gpio device via the
gpio character device ABI.
Finding the right device can sometimes be a bit tricky.
Further information might be found in the documentation of your SBC.
On a Raspberry Pi 4B it is /dev/gpiochip0, but on a
Raspberry Pi 5 the appropiate device is /dev/gpiochip4.
gpio_pin is the number of the gpio pin the radio transmitter module,
e.g. an FS1000A module, is connected to.
The sequence is transmitted by iterating over the characters of a string slice. If the character is ‘1’ a binary one will be transmitted, or a binary zero if the character is ‘0’, respectively. All other characters will result in a sync bit.
§Examples
use libsparkypi::*;
let my_signal = Transmission::builder()
.sequence("s000000000000010101010001")
.pulse_length(320)
.repeats(10)
.protocol(P1)
.build();
// output on device /dev/gpiochip0, gpio pin 18
my_signal.send_to("/dev/gpiochip0", 18).unwrap();Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance with default values, e.g. all fields with numbers will be zero, and the string will be empty.
Sourcepub fn builder() -> TransmissionBuilder
pub fn builder() -> TransmissionBuilder
Invokes the builder.
Sourcepub fn csv_as_bytes(&self) -> Vec<u8> ⓘ
pub fn csv_as_bytes(&self) -> Vec<u8> ⓘ
Creates a byte vector containing the data from the transmission in the form of literal characters in the following comma separated pattern:
SEQUENCE,PULSE_LENGTH,REPEATS,SHORT,LONG,SYNC_BIT,SYNC_GAP
You can send those bytes e.g. via UART to an appropriately programmed microcontroller, which subsequently can parse the values, and transmit the binary sequence accordingly via a radio module. You can for example connect an Arduino Nano via USB to a regular x86 PC and make use of the serialport crate.
Trait Implementations§
Source§impl Clone for Transmission
impl Clone for Transmission
Source§fn clone(&self) -> Transmission
fn clone(&self) -> Transmission
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more