use std::sync::{Mutex, PoisonError};
use crate::board::{self, Jpeg};
use crate::error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Config {
pub width: u32,
pub height: u32,
pub fps: u32,
pub quality: u8,
}
impl Config {
#[must_use]
pub const fn qvga_jpeg() -> Self {
Config {
width: 320,
height: 240,
fps: 15,
quality: 80,
}
}
#[must_use]
pub const fn vga_jpeg() -> Self {
Config {
width: 640,
height: 480,
fps: 10,
quality: 80,
}
}
#[must_use]
pub const fn at_fps(mut self, fps: u32) -> Self {
self.fps = fps;
self
}
}
static CONFIG: Mutex<Option<Config>> = Mutex::new(None);
pub fn begin(config: Config) -> bool {
let r = board::with(|b| b.cam_begin(&config));
if r.is_ok() {
*CONFIG.lock().unwrap_or_else(PoisonError::into_inner) = Some(config);
}
error::ok(r)
}
pub fn grab() -> Option<Jpeg> {
error::some(board::with(|b| b.cam_grab()))
}
#[must_use]
pub fn config() -> Option<Config> {
*CONFIG.lock().unwrap_or_else(PoisonError::into_inner)
}