Skip to content

Commit 8568746

Browse files
committed
Add quiet/high speed mode
1 parent b215080 commit 8568746

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

dim.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
0b00000001,
1313
]
1414

15+
sys.stdout.buffer.write(b'.q.c.s')
1516
while True:
1617
for pattern in patterns:
1718
#sys.stdout.buffer.write(b'.c')

src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const HELP_MESSAGE: &str = "
2121
.s - strobe active row\r
2222
.c - clear active row\r
2323
.i - toggle instant strobe\r
24+
.q - set quiet (high speed) mode\r
2425
\r
2526
anything else will be interpreted as data to active row\r
2627
use '..' to enter a literal '.'-byte as data\r
@@ -80,6 +81,7 @@ fn main() -> ! {
8081
const CLEAR: u8 = 'c' as u8;
8182
const HELP: u8 = 'h' as u8;
8283
const INSTANT: u8 = 'i' as u8;
84+
const QUIET: u8 = 'q' as u8;
8385

8486
let mut command_mode = false;
8587
let mut active_row = Row0;
@@ -139,6 +141,10 @@ fn main() -> ! {
139141
}
140142
command_mode = false;
141143
},
144+
(true, QUIET, _) => {
145+
usb_serial.set_quiet(true);
146+
command_mode = false;
147+
},
142148
(true, _, _) => {
143149
usb_serial.write_str("Invalid command character\r\n");
144150
command_mode = false;

src/usb.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl UsbBus {
4848
pub struct UsbSerial<'a> {
4949
dev: UsbDevice<'a, usb::UsbBus<usb::Peripheral>>,
5050
serial: SerialPort<'a, usb::UsbBus<usb::Peripheral>>,
51+
quiet_mode: bool,
5152
}
5253

5354
impl<'a> UsbSerial<'a> {
@@ -67,6 +68,7 @@ impl<'a> UsbSerial<'a> {
6768
UsbSerial {
6869
dev: usb_dev,
6970
serial: usb_serial,
71+
quiet_mode: false,
7072
}
7173
}
7274

@@ -80,13 +82,16 @@ impl<'a> UsbSerial<'a> {
8082
}
8183

8284
pub fn write(&mut self, buf: &[u8]) -> usize {
83-
loop {
84-
let result = self.serial.write(buf);
85-
if let Ok(count) = result {
86-
return count;
85+
if self.quiet_mode {
86+
return buf.len();
87+
} else {
88+
loop {
89+
let result = self.serial.write(buf);
90+
if let Ok(count) = result {
91+
return count;
92+
}
8793
}
8894
}
89-
9095
}
9196

9297
pub fn write_str(&mut self, message: &str) -> usize {
@@ -108,5 +113,9 @@ impl<'a> UsbSerial<'a> {
108113
return bytes_written
109114

110115
}
116+
117+
pub fn set_quiet(&mut self, quiet_mode: bool) {
118+
self.quiet_mode = quiet_mode;
119+
}
111120
}
112121

0 commit comments

Comments
 (0)