Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn v4l_page(_req: HttpRequest) -> impl Responder {
- let cameras_path = fs::read_dir("/dev/").unwrap()
- .filter(|f| f.as_ref().unwrap().file_name().to_str().unwrap().starts_with("video"))
- .map(|f| String::from(f.unwrap().path().clone().to_str().unwrap()))
- .collect::<Vec<_>>();
- println!("{:#?}", cameras_path);
- let mut main_json = json!({"cameras":{}});
- let cameras_json = &mut main_json["cameras"];
- 'camera_loop: for camera_path in cameras_path {
- println!("{:#?}", camera_path);
- let camera = Camera::new(&camera_path);
- if camera.is_err() {
- continue;
- }
- let camera = camera.unwrap();
- let mut controls = Vec::<serde_json::value::Value>::new();
- for i in camera.controls() {
- if i.is_err() {
- println!("Error: {:#?}", i);
- continue 'camera_loop;
- }
- let value = serde_json::to_value(i.unwrap());
- if value.is_err() {
- println!("Error with value: {:#?}", value);
- continue 'camera_loop;
- }
- controls.push(value.unwrap());
- }
- cameras_json[&camera_path]["controls"] = serde_json::to_value(controls).unwrap();
- let mut formats = Vec::<serde_json::value::Value>::new();
- for i in camera.formats() {
- if i.is_err() {
- println!("Error: {:#?}", i);
- continue 'camera_loop;
- }
- let format = i.unwrap();
- let value = serde_json::to_value(&format);
- if value.is_err() {
- println!("Error with value: {:#?}", value);
- continue 'camera_loop;
- }
- let mut value = value.unwrap();
- let get_fourcc = |i: &String| -> [u8; 4] {
- let mut array = [0; 4];
- array.copy_from_slice(&i.as_bytes()[0..4]);
- return array;
- };
- let fourcc = get_fourcc(&format.description);
- let resolutions = camera.resolutions(fourcc);
- if resolutions.is_err() {
- println!("Error with value: {:#?} for format {}", resolutions, &format.description);
- }
- let resolutions_interval = Vec::<serde_json::value::Value>::new();
- for resolution in &resolutions.into_iter() {
- //camera.intervals(fourcc, resolution.);
- println!("> {:#?} > {:#?}", &format.description, resolution);
- //resolutions_interval.push()
- }
- value["resolutions"] = serde_json::to_value(resolutions.unwrap()).unwrap();
- formats.push(value);
- }
- cameras_json[&camera_path]["formats"] = serde_json::to_value(formats).unwrap();
- }
- serde_json::to_string_pretty(&main_json)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement