]>
code.octet-stream.net Git - m17rt/blob - m17app/src/serial.rs
1 use serialport
::SerialPort
;
3 use crate::soundmodem
::Ptt
;
5 /// The pin on the serial port which is driving PTT
9 // Data Terminal ready (DTR)
13 pub struct SerialPtt
{
14 port
: Box
<dyn SerialPort
>,
19 pub fn available_ports() -> impl Iterator
<Item
= String
> {
20 serialport
::available_ports()
21 .unwrap
_or
_else
(|_
| vec
![])
26 pub fn new(port_name
: &str, pin
: PttPin
) -> Self {
27 // TODO: error handling
28 let port
= serialport
::new(port_name
, 9600).open().unwrap
();
33 impl Ptt
for SerialPtt
{
34 fn ptt_on(&mut self) {
35 let _
= match self.pin
{
36 PttPin
::Rts
=> self.port
.write_request_to_send(true),
37 PttPin
::Dtr
=> self.port
.write_data_terminal_ready(true),
41 fn ptt_off(&mut self) {
42 let _
= match self.pin
{
43 PttPin
::Rts
=> self.port
.write_request_to_send(false),
44 PttPin
::Dtr
=> self.port
.write_data_terminal_ready(false),