1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod capture;

use bytes::BytesMut;
use rusb::Context;

pub struct Cappy3ds<F> {
    data_callback: F,
    usb_context: Option<rusb::Context>,
    device_handle: Option<rusb::DeviceHandle<rusb::Context>>,
}

impl<F> Cappy3ds<F>
where
    F: FnMut(&[i16], BytesMut, BytesMut),
{
    pub fn new(data_callback: F) -> Self {
        Self {
            data_callback,
            usb_context: None,
            device_handle: None,
        }
    }

    pub fn connect(&mut self) {
        match Context::new() {
            Ok(mut context) => match capture::katsukitty::connect(&mut context) {
                Ok(handle) => {
                    self.device_handle = Some(handle);
                    self.usb_context = Some(context);
                }
                Err(err) => {
                    println!("{}", err);
                    todo!();
                }
            },
            Err(e) => {
                println!("could not initialize libusb: {}", e);
                todo!();
            }
        }
    }

    pub fn do_capture(self) {
        capture::katsukitty::do_capture(&mut self.device_handle.unwrap(), self.data_callback);
    }
}