Skip to content

Commit e96c9b0

Browse files
Add debug in a ton of structs
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent b94d92d commit e96c9b0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "MIT OR Apache-2.0"
1010
readme = "README.md"
1111

1212
[dependencies]
13+
derivative = "1.0.3"
1314
libc = "0.2"
1415

1516
[features]

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub use v4l2::pubconsts as consts;
4949

5050
pub type Result<T> = result::Result<T, Error>;
5151

52+
#[macro_use]
53+
extern crate derivative;
54+
5255
#[derive(Debug)]
5356
pub enum Error {
5457
/// I/O error when using the camera.
@@ -103,6 +106,7 @@ impl From<io::Error> for Error {
103106
}
104107
}
105108

109+
#[derive(Debug)]
106110
pub struct Config<'a> {
107111
/// The mix of numerator and denominator. v4l2 uses frame intervals instead of frame rates.
108112
/// Default is `(1, 10)`.
@@ -245,6 +249,7 @@ impl fmt::Debug for IntervalInfo {
245249
}
246250
}
247251

252+
#[derive(Debug)]
248253
pub struct Frame {
249254
/// Width and height of the frame.
250255
pub resolution: (u32, u32),
@@ -699,6 +704,7 @@ impl Drop for Camera {
699704
}
700705
}
701706

707+
#[derive(Debug)]
702708
pub struct FormatIter<'a> {
703709
camera: &'a Camera,
704710
index: u32,
@@ -726,6 +732,7 @@ impl<'a> Iterator for FormatIter<'a> {
726732
}
727733
}
728734

735+
#[derive(Debug)]
729736
pub struct ControlIter<'a> {
730737
camera: &'a Camera,
731738
id: u32,

src/v4l2.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(clippy::unreadable_literal)]
22

33
use std::ffi::CString;
4+
use std::fmt;
45
use std::os::unix::io::RawFd;
56
use std::ptr::null_mut;
67
use std::{io, mem, usize};
@@ -132,12 +133,15 @@ pub fn mmap(length: usize, fd: RawFd, offset: usize) -> io::Result<MappedRegion>
132133
})
133134
}
134135

136+
#[derive(Derivative)]
137+
#[derivative(Debug)]
135138
#[repr(C)]
136139
pub struct Format {
137140
pub ftype: u32,
138141
#[cfg(target_pointer_width = "64")]
139142
padding: u32,
140143
pub fmt: PixFormat,
144+
#[derivative(Debug="ignore")]
141145
space: [u8; 156],
142146
}
143147

@@ -162,6 +166,7 @@ impl Format {
162166
}
163167
}
164168

169+
#[derive(Debug)]
165170
#[repr(C)]
166171
pub struct PixFormat {
167172
pub width: u32,
@@ -188,6 +193,7 @@ impl PixFormat {
188193
}
189194
}
190195

196+
#[derive(Debug)]
191197
#[repr(C)]
192198
pub struct RequestBuffers {
193199
pub count: u32,
@@ -207,13 +213,16 @@ impl RequestBuffers {
207213
}
208214
}
209215

216+
#[derive(Derivative)]
217+
#[derivative(Debug)]
210218
#[repr(C)]
211219
pub struct Buffer {
212220
pub index: u32,
213221
pub btype: u32,
214222
pub bytesused: u32,
215223
pub flags: u32,
216224
pub field: u32,
225+
#[derivative(Debug="ignore")]
217226
pub timestamp: Timeval,
218227
pub timecode: TimeCode,
219228
pub sequence: u32,
@@ -233,6 +242,7 @@ impl Buffer {
233242
}
234243
}
235244

245+
#[derive(Debug)]
236246
#[repr(C)]
237247
pub struct TimeCode {
238248
pub ttype: u32,
@@ -244,6 +254,7 @@ pub struct TimeCode {
244254
pub userbits: [u8; 4],
245255
}
246256

257+
#[derive(Debug)]
247258
#[repr(C)]
248259
pub struct FmtDesc {
249260
pub index: u32,
@@ -262,10 +273,13 @@ impl FmtDesc {
262273
}
263274
}
264275

276+
#[derive(Derivative)]
277+
#[derivative(Debug)]
265278
#[repr(C)]
266279
pub struct StreamParm {
267280
pub ptype: u32,
268281
pub parm: CaptureParm,
282+
#[derivative(Debug="ignore")]
269283
space: [u8; 160],
270284
}
271285

@@ -279,6 +293,7 @@ impl StreamParm {
279293
}
280294
}
281295

296+
#[derive(Debug)]
282297
#[repr(C)]
283298
pub struct CaptureParm {
284299
pub capability: u32,
@@ -289,12 +304,14 @@ pub struct CaptureParm {
289304
reserved: [u32; 4],
290305
}
291306

307+
#[derive(Debug)]
292308
#[repr(C)]
293309
pub struct Fract {
294310
pub numerator: u32,
295311
pub denominator: u32,
296312
}
297313

314+
#[derive(Debug)]
298315
#[repr(C)]
299316
pub struct Frmsizeenum {
300317
pub index: u32,
@@ -320,12 +337,14 @@ impl Frmsizeenum {
320337
}
321338
}
322339

340+
#[derive(Debug)]
323341
#[repr(C)]
324342
pub struct FrmsizeDiscrete {
325343
pub width: u32,
326344
pub height: u32,
327345
}
328346

347+
#[derive(Debug)]
329348
#[repr(C)]
330349
pub struct FrmsizeStepwise {
331350
pub min_width: u32,
@@ -336,6 +355,7 @@ pub struct FrmsizeStepwise {
336355
pub step_height: u32,
337356
}
338357

358+
#[derive(Debug)]
339359
#[repr(C)]
340360
pub struct Frmivalenum {
341361
pub index: u32,
@@ -365,13 +385,15 @@ impl Frmivalenum {
365385
}
366386
}
367387

388+
#[derive(Debug)]
368389
#[repr(C)]
369390
pub struct FrmivalStepwise {
370391
pub min: Fract,
371392
pub max: Fract,
372393
pub step: Fract,
373394
}
374395

396+
#[derive(Debug)]
375397
#[repr(C)]
376398
pub struct QueryCtrl {
377399
pub id: u32,
@@ -393,6 +415,7 @@ impl QueryCtrl {
393415
}
394416
}
395417

418+
#[derive(Debug)]
396419
#[repr(C)]
397420
pub struct QueryExtCtrl {
398421
pub id: u32,
@@ -420,6 +443,7 @@ impl QueryExtCtrl {
420443
}
421444
}
422445

446+
#[derive(Debug)]
423447
#[repr(C, packed)]
424448
pub struct QueryMenu {
425449
pub id: u32,
@@ -434,6 +458,12 @@ pub union QueryMenuData {
434458
value: i64,
435459
}
436460

461+
impl fmt::Debug for QueryMenuData {
462+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
463+
write!(f, "{:?}", self.name())
464+
}
465+
}
466+
437467
impl QueryMenu {
438468
pub fn new(id: u32) -> QueryMenu {
439469
let mut menu: QueryMenu = unsafe { mem::zeroed() };
@@ -452,6 +482,7 @@ impl QueryMenuData {
452482
}
453483
}
454484

485+
#[derive(Debug)]
455486
#[repr(C)]
456487
pub struct Control {
457488
pub id: u32,
@@ -464,6 +495,7 @@ impl Control {
464495
}
465496
}
466497

498+
#[derive(Debug)]
467499
#[repr(C, packed)]
468500
pub struct ExtControl {
469501
pub id: u32,
@@ -483,6 +515,7 @@ impl ExtControl {
483515
}
484516
}
485517

518+
#[derive(Debug)]
486519
#[repr(C)]
487520
pub struct ExtControls<'a> {
488521
pub ctrl_class: u32,

0 commit comments

Comments
 (0)