pulse threshold

This commit is contained in:
devdesk 2024-02-23 01:48:11 +02:00
parent 373b17d8a5
commit bfaa0eca2f

View File

@ -2,6 +2,7 @@ use crate::offline::{Header, HDR_SIZE};
use bracket_color::prelude::*; use bracket_color::prelude::*;
use clap::Parser; use clap::Parser;
use dotenv::dotenv; use dotenv::dotenv;
use std::time::SystemTime;
use std::{ use std::{
io::Write, io::Write,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
@ -9,6 +10,11 @@ use std::{
}; };
use v4l::video::Output; use v4l::video::Output;
const MIN_CUTOFF: f64 = 26.0;
const MAX_CUTOFF: f64 = 36.0;
const MID_CUTOFF: f64 = (MIN_CUTOFF + MAX_CUTOFF) / 2.0;
const RANGE_CUTOFF: f64 = MAX_CUTOFF - MIN_CUTOFF;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
struct Args { struct Args {
@ -87,6 +93,10 @@ fn main(streamer: Arc<Mutex<Streamer>>) -> anyhow::Result<()> {
const WIDTH: usize = 288; const WIDTH: usize = 288;
const HEIGHT: usize = 384; const HEIGHT: usize = 384;
println!("reading cutoff"); println!("reading cutoff");
let start = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs_f64();
let cutoff = streamer.lock().unwrap().cutoff; let cutoff = streamer.lock().unwrap().cutoff;
let greyscale = !args.temperature || cutoff.is_none(); let greyscale = !args.temperature || cutoff.is_none();
let fourcc_repr = if greyscale { let fourcc_repr = if greyscale {
@ -143,7 +153,13 @@ fn main(streamer: Arc<Mutex<Streamer>>) -> anyhow::Result<()> {
{ {
if len == FRAME_LEN { if len == FRAME_LEN {
// read once per frame, can make it lower if need be // read once per frame, can make it lower if need be
let cutoff = streamer.lock().unwrap().cutoff.unwrap_or(0.0); // let cutoff = streamer.lock().unwrap().cutoff.unwrap_or(0.0);
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs_f64();
let dt = now - start;
let cutoff = MID_CUTOFF + f64::sin(dt / 2.0) * 0.5 * RANGE_CUTOFF;
// swap the bytes, we are using LE, not BE, 16 bit grayscale // swap the bytes, we are using LE, not BE, 16 bit grayscale
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2 // possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
for i in 0..FRAME_LEN / 2 { for i in 0..FRAME_LEN / 2 {