Skip to content

Commit

Permalink
Proper offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Supernovatux committed Aug 22, 2022
1 parent d3a3c9f commit de001cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
20 changes: 5 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/cli_parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs;

use clap::{Parser};
use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};
use log::info;
#[derive(Parser, Debug, Clone)]
Expand All @@ -20,11 +20,11 @@ pub struct Cli {
///Maximum and minimum change to brightness;
#[clap(short, long, value_parser, default_value_t = 10)]
pub limit: i16,
///Offset to limit
///Offset to limit. Use as --offset=<Value>
/// if limit=10
/// offset = 5
/// offset = -5
/// then brightness will vary between -15 to 5;
#[clap(short, long, value_parser, default_value_t = 7)]
#[clap(long, value_parser, default_value_t = -7)]
pub offset: i16,
///Interval in which brightness values are refreshed
#[clap(short, long, value_parser, default_value_t = 5)]
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ async fn main() {
}
tokio::select! {
_ = interval.tick() => info!("Current brightness {}",brightness),
_ = &mut rx => break,
_ = &mut rx => {
brightness_dev.set_brightness(-change);
break;},
}
}
handle.shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cli_parser::get_offset;

pub fn get_value_to_change(lim: u8, brightness: i16) -> i16 {
debug!("Image brightness {}", brightness);
((-2.0 * lim as f64 / 255_f64) * brightness as f64 + lim as f64 - get_offset() as f64) as i16
((-2.0 * lim as f64 / 255_f64) * brightness as f64 + lim as f64 + get_offset() as f64) as i16
}

pub fn get_average_brightness(img: DynamicImage) -> i16 {
Expand Down

0 comments on commit de001cc

Please sign in to comment.