Browse Source

Remove RefCell wrapping around cameras

pull/65/head
Steve Cook 2 years ago
parent
commit
a35a3e64df
  1. 10
      ctru-rs/examples/camera-image.rs
  2. 17
      ctru-rs/src/services/cam.rs

10
ctru-rs/examples/camera-image.rs

@ -28,9 +28,10 @@ fn main() {
println!("Initializing camera"); println!("Initializing camera");
let cam = Cam::init().expect("Failed to initialize CAM service."); let mut cam = Cam::init().expect("Failed to initialize CAM service.");
let mut camera = cam.outer_right_cam.borrow_mut(); {
let camera = &mut cam.outer_right_cam;
camera camera
.set_size(CamSize::CTR_TOP_LCD) .set_size(CamSize::CTR_TOP_LCD)
@ -53,7 +54,7 @@ fn main() {
camera camera
.set_trimming(false) .set_trimming(false)
.expect("Failed to disable trimming"); .expect("Failed to disable trimming");
}
let mut buf = vec![0u8; BUF_SIZE]; let mut buf = vec![0u8; BUF_SIZE];
println!("\nPress R to take a new picture"); println!("\nPress R to take a new picture");
@ -71,6 +72,9 @@ fn main() {
println!("Capturing new image"); println!("Capturing new image");
cam.play_shutter_sound(CamShutterSoundType::NORMAL) cam.play_shutter_sound(CamShutterSoundType::NORMAL)
.expect("Failed to play shutter sound"); .expect("Failed to play shutter sound");
let camera = &mut cam.outer_right_cam;
buf = camera buf = camera
.take_picture( .take_picture(
WIDTH.try_into().unwrap(), WIDTH.try_into().unwrap(),

17
ctru-rs/src/services/cam.rs

@ -1,15 +1,14 @@
use crate::services::gspgpu::FramebufferFormat; use crate::services::gspgpu::FramebufferFormat;
use bitflags::bitflags; use bitflags::bitflags;
use ctru_sys::Handle; use ctru_sys::Handle;
use std::cell::RefCell;
use std::time::Duration; use std::time::Duration;
#[non_exhaustive] #[non_exhaustive]
pub struct Cam { pub struct Cam {
pub inner_cam: RefCell<InwardCam>, pub inner_cam: InwardCam,
pub outer_right_cam: RefCell<OutwardRightCam>, pub outer_right_cam: OutwardRightCam,
pub outer_left_cam: RefCell<OutwardLeftCam>, pub outer_left_cam: OutwardLeftCam,
pub both_outer_cams: RefCell<BothOutwardCam>, pub both_outer_cams: BothOutwardCam,
} }
bitflags! { bitflags! {
@ -871,10 +870,10 @@ impl Cam {
Err(r.into()) Err(r.into())
} else { } else {
Ok(Cam { Ok(Cam {
inner_cam: RefCell::new(InwardCam), inner_cam: InwardCam,
outer_right_cam: RefCell::new(OutwardRightCam), outer_right_cam: OutwardRightCam,
outer_left_cam: RefCell::new(OutwardLeftCam), outer_left_cam: OutwardLeftCam,
both_outer_cams: RefCell::new(BothOutwardCam), both_outer_cams: BothOutwardCam,
}) })
} }
} }

Loading…
Cancel
Save