Skip to content

Commit 7facfde

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

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-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: 30 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};
@@ -162,6 +163,7 @@ impl Format {
162163
}
163164
}
164165

166+
#[derive(Debug)]
165167
#[repr(C)]
166168
pub struct PixFormat {
167169
pub width: u32,
@@ -188,6 +190,7 @@ impl PixFormat {
188190
}
189191
}
190192

193+
#[derive(Debug)]
191194
#[repr(C)]
192195
pub struct RequestBuffers {
193196
pub count: u32,
@@ -207,13 +210,16 @@ impl RequestBuffers {
207210
}
208211
}
209212

213+
#[derive(Derivative)]
214+
#[derivative(Debug)]
210215
#[repr(C)]
211216
pub struct Buffer {
212217
pub index: u32,
213218
pub btype: u32,
214219
pub bytesused: u32,
215220
pub flags: u32,
216221
pub field: u32,
222+
#[derivative(Debug="ignore")]
217223
pub timestamp: Timeval,
218224
pub timecode: TimeCode,
219225
pub sequence: u32,
@@ -233,6 +239,7 @@ impl Buffer {
233239
}
234240
}
235241

242+
#[derive(Debug)]
236243
#[repr(C)]
237244
pub struct TimeCode {
238245
pub ttype: u32,
@@ -244,6 +251,7 @@ pub struct TimeCode {
244251
pub userbits: [u8; 4],
245252
}
246253

254+
#[derive(Debug)]
247255
#[repr(C)]
248256
pub struct FmtDesc {
249257
pub index: u32,
@@ -262,10 +270,13 @@ impl FmtDesc {
262270
}
263271
}
264272

273+
#[derive(Derivative)]
274+
#[derivative(Debug)]
265275
#[repr(C)]
266276
pub struct StreamParm {
267277
pub ptype: u32,
268278
pub parm: CaptureParm,
279+
#[derivative(Debug="ignore")]
269280
space: [u8; 160],
270281
}
271282

@@ -279,6 +290,7 @@ impl StreamParm {
279290
}
280291
}
281292

293+
#[derive(Debug)]
282294
#[repr(C)]
283295
pub struct CaptureParm {
284296
pub capability: u32,
@@ -289,12 +301,14 @@ pub struct CaptureParm {
289301
reserved: [u32; 4],
290302
}
291303

304+
#[derive(Debug)]
292305
#[repr(C)]
293306
pub struct Fract {
294307
pub numerator: u32,
295308
pub denominator: u32,
296309
}
297310

311+
#[derive(Debug)]
298312
#[repr(C)]
299313
pub struct Frmsizeenum {
300314
pub index: u32,
@@ -320,12 +334,14 @@ impl Frmsizeenum {
320334
}
321335
}
322336

337+
#[derive(Debug)]
323338
#[repr(C)]
324339
pub struct FrmsizeDiscrete {
325340
pub width: u32,
326341
pub height: u32,
327342
}
328343

344+
#[derive(Debug)]
329345
#[repr(C)]
330346
pub struct FrmsizeStepwise {
331347
pub min_width: u32,
@@ -336,6 +352,7 @@ pub struct FrmsizeStepwise {
336352
pub step_height: u32,
337353
}
338354

355+
#[derive(Debug)]
339356
#[repr(C)]
340357
pub struct Frmivalenum {
341358
pub index: u32,
@@ -365,13 +382,15 @@ impl Frmivalenum {
365382
}
366383
}
367384

385+
#[derive(Debug)]
368386
#[repr(C)]
369387
pub struct FrmivalStepwise {
370388
pub min: Fract,
371389
pub max: Fract,
372390
pub step: Fract,
373391
}
374392

393+
#[derive(Debug)]
375394
#[repr(C)]
376395
pub struct QueryCtrl {
377396
pub id: u32,
@@ -393,6 +412,7 @@ impl QueryCtrl {
393412
}
394413
}
395414

415+
#[derive(Debug)]
396416
#[repr(C)]
397417
pub struct QueryExtCtrl {
398418
pub id: u32,
@@ -420,6 +440,7 @@ impl QueryExtCtrl {
420440
}
421441
}
422442

443+
#[derive(Debug)]
423444
#[repr(C, packed)]
424445
pub struct QueryMenu {
425446
pub id: u32,
@@ -434,6 +455,12 @@ pub union QueryMenuData {
434455
value: i64,
435456
}
436457

458+
impl fmt::Debug for QueryMenuData {
459+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
460+
write!(f, "{:?}", self.name())
461+
}
462+
}
463+
437464
impl QueryMenu {
438465
pub fn new(id: u32) -> QueryMenu {
439466
let mut menu: QueryMenu = unsafe { mem::zeroed() };
@@ -452,6 +479,7 @@ impl QueryMenuData {
452479
}
453480
}
454481

482+
#[derive(Debug)]
455483
#[repr(C)]
456484
pub struct Control {
457485
pub id: u32,
@@ -464,6 +492,7 @@ impl Control {
464492
}
465493
}
466494

495+
#[derive(Debug)]
467496
#[repr(C, packed)]
468497
pub struct ExtControl {
469498
pub id: u32,
@@ -483,6 +512,7 @@ impl ExtControl {
483512
}
484513
}
485514

515+
#[derive(Debug)]
486516
#[repr(C)]
487517
pub struct ExtControls<'a> {
488518
pub ctrl_class: u32,

0 commit comments

Comments
 (0)