Browse Source

CAM renaming/fixing with build problems

pull/107/head
Andrea Ciliberti 2 years ago
parent
commit
7688644fe1
  1. 292
      ctru-rs/src/services/cam.rs

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

@ -1,11 +1,10 @@
//! CAM service //! Camera service
//! //!
//! The CAM service provides access to the cameras. Cameras can return 2D images //! The CAM service provides access to the cameras. Cameras can return 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 displayed or used in other ways.
use crate::error::{Error, ResultCode}; use crate::error::{Error, ResultCode};
use crate::services::gspgpu::FramebufferFormat; use crate::services::gspgpu::FramebufferFormat;
use bitflags::bitflags;
use ctru_sys::Handle; use ctru_sys::Handle;
use std::time::Duration; use std::time::Duration;
@ -21,177 +20,154 @@ pub struct Cam {
pub both_outer_cams: BothOutwardCam, pub both_outer_cams: BothOutwardCam,
} }
bitflags! { /// Flag to pass to [Camera::flip_image]
/// A set of flags to be passed to [Camera::flip_image]
#[derive(Default)] #[derive(Default)]
pub struct CamFlip: u32 { #[repr(u32)]
const NONE = ctru_sys::FLIP_NONE; pub enum FlipMode {
const HORIZONTAL = ctru_sys::FLIP_HORIZONTAL; None = ctru_sys::FLIP_NONE,
const VERTICAL = ctru_sys::FLIP_VERTICAL; Horizontal = ctru_sys::FLIP_HORIZONTAL,
const REVERSE = ctru_sys::FLIP_REVERSE; Vertical = ctru_sys::FLIP_VERTICAL,
} Reverse = ctru_sys::FLIP_REVERSE,
} }
bitflags! { /// Flag to pass to [Camera::set_view_size]
/// A set of flags to be passed to [Camera::set_view_size] #[repr(u32)]
#[derive(Default)] pub enum PictureSize {
pub struct CamSize: u32 { Vga = ctru_sys::SIZE_VGA,
const VGA = ctru_sys::SIZE_VGA; QVga = ctru_sys::SIZE_QVGA,
const QVGA = ctru_sys::SIZE_QVGA; QQVga = ctru_sys::SIZE_QQVGA,
const QQVGA = ctru_sys::SIZE_QQVGA; Cif = ctru_sys::SIZE_CIF,
const CIF = ctru_sys::SIZE_CIF; QCif = ctru_sys::SIZE_QCIF,
const QCIF = ctru_sys::SIZE_QCIF; DS = ctru_sys::SIZE_DS_LCD,
const DS_LCD = ctru_sys::SIZE_DS_LCD; DSX4 = ctru_sys::SIZE_DS_LCDx4,
const DS_LCD_X4 = ctru_sys::SIZE_DS_LCDx4; TopLCD = ctru_sys::SIZE_CTR_TOP_LCD,
const CTR_TOP_LCD = ctru_sys::SIZE_CTR_TOP_LCD; BottomLCD = ctru_sys::SIZE_CTR_BOTTOM_LCD,
const CTR_BOTTOM_LCD = ctru_sys::SIZE_CTR_BOTTOM_LCD; }
}
} /// Flag to pass to [Camera::set_frame_rate]
#[repr(u32)]
bitflags! { pub enum FrameRate {
/// A set of flags to be passed to [Camera::set_frame_rate] Fps15 = ctru_sys::FRAME_RATE_15,
#[derive(Default)] Fps15To5 = ctru_sys::FRAME_RATE_15_TO_5,
pub struct CamFrameRate: u32 { Fps15To2 = ctru_sys::FRAME_RATE_15_TO_2,
const RATE_15 = ctru_sys::FRAME_RATE_15; Fps10 = ctru_sys::FRAME_RATE_10,
const RATE_15_TO_5 = ctru_sys::FRAME_RATE_15_TO_5; Fps8_5 = ctru_sys::FRAME_RATE_8_5,
const RATE_15_TO_2 = ctru_sys::FRAME_RATE_15_TO_2; Fps5 = ctru_sys::FRAME_RATE_5,
const RATE_10 = ctru_sys::FRAME_RATE_10; Fps20 = ctru_sys::FRAME_RATE_20,
const RATE_8_5 = ctru_sys::FRAME_RATE_8_5; Fps20To5 = ctru_sys::FRAME_RATE_20_TO_5,
const RATE_5 = ctru_sys::FRAME_RATE_5; Fps30 = ctru_sys::FRAME_RATE_30,
const RATE_20 = ctru_sys::FRAME_RATE_20; Fps30To5 = ctru_sys::FRAME_RATE_30_TO_5,
const RATE_20_TO_5 = ctru_sys::FRAME_RATE_20_TO_5; Fps15To10 = ctru_sys::FRAME_RATE_15_TO_10,
const RATE_30 = ctru_sys::FRAME_RATE_30; Fps20To10 = ctru_sys::FRAME_RATE_20_TO_10,
const RATE_30_TO_5 = ctru_sys::FRAME_RATE_30_TO_5; Fps30To10 = ctru_sys::FRAME_RATE_30_TO_10,
const RATE_15_TO_10 = ctru_sys::FRAME_RATE_15_TO_10; }
const RATE_20_TO_10 = ctru_sys::FRAME_RATE_20_TO_10;
const RATE_30_TO_10 = ctru_sys::FRAME_RATE_30_TO_10; /// Flag to pass to [Camera::set_white_balance] or
}
}
bitflags! {
/// A set of flags to be passed to [Camera::set_white_balance] or
/// [Camera::set_white_balance_without_base_up] /// [Camera::set_white_balance_without_base_up]
#[derive(Default)] #[repr(u32)]
pub struct CamWhiteBalance: u32 { pub enum WhiteBalance {
const AUTO = ctru_sys::WHITE_BALANCE_AUTO; Auto = ctru_sys::WHITE_BALANCE_AUTO,
const BALANCE_3200K = ctru_sys::WHITE_BALANCE_3200K; Type3200K = ctru_sys::WHITE_BALANCE_3200K,
const BALANCE_4150K = ctru_sys::WHITE_BALANCE_4150K; Type4150K = ctru_sys::WHITE_BALANCE_4150K,
const BALANCE_5200K = ctru_sys::WHITE_BALANCE_5200K; Type5200K = ctru_sys::WHITE_BALANCE_5200K,
const BALANCE_6000K = ctru_sys::WHITE_BALANCE_6000K; Type6000K = ctru_sys::WHITE_BALANCE_6000K,
const BALANCE_7000K = ctru_sys::WHITE_BALANCE_7000K; Type7000K = ctru_sys::WHITE_BALANCE_7000K,
const NORMAL = ctru_sys::WHITE_BALANCE_NORMAL; Normal = ctru_sys::WHITE_BALANCE_NORMAL,
const TUNGSTEN = ctru_sys::WHITE_BALANCE_TUNGSTEN; Tungsten = ctru_sys::WHITE_BALANCE_TUNGSTEN,
const WHITE_FLUORESCENT_LIGHT = ctru_sys::WHITE_BALANCE_WHITE_FLUORESCENT_LIGHT; FluorescentLight = ctru_sys::WHITE_BALANCE_WHITE_FLUORESCENT_LIGHT,
const DAYLIGHT = ctru_sys::WHITE_BALANCE_DAYLIGHT; Daylight = ctru_sys::WHITE_BALANCE_DAYLIGHT,
const CLOUDY = ctru_sys::WHITE_BALANCE_CLOUDY; Cloudy = ctru_sys::WHITE_BALANCE_CLOUDY,
const HORIZON = ctru_sys::WHITE_BALANCE_HORIZON; Horizon = ctru_sys::WHITE_BALANCE_HORIZON,
const SHADE = ctru_sys::WHITE_BALANCE_SHADE; Shade = ctru_sys::WHITE_BALANCE_SHADE,
} }
}
/// Flag to pass to [Camera::set_photo_mode]
bitflags! { #[repr(u32)]
/// A set of flags to be passed to [Camera::set_photo_mode] pub enum PhotoMode {
#[derive(Default)] Normal = ctru_sys::PHOTO_MODE_NORMAL,
pub struct CamPhotoMode: u32 { Portrait = ctru_sys::PHOTO_MODE_PORTRAIT,
const NORMAL = ctru_sys::PHOTO_MODE_NORMAL; Landscape = ctru_sys::PHOTO_MODE_LANDSCAPE,
const PORTRAIT = ctru_sys::PHOTO_MODE_PORTRAIT; Nightview = ctru_sys::PHOTO_MODE_NIGHTVIEW,
const LANDSCAPE = ctru_sys::PHOTO_MODE_LANDSCAPE; Letter = ctru_sys::PHOTO_MODE_LETTER,
const NIGHTVIEW = ctru_sys::PHOTO_MODE_NIGHTVIEW; }
const LETTER = ctru_sys::PHOTO_MODE_LETTER;
} /// Flag to pass to [Camera::set_effect]
} #[repr(u32)]
pub enum Effect {
bitflags! { None = ctru_sys::EFFECT_NONE,
/// A set of flags to be passed to [Camera::set_effect] Mono = ctru_sys::EFFECT_MONO,
#[derive(Default)] Sepia = ctru_sys::EFFECT_SEPIA,
pub struct CamEffect: u32 { Negative = ctru_sys::EFFECT_NEGATIVE,
const NONE = ctru_sys::EFFECT_NONE; Negafilm = ctru_sys::EFFECT_NEGAFILM,
const MONO = ctru_sys::EFFECT_MONO; Sepia01 = ctru_sys::EFFECT_SEPIA01,
const SEPIA = ctru_sys::EFFECT_SEPIA; }
const NEGATIVE = ctru_sys::EFFECT_NEGATIVE;
const NEGAFILM = ctru_sys::EFFECT_NEGAFILM; /// Flag to pass to [Camera::set_contrast]
const SEPIA01 = ctru_sys::EFFECT_SEPIA01; #[repr(u32)]
} pub enum Contrast {
} Pattern01 = ctru_sys::CONTRAST_PATTERN_01,
Pattern02 = ctru_sys::CONTRAST_PATTERN_02,
bitflags! { Pattern03 = ctru_sys::CONTRAST_PATTERN_03,
/// A set of flags to be passed to [Camera::set_contrast] Pattern04 = ctru_sys::CONTRAST_PATTERN_04,
#[derive(Default)] Pattern05 = ctru_sys::CONTRAST_PATTERN_05,
pub struct CamContrast: u32 { Pattern06 = ctru_sys::CONTRAST_PATTERN_06,
const PATTERN_01 = ctru_sys::CONTRAST_PATTERN_01; Pattern07 = ctru_sys::CONTRAST_PATTERN_07,
const PATTERN_02 = ctru_sys::CONTRAST_PATTERN_02; Pattern08 = ctru_sys::CONTRAST_PATTERN_08,
const PATTERN_03 = ctru_sys::CONTRAST_PATTERN_03; Pattern09 = ctru_sys::CONTRAST_PATTERN_09,
const PATTERN_04 = ctru_sys::CONTRAST_PATTERN_04; Pattern10 = ctru_sys::CONTRAST_PATTERN_10,
const PATTERN_05 = ctru_sys::CONTRAST_PATTERN_05; Pattern11 = ctru_sys::CONTRAST_PATTERN_11,
const PATTERN_06 = ctru_sys::CONTRAST_PATTERN_06;
const PATTERN_07 = ctru_sys::CONTRAST_PATTERN_07; Low = ctru_sys::CONTRAST_LOW,
const PATTERN_08 = ctru_sys::CONTRAST_PATTERN_08; Normal = ctru_sys::CONTRAST_NORMAL,
const PATTERN_09 = ctru_sys::CONTRAST_PATTERN_09; High = ctru_sys::CONTRAST_HIGH,
const PATTERN_10 = ctru_sys::CONTRAST_PATTERN_10; }
const PATTERN_11 = ctru_sys::CONTRAST_PATTERN_11;
/// Flag to pass to [Camera::set_lens_correction]
const LOW = ctru_sys::CONTRAST_LOW; #[repr(u32)]
const NORMAL = ctru_sys::CONTRAST_NORMAL; pub enum LensCorrection {
const HIGH = ctru_sys::CONTRAST_HIGH; Off = ctru_sys::LENS_CORRECTION_DARK,
} Normal = ctru_sys::LENS_CORRECTION_NORMAL,
} Bright = ctru_sys::LENS_CORRECTION_BRIGHT,
}
bitflags! {
/// A set of flags to be passed to [Camera::set_lens_correction] /// Flag to pass to [Camera::set_output_format]
#[derive(Default)] #[repr(u32)]
pub struct CamLensCorrection: u32 { pub enum OutputFormat {
const OFF = ctru_sys::LENS_CORRECTION_OFF; Yuv422 = ctru_sys::OUTPUT_YUV_422,
const ON_70 = ctru_sys::LENS_CORRECTION_ON_70; Rgb565 = ctru_sys::OUTPUT_RGB_565,
const ON_90 = ctru_sys::LENS_CORRECTION_ON_90; }
const DARK = ctru_sys::LENS_CORRECTION_DARK; /// Flag to pass to [Cam::play_shutter_sound]
const NORMAL = ctru_sys::LENS_CORRECTION_NORMAL; #[repr(u32)]
const BRIGHT = ctru_sys::LENS_CORRECTION_BRIGHT; pub enum ShutterSound {
} Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL,
} Movie = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE,
MovieEnd = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE_END,
bitflags! { }
/// A set of flags to be passed to [Camera::set_output_format]
#[derive(Default)] impl TryFrom<FramebufferFormat> for OutputFormat {
pub struct CamOutputFormat: u32 {
const YUV_422 = ctru_sys::OUTPUT_YUV_422;
const RGB_565 = ctru_sys::OUTPUT_RGB_565;
}
}
impl TryFrom<FramebufferFormat> for CamOutputFormat {
type Error = (); type Error = ();
fn try_from(value: FramebufferFormat) -> Result<Self, Self::Error> { fn try_from(value: FramebufferFormat) -> Result<Self, Self::Error> {
match value { match value {
FramebufferFormat::Rgb565 => Ok(CamOutputFormat::RGB_565), FramebufferFormat::Rgb565 => Ok(OutputFormat::RGB_565),
_ => Err(()), _ => Err(()),
} }
} }
} }
impl TryFrom<CamOutputFormat> for FramebufferFormat { impl TryFrom<OutputFormat> for FramebufferFormat {
type Error = (); type Error = ();
fn try_from(value: CamOutputFormat) -> Result<Self, Self::Error> { fn try_from(value: OutputFormat) -> Result<Self, Self::Error> {
match value { match value {
CamOutputFormat::RGB_565 => Ok(FramebufferFormat::Rgb565), OutputFormat::Rgb565 => Ok(FramebufferFormat::Rgb565),
_ => Err(()), _ => Err(()),
} }
} }
} }
bitflags! {
/// A set of flags to be passed to [Cam::play_shutter_sound]
#[derive(Default)]
pub struct CamShutterSoundType: u32 {
const NORMAL = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL;
const MOVIE = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE;
const MOVIE_END = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE_END;
}
}
/// Struct containing coordinates passed to [Camera::set_trimming_params]. /// Struct containing coordinates passed to [Camera::set_trimming_params].
pub struct CamTrimmingParams { pub struct CamTrimmingParams {
x_start: i16, x_start: i16,
@ -806,8 +782,8 @@ impl Cam {
} }
} }
/// Plays the specified sound based on the [CamShutterSoundType] argument /// Plays the specified sound based on the [ShutterSound] argument
pub fn play_shutter_sound(&self, sound: CamShutterSoundType) -> crate::Result<()> { pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.bits()))?; ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.bits()))?;
Ok(()) Ok(())

Loading…
Cancel
Save