web can update pulse
This commit is contained in:
parent
bfaa0eca2f
commit
39551f3794
|
@ -10,11 +10,6 @@ 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 {
|
||||||
|
@ -58,13 +53,17 @@ fn rgb_to_u8s(rgb: &RGB) -> (u8, u8, u8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Streamer {
|
pub(crate) struct Streamer {
|
||||||
pub(crate) cutoff: Option<f64>,
|
pub(crate) min_cutoff: f64,
|
||||||
|
pub(crate) max_cutoff: f64,
|
||||||
|
pub(crate) freq_hz: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn initialize() -> Arc<Mutex<Streamer>> {
|
pub(crate) fn initialize() -> Arc<Mutex<Streamer>> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
Arc::new(Mutex::new(Streamer {
|
Arc::new(Mutex::new(Streamer {
|
||||||
cutoff: args.red_cutoff,
|
min_cutoff: args.red_cutoff.unwrap_or(26.),
|
||||||
|
max_cutoff: args.red_cutoff.unwrap_or(26.) + 10.0,
|
||||||
|
freq_hz: 1.0,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +96,7 @@ fn main(streamer: Arc<Mutex<Streamer>>) -> anyhow::Result<()> {
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs_f64();
|
.as_secs_f64();
|
||||||
let cutoff = streamer.lock().unwrap().cutoff;
|
let greyscale = !args.temperature;
|
||||||
let greyscale = !args.temperature || cutoff.is_none();
|
|
||||||
let fourcc_repr = if greyscale {
|
let fourcc_repr = if greyscale {
|
||||||
[
|
[
|
||||||
b'Y', // | 0b10000000
|
b'Y', // | 0b10000000
|
||||||
|
@ -153,13 +151,16 @@ 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 state = streamer.lock().unwrap();
|
||||||
|
let mid = (state.min_cutoff + state.max_cutoff) / 2.0;
|
||||||
|
let range = state.max_cutoff - state.min_cutoff;
|
||||||
|
let hz = state.freq_hz;
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs_f64();
|
.as_secs_f64();
|
||||||
let dt = now - start;
|
let dt = now - start;
|
||||||
let cutoff = MID_CUTOFF + f64::sin(dt / 2.0) * 0.5 * RANGE_CUTOFF;
|
let cutoff = mid + f64::sin(dt / hz) * 0.5 * range;
|
||||||
// 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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user