@ -3,6 +3,7 @@
//! The CAM service provides access to the cameras. Cameras can return 2D images
//! The CAM service provides access to the cameras. Cameras can return 2D images
//! in the form of byte vectors which can be used for display or other usages.
//! in the form of byte vectors which can be used for display or other usages.
use crate ::error ::ResultCode ;
use crate ::services ::gspgpu ::FramebufferFormat ;
use crate ::services ::gspgpu ::FramebufferFormat ;
use bitflags ::bitflags ;
use bitflags ::bitflags ;
use ctru_sys ::Handle ;
use ctru_sys ::Handle ;
@ -267,28 +268,14 @@ impl BothOutwardCam {
brightness_synchronization : bool ,
brightness_synchronization : bool ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetBrightnessSynchronization ( brightness_synchronization ) ;
ResultCode ( ctru_sys ::CAMU_SetBrightnessSynchronization (
if r < 0 {
brightness_synchronization ,
Err ( r . into ( ) )
) ) ? ;
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
}
fn synchronize_vsync_timing ( & self ) -> crate ::Result < ( ) > {
unsafe {
let r =
ctru_sys ::CAMU_SynchronizeVsyncTiming ( ctru_sys ::SELECT_OUT1 , ctru_sys ::SELECT_OUT2 ) ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
}
}
}
}
impl Camera for BothOutwardCam {
impl Camera for BothOutwardCam {
fn camera_as_raw ( & self ) -> ctru_sys ::u32_ {
fn camera_as_raw ( & self ) -> ctru_sys ::u32_ {
ctru_sys ::SELECT_OUT1_OUT2
ctru_sys ::SELECT_OUT1_OUT2
@ -313,72 +300,55 @@ pub trait Camera {
fn is_busy ( & self ) -> crate ::Result < bool > {
fn is_busy ( & self ) -> crate ::Result < bool > {
unsafe {
unsafe {
let mut is_busy = false ;
let mut is_busy = false ;
let r = ctru_sys ::CAMU_IsBusy ( & mut is_busy , self . port_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_IsBusy ( & mut is_busy , self . port_as_raw ( ) ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( is_busy )
Ok ( is_busy )
}
}
}
}
}
/// Returns the maximum amount of transfer bytes based on the view size, trimming, and other
/// Returns the maximum amount of transfer bytes based on the view size, trimming, and other
/// modifications set to the camera
/// modifications set to the camera
fn get_transfer_bytes ( & self ) -> crate ::Result < u32 > {
fn get_transfer_bytes ( & self ) -> crate ::Result < u32 > {
unsafe {
unsafe {
let mut transfer_bytes = 0 ;
let mut transfer_bytes = 0 ;
let r = ctru_sys ::CAMU_GetTransferBytes ( & mut transfer_bytes , self . port_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_GetTransferBytes (
if r < 0 {
& mut transfer_bytes ,
Err ( r . into ( ) )
self . port_as_raw ( ) ,
} else {
) ) ? ;
Ok ( transfer_bytes )
Ok ( transfer_bytes )
}
}
}
}
}
/// Sets whether or not the camera should trim the image based on parameters set by
/// Sets whether or not the camera should trim the image based on parameters set by
/// [Camera::set_trimming_params]
/// [Camera::set_trimming_params]
fn set_trimming ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
fn set_trimming ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetTrimming ( self . port_as_raw ( ) , enabled ) ;
ResultCode ( ctru_sys ::CAMU_SetTrimming ( self . port_as_raw ( ) , enabled ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Returns whether or not trimming is currently enabled for the camera
/// Returns whether or not trimming is currently enabled for the camera
fn is_trimming_enabled ( & self ) -> crate ::Result < bool > {
fn is_trimming_enabled ( & self ) -> crate ::Result < bool > {
unsafe {
unsafe {
let mut trimming = false ;
let mut trimming = false ;
let r = ctru_sys ::CAMU_IsTrimming ( & mut trimming , self . port_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_IsTrimming ( & mut trimming , self . port_as_raw ( ) ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( trimming )
Ok ( trimming )
}
}
}
}
}
/// Sets trimming parameters based on coordinates specified inside a [CamTrimmingParams]
/// Sets trimming parameters based on coordinates specified inside a [CamTrimmingParams]
fn set_trimming_params ( & mut self , params : CamTrimmingParams ) -> crate ::Result < ( ) > {
fn set_trimming_params ( & mut self , params : CamTrimmingParams ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetTrimmingParams (
ResultCode ( ctru_sys ::CAMU_SetTrimmingParams (
self . port_as_raw ( ) ,
self . port_as_raw ( ) ,
params . x_start ,
params . x_start ,
params . y_start ,
params . y_start ,
params . x_end ,
params . x_end ,
params . y_end ,
params . y_end ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Returns the set [CamTrimmingParams] from the camera
/// Returns the set [CamTrimmingParams] from the camera
fn get_trimming_params ( & self ) -> crate ::Result < CamTrimmingParams > {
fn get_trimming_params ( & self ) -> crate ::Result < CamTrimmingParams > {
@ -387,16 +357,14 @@ pub trait Camera {
let mut y_start = 0 ;
let mut y_start = 0 ;
let mut x_end = 0 ;
let mut x_end = 0 ;
let mut y_end = 0 ;
let mut y_end = 0 ;
let r = ctru_sys ::CAMU_GetTrimmingParams (
ResultCode ( ctru_sys ::CAMU_GetTrimmingParams (
& mut x_start ,
& mut x_start ,
& mut y_start ,
& mut y_start ,
& mut x_end ,
& mut x_end ,
& mut y_end ,
& mut y_end ,
self . port_as_raw ( ) ,
self . port_as_raw ( ) ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( CamTrimmingParams {
Ok ( CamTrimmingParams {
x_start ,
x_start ,
y_start ,
y_start ,
@ -405,7 +373,6 @@ pub trait Camera {
} )
} )
}
}
}
}
}
/// Sets the trimming parameters revolving around the center of the image.
/// Sets the trimming parameters revolving around the center of the image.
/// The new width will be `trim_width / 2` to the left and right of the center.
/// The new width will be `trim_width / 2` to the left and right of the center.
@ -418,44 +385,35 @@ pub trait Camera {
cam_height : i16 ,
cam_height : i16 ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetTrimmingParamsCenter (
ResultCode ( ctru_sys ::CAMU_SetTrimmingParamsCenter (
self . port_as_raw ( ) ,
self . port_as_raw ( ) ,
trim_width ,
trim_width ,
trim_height ,
trim_height ,
cam_width ,
cam_width ,
cam_height ,
cam_height ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the exposure level of the camera
/// Sets the exposure level of the camera
fn set_exposure ( & mut self , exposure : i8 ) -> crate ::Result < ( ) > {
fn set_exposure ( & mut self , exposure : i8 ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetExposure ( self . camera_as_raw ( ) , exposure ) ;
ResultCode ( ctru_sys ::CAMU_SetExposure ( self . camera_as_raw ( ) , exposure ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the white balance mod of the camera based on the passed [CamWhiteBalance] argument
/// Sets the white balance mod of the camera based on the passed [CamWhiteBalance] argument
fn set_white_balance ( & mut self , white_balance : CamWhiteBalance ) -> crate ::Result < ( ) > {
fn set_white_balance ( & mut self , white_balance : CamWhiteBalance ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetWhiteBalance ( self . camera_as_raw ( ) , white_balance . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetWhiteBalance (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
white_balance . bits ( ) ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the white balance mode of the camera based on the passed [CamWhiteBalance] argument
/// Sets the white balance mode of the camera based on the passed [CamWhiteBalance] argument
// TODO: Explain base up
// TODO: Explain base up
@ -464,92 +422,79 @@ pub trait Camera {
white_balance : CamWhiteBalance ,
white_balance : CamWhiteBalance ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetWhiteBalanceWithoutBaseUp (
ResultCode ( ctru_sys ::CAMU_SetWhiteBalanceWithoutBaseUp (
self . camera_as_raw ( ) ,
self . camera_as_raw ( ) ,
white_balance . bits ( ) ,
white_balance . bits ( ) ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the sharpness of the camera
/// Sets the sharpness of the camera
fn set_sharpness ( & mut self , sharpness : i8 ) -> crate ::Result < ( ) > {
fn set_sharpness ( & mut self , sharpness : i8 ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetSharpness ( self . camera_as_raw ( ) , sharpness ) ;
ResultCode ( ctru_sys ::CAMU_SetSharpness ( self . camera_as_raw ( ) , sharpness ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets whether auto exposure is enabled or disabled for the camera
/// Sets whether auto exposure is enabled or disabled for the camera
fn set_auto_exposure ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
fn set_auto_exposure ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetAutoExposure ( self . camera_as_raw ( ) , enabled ) ;
ResultCode ( ctru_sys ::CAMU_SetAutoExposure (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
enabled ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Returns true if auto exposure is enabled for the camera
/// Returns true if auto exposure is enabled for the camera
fn is_auto_exposure_enabled ( & self ) -> crate ::Result < bool > {
fn is_auto_exposure_enabled ( & self ) -> crate ::Result < bool > {
unsafe {
unsafe {
let mut enabled = false ;
let mut enabled = false ;
let r = ctru_sys ::CAMU_IsAutoExposure ( & mut enabled , self . camera_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_IsAutoExposure (
if r < 0 {
& mut enabled ,
Err ( r . into ( ) )
self . camera_as_raw ( ) ,
} else {
) ) ? ;
Ok ( enabled )
Ok ( enabled )
}
}
}
}
}
/// Sets whether auto white balance is enabled or disabled for the camera
/// Sets whether auto white balance is enabled or disabled for the camera
fn set_auto_white_balance ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
fn set_auto_white_balance ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetAutoWhiteBalance ( self . camera_as_raw ( ) , enabled ) ;
ResultCode ( ctru_sys ::CAMU_SetAutoWhiteBalance (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
enabled ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Returns true if auto white balance is enabled for the camera
/// Returns true if auto white balance is enabled for the camera
fn is_auto_white_balance_enabled ( & self ) -> crate ::Result < bool > {
fn is_auto_white_balance_enabled ( & self ) -> crate ::Result < bool > {
unsafe {
unsafe {
let mut enabled = false ;
let mut enabled = false ;
let r = ctru_sys ::CAMU_IsAutoWhiteBalance ( & mut enabled , self . camera_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_IsAutoWhiteBalance (
if r < 0 {
& mut enabled ,
Err ( r . into ( ) )
self . camera_as_raw ( ) ,
} else {
) ) ? ;
Ok ( enabled )
Ok ( enabled )
}
}
}
}
}
/// Sets the flip direction of the camera's image based on the passed [CamFlip] argument
/// Sets the flip direction of the camera's image based on the passed [CamFlip] argument
fn flip_image ( & mut self , flip : CamFlip ) -> crate ::Result < ( ) > {
fn flip_image ( & mut self , flip : CamFlip ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r =
ResultCode ( ctru_sys ::CAMU_FlipImage (
ctru_sys ::CAMU_FlipImage ( self . camera_as_raw ( ) , flip . bits ( ) , ctru_sys ::CONTEXT_A ) ;
self . camera_as_raw ( ) ,
if r < 0 {
flip . bits ( ) ,
Err ( r . into ( ) )
ctru_sys ::CONTEXT_A ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the image resolution of the camera in detail
/// Sets the image resolution of the camera in detail
///
///
@ -571,7 +516,7 @@ pub trait Camera {
crop_1 : ( i16 , i16 ) ,
crop_1 : ( i16 , i16 ) ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetDetailSize (
ResultCode ( ctru_sys ::CAMU_SetDetailSize (
self . camera_as_raw ( ) ,
self . camera_as_raw ( ) ,
width ,
width ,
height ,
height ,
@ -580,105 +525,92 @@ pub trait Camera {
crop_1 . 0 ,
crop_1 . 0 ,
crop_1 . 1 ,
crop_1 . 1 ,
ctru_sys ::CONTEXT_A ,
ctru_sys ::CONTEXT_A ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the view size of the camera based on the passed [CamSize] argument.
/// Sets the view size of the camera based on the passed [CamSize] argument.
fn set_view_size ( & mut self , size : CamSize ) -> crate ::Result < ( ) > {
fn set_view_size ( & mut self , size : CamSize ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetSize ( self . camera_as_raw ( ) , size . bits ( ) , ctru_sys ::CONTEXT_A ) ;
ResultCode ( ctru_sys ::CAMU_SetSize (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
size . bits ( ) ,
} else {
ctru_sys ::CONTEXT_A ,
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the frame rate of the camera based on the passed [CamFrameRate] argument.
/// Sets the frame rate of the camera based on the passed [CamFrameRate] argument.
fn set_frame_rate ( & mut self , frame_rate : CamFrameRate ) -> crate ::Result < ( ) > {
fn set_frame_rate ( & mut self , frame_rate : CamFrameRate ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetFrameRate ( self . camera_as_raw ( ) , frame_rate . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetFrameRate (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
frame_rate . bits ( ) ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the photo mode of the camera based on the passed [CamPhotoMode] argument.
/// Sets the photo mode of the camera based on the passed [CamPhotoMode] argument.
fn set_photo_mode ( & mut self , photo_mode : CamPhotoMode ) -> crate ::Result < ( ) > {
fn set_photo_mode ( & mut self , photo_mode : CamPhotoMode ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetPhotoMode ( self . camera_as_raw ( ) , photo_mode . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetPhotoMode (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
photo_mode . bits ( ) ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the effect of the camera based on the passed [CamEffect] argument.
/// Sets the effect of the camera based on the passed [CamEffect] argument.
///
///
/// Multiple effects can be set at once by combining the bitflags of [CamEffect]
/// Multiple effects can be set at once by combining the bitflags of [CamEffect]
fn set_effect ( & mut self , effect : CamEffect ) -> crate ::Result < ( ) > {
fn set_effect ( & mut self , effect : CamEffect ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r =
ResultCode ( ctru_sys ::CAMU_SetEffect (
ctru_sys ::CAMU_SetEffect ( self . camera_as_raw ( ) , effect . bits ( ) , ctru_sys ::CONTEXT_A ) ;
self . camera_as_raw ( ) ,
if r < 0 {
effect . bits ( ) ,
Err ( r . into ( ) )
ctru_sys ::CONTEXT_A ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the contrast of the camera based on the passed [CamContrast] argument.
/// Sets the contrast of the camera based on the passed [CamContrast] argument.
fn set_contrast ( & mut self , contrast : CamContrast ) -> crate ::Result < ( ) > {
fn set_contrast ( & mut self , contrast : CamContrast ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetContrast ( self . camera_as_raw ( ) , contrast . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetContrast (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
contrast . bits ( ) ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the lens correction of the camera based on the passed [CamLensCorrection] argument.
/// Sets the lens correction of the camera based on the passed [CamLensCorrection] argument.
fn set_lens_correction ( & mut self , lens_correction : CamLensCorrection ) -> crate ::Result < ( ) > {
fn set_lens_correction ( & mut self , lens_correction : CamLensCorrection ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetLensCorrection ( self . camera_as_raw ( ) , lens_correction . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetLensCorrection (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
lens_correction . bits ( ) ,
} else {
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the output format of the camera based on the passed [CamOutputFormat] argument.
/// Sets the output format of the camera based on the passed [CamOutputFormat] argument.
fn set_output_format ( & mut self , format : CamOutputFormat ) -> crate ::Result < ( ) > {
fn set_output_format ( & mut self , format : CamOutputFormat ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetOutputFormat (
ResultCode ( ctru_sys ::CAMU_SetOutputFormat (
self . camera_as_raw ( ) ,
self . camera_as_raw ( ) ,
format . bits ( ) ,
format . bits ( ) ,
ctru_sys ::CONTEXT_A ,
ctru_sys ::CONTEXT_A ,
) ;
) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the region in which auto exposure should be based on.
/// Sets the region in which auto exposure should be based on.
///
///
@ -696,14 +628,16 @@ pub trait Camera {
height : i16 ,
height : i16 ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetAutoExposureWindow ( self . camera_as_raw ( ) , x , y , width , height ) ;
ResultCode ( ctru_sys ::CAMU_SetAutoExposureWindow (
if r < 0 {
self . camera_as_raw ( ) ,
Err ( r . into ( ) )
x ,
} else {
y ,
width ,
height ,
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the region in which auto white balance should be based on.
/// Sets the region in which auto white balance should be based on.
///
///
@ -721,27 +655,24 @@ pub trait Camera {
height : i16 ,
height : i16 ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r =
ResultCode ( ctru_sys ::CAMU_SetAutoWhiteBalanceWindow (
ctru_sys ::CAMU_SetAutoWhiteBalanceWindow ( self . camera_as_raw ( ) , x , y , width , height ) ;
self . camera_as_raw ( ) ,
if r < 0 {
x ,
Err ( r . into ( ) )
y ,
} else {
width ,
height ,
) ) ? ;
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets whether the noise filter should be enabled or disabled for the camera
/// Sets whether the noise filter should be enabled or disabled for the camera
fn set_noise_filter ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
fn set_noise_filter ( & mut self , enabled : bool ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetNoiseFilter ( self . camera_as_raw ( ) , enabled ) ;
ResultCode ( ctru_sys ::CAMU_SetNoiseFilter ( self . camera_as_raw ( ) , enabled ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Sets the image quality calibration data for the camera based on the passed in
/// Sets the image quality calibration data for the camera based on the passed in
/// [ImageQualityCalibrationData] argument
/// [ImageQualityCalibrationData] argument
@ -750,40 +681,28 @@ pub trait Camera {
data : ImageQualityCalibrationData ,
data : ImageQualityCalibrationData ,
) -> crate ::Result < ( ) > {
) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetImageQualityCalibrationData ( data . 0 ) ;
ResultCode ( ctru_sys ::CAMU_SetImageQualityCalibrationData ( data . 0 ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Returns the current [ImageQualityCalibrationData] for the camera
/// Returns the current [ImageQualityCalibrationData] for the camera
fn get_image_quality_calibration_data ( & self ) -> crate ::Result < ImageQualityCalibrationData > {
fn get_image_quality_calibration_data ( & self ) -> crate ::Result < ImageQualityCalibrationData > {
unsafe {
unsafe {
let mut data = ImageQualityCalibrationData ::default ( ) ;
let mut data = ImageQualityCalibrationData ::default ( ) ;
let r = ctru_sys ::CAMU_GetImageQualityCalibrationData ( & mut data . 0 ) ;
ResultCode ( ctru_sys ::CAMU_GetImageQualityCalibrationData ( & mut data . 0 ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( data )
Ok ( data )
}
}
}
}
}
/// Sets the camera as the current sleep camera
/// Sets the camera as the current sleep camera
// TODO: Explain sleep camera
// TODO: Explain sleep camera
fn set_sleep_camera ( & mut self ) -> crate ::Result < ( ) > {
fn set_sleep_camera ( & mut self ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetSleepCamera ( self . camera_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_SetSleepCamera ( self . camera_as_raw ( ) ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
/// Requests the camera to take a picture and returns a vector containing the image bytes.
/// Requests the camera to take a picture and returns a vector containing the image bytes.
///
///
@ -804,12 +723,12 @@ pub trait Camera {
) -> crate ::Result < Vec < u8 > > {
) -> crate ::Result < Vec < u8 > > {
let transfer_unit = unsafe {
let transfer_unit = unsafe {
let mut buf_size = 0 ;
let mut buf_size = 0 ;
let r = ctru_sys ::CAMU_GetMaxBytes ( & mut buf_size , width as i16 , height as i16 ) ;
ResultCode ( ctru_sys ::CAMU_GetMaxBytes (
if r < 0 {
& mut buf_size ,
Err ( crate ::Error ::from ( r ) )
width as i16 ,
} else {
height as i16 ,
Ok ( buf_size )
) ) ? ;
}
Ok ::< u32 , i32 > ( buf_size )
} ? ;
} ? ;
let screen_size = u32 ::from ( width ) * u32 ::from ( width ) * 2 ;
let screen_size = u32 ::from ( width ) * u32 ::from ( width ) * 2 ;
@ -817,83 +736,40 @@ pub trait Camera {
let mut buf = vec! [ 0 u8 ; usize ::try_from ( screen_size ) . unwrap ( ) ] ;
let mut buf = vec! [ 0 u8 ; usize ::try_from ( screen_size ) . unwrap ( ) ] ;
unsafe {
unsafe {
let r = ctru_sys ::CAMU_SetTransferBytes (
ResultCode ( ctru_sys ::CAMU_SetTransferBytes (
self . port_as_raw ( ) ,
self . port_as_raw ( ) ,
transfer_unit ,
transfer_unit ,
width as i16 ,
width as i16 ,
height as i16 ,
height as i16 ,
) ;
) ) ? ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
} ;
unsafe {
unsafe {
let r = ctru_sys ::CAMU_Activate ( self . camera_as_raw ( ) ) ;
ResultCode ( ctru_sys ::CAMU_Activate ( self . camera_as_raw ( ) ) ) ? ;
if r < 0 {
ResultCode ( ctru_sys ::CAMU_ClearBuffer ( self . port_as_raw ( ) ) ) ? ;
return Err ( r . into ( ) ) ;
ResultCode ( ctru_sys ::CAMU_StartCapture ( self . port_as_raw ( ) ) ) ? ;
}
} ;
unsafe {
let r = ctru_sys ::CAMU_ClearBuffer ( self . port_as_raw ( ) ) ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
unsafe {
let r = ctru_sys ::CAMU_StartCapture ( self . port_as_raw ( ) ) ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
} ;
let receive_event = unsafe {
let receive_event = unsafe {
let mut completion_handle : Handle = 0 ;
let mut completion_handle : Handle = 0 ;
let r = ctru_sys ::CAMU_SetReceiving (
ResultCode ( ctru_sys ::CAMU_SetReceiving (
& mut completion_handle ,
& mut completion_handle ,
buf . as_mut_ptr ( ) as * mut ::libc ::c_void ,
buf . as_mut_ptr ( ) as * mut ::libc ::c_void ,
self . port_as_raw ( ) ,
self . port_as_raw ( ) ,
screen_size ,
screen_size ,
transfer_unit . try_into ( ) . unwrap ( ) ,
transfer_unit . try_into ( ) . unwrap ( ) ,
) ;
) ) ? ;
if r < 0 {
Ok ::< Handle , i32 > ( completion_handle )
Err ( crate ::Error ::from ( r ) )
} else {
Ok ( completion_handle )
}
} ? ;
} ? ;
unsafe {
unsafe {
let r = ctru_sys ::svcWaitSynchronization (
ResultCode ( ctru_sys ::svcWaitSynchronization (
receive_event ,
receive_event ,
timeout . as_nanos ( ) . try_into ( ) . unwrap ( ) ,
timeout . as_nanos ( ) . try_into ( ) . unwrap ( ) ,
) ;
) ) ? ;
if r < 0 {
ResultCode ( ctru_sys ::CAMU_StopCapture ( self . port_as_raw ( ) ) ) ? ;
return Err ( r . into ( ) ) ;
ResultCode ( ctru_sys ::svcCloseHandle ( receive_event ) ) ? ;
}
ResultCode ( ctru_sys ::CAMU_Activate ( ctru_sys ::SELECT_NONE ) ) ? ;
} ;
unsafe {
let r = ctru_sys ::CAMU_StopCapture ( self . port_as_raw ( ) ) ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
unsafe {
let r = ctru_sys ::svcCloseHandle ( receive_event ) ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
unsafe {
let r = ctru_sys ::CAMU_Activate ( ctru_sys ::SELECT_NONE ) ;
if r < 0 {
return Err ( r . into ( ) ) ;
}
} ;
} ;
Ok ( buf )
Ok ( buf )
@ -910,10 +786,7 @@ impl Cam {
/// rare in practice.
/// rare in practice.
pub fn init ( ) -> crate ::Result < Cam > {
pub fn init ( ) -> crate ::Result < Cam > {
unsafe {
unsafe {
let r = ctru_sys ::camInit ( ) ;
ResultCode ( ctru_sys ::camInit ( ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( Cam {
Ok ( Cam {
inner_cam : InwardCam ,
inner_cam : InwardCam ,
outer_right_cam : OutwardRightCam ,
outer_right_cam : OutwardRightCam ,
@ -922,20 +795,15 @@ impl Cam {
} )
} )
}
}
}
}
}
/// Plays the specified sound based on the [CamShutterSoundType] argument
/// Plays the specified sound based on the [CamShutterSoundType] argument
pub fn play_shutter_sound ( & self , sound : CamShutterSoundType ) -> crate ::Result < ( ) > {
pub fn play_shutter_sound ( & self , sound : CamShutterSoundType ) -> crate ::Result < ( ) > {
unsafe {
unsafe {
let r = ctru_sys ::CAMU_PlayShutterSound ( sound . bits ( ) ) ;
ResultCode ( ctru_sys ::CAMU_PlayShutterSound ( sound . bits ( ) ) ) ? ;
if r < 0 {
Err ( r . into ( ) )
} else {
Ok ( ( ) )
Ok ( ( ) )
}
}
}
}
}
}
}
impl Drop for Cam {
impl Drop for Cam {
fn drop ( & mut self ) {
fn drop ( & mut self ) {