diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 03ae2da..c65d6b1 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -28,32 +28,33 @@ fn main() { println!("Initializing camera"); - let cam = Cam::init().expect("Failed to initialize CAM service."); - - let mut camera = cam.outer_right_cam.borrow_mut(); - - camera - .set_size(CamSize::CTR_TOP_LCD) - .expect("Failed to set camera size"); - - camera - .set_output_format(CamOutputFormat::RGB_565) - .expect("Failed to set camera output format"); - - camera - .set_noise_filter(true) - .expect("Failed to enable noise filter"); - camera - .set_auto_exposure(true) - .expect("Failed to enable auto exposure"); - camera - .set_auto_white_balance(true) - .expect("Failed to enable auto white balance"); - - camera - .set_trimming(false) - .expect("Failed to disable trimming"); - + let mut cam = Cam::init().expect("Failed to initialize CAM service."); + + { + let camera = &mut cam.outer_right_cam; + + camera + .set_size(CamSize::CTR_TOP_LCD) + .expect("Failed to set camera size"); + + camera + .set_output_format(CamOutputFormat::RGB_565) + .expect("Failed to set camera output format"); + + camera + .set_noise_filter(true) + .expect("Failed to enable noise filter"); + camera + .set_auto_exposure(true) + .expect("Failed to enable auto exposure"); + camera + .set_auto_white_balance(true) + .expect("Failed to enable auto white balance"); + + camera + .set_trimming(false) + .expect("Failed to disable trimming"); + } let mut buf = vec![0u8; BUF_SIZE]; println!("\nPress R to take a new picture"); @@ -71,6 +72,9 @@ fn main() { println!("Capturing new image"); cam.play_shutter_sound(CamShutterSoundType::NORMAL) .expect("Failed to play shutter sound"); + + let camera = &mut cam.outer_right_cam; + buf = camera .take_picture( WIDTH.try_into().unwrap(), diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 0a4d799..42f2a42 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -1,15 +1,14 @@ use crate::services::gspgpu::FramebufferFormat; use bitflags::bitflags; use ctru_sys::Handle; -use std::cell::RefCell; use std::time::Duration; #[non_exhaustive] pub struct Cam { - pub inner_cam: RefCell, - pub outer_right_cam: RefCell, - pub outer_left_cam: RefCell, - pub both_outer_cams: RefCell, + pub inner_cam: InwardCam, + pub outer_right_cam: OutwardRightCam, + pub outer_left_cam: OutwardLeftCam, + pub both_outer_cams: BothOutwardCam, } bitflags! { @@ -871,10 +870,10 @@ impl Cam { Err(r.into()) } else { Ok(Cam { - inner_cam: RefCell::new(InwardCam), - outer_right_cam: RefCell::new(OutwardRightCam), - outer_left_cam: RefCell::new(OutwardLeftCam), - both_outer_cams: RefCell::new(BothOutwardCam), + inner_cam: InwardCam, + outer_right_cam: OutwardRightCam, + outer_left_cam: OutwardLeftCam, + both_outer_cams: BothOutwardCam, }) } }