Skip to content

Commit

Permalink
Remove unstable features in Helion
Browse files Browse the repository at this point in the history
Also reflect need for building with nightly in README
  • Loading branch information
bryal committed May 3, 2015
1 parent dff6c80 commit f9ec082
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helion"
version = "0.1.3"
version = "0.1.4"
authors = ["bryal <[email protected]>"]
build = "build.rs"

Expand All @@ -10,4 +10,4 @@ dxgcap = "*"
time = "*"

[dependencies.se_rs_ial]
git = "https://github.com/bryal/se-rs-ial"
git = "https://github.com/bryal/se-rs-ial"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ Notes about config sections:
cargo build --release
```

Only Windows is supported at this time, as DXGCap is Windows only and I have not yet added support for any linux screen capturing.
Helion depends on se_rs_ial, which is unstable. As such, Rust Nightly is needed to build the software.

Only Windows is supported at this time, as dxgcap is Windows only and I have not yet added support for any linux screen capturing.
19 changes: 10 additions & 9 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::config::{self, AdditiveColorConf};

use std::cmp::{max, min, partial_min};
use config::{self, AdditiveColorConf};
use partial_min;
use std::cmp::{ max, min };
use std::mem;

static RGB_SIZE: usize = 3; // RGB8 => 3 bytes, what LEDstream expects
Expand Down Expand Up @@ -62,10 +62,11 @@ pub trait Pixel {
/// Transform the color of a pixel with HSV modifiers.
fn hsv_transform(&self, transformer: &HSVTransformer) -> HSV {
let hsv = self.to_hsv();
HSV{hue: hsv.hue,
saturation: partial_min(1.0, hsv.saturation * transformer.saturationGain)
.unwrap_or(1.0),
value: partial_min(1.0, hsv.value * transformer.valueGain).unwrap_or(1.0)}
HSV{
hue: hsv.hue,
saturation: partial_min(1.0, hsv.saturation * transformer.saturationGain, 1.0),
value: partial_min(1.0, hsv.value * transformer.valueGain, 1.0)
}
}
}

Expand Down Expand Up @@ -142,7 +143,7 @@ impl Pixel for HSV {
let p = (val_255 * (1.0 - self.saturation)) as u8;
let q = (val_255 * (1.0 - self.saturation * factorial_part)) as u8;
let t = (val_255 * (1.0 - self.saturation * (1.0 - factorial_part))) as u8;

let (r, g, b) = match sector {
0 => (v_8bit, t, p),
1 => (q, v_8bit, p),
Expand Down Expand Up @@ -197,4 +198,4 @@ pub fn linear_smooth(from: &RGB8, to: RGB8, factor: f64) -> RGB8 {
b: (from.b as f64 + (b_diff * factor)) as u8,
}
}
}
}
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::fs::File;
use std::ops::Range;
use std::path;

use rustc_serialize::{json, Decoder, Decodable};
use rustc_serialize::{ json, Decoder, Decodable };

/// Configuration of a serial output
#[derive(Clone, RustcDecodable)]
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Decodable for Smoothing {
}
}

/// Color manipulation config used to tune the output colors to specific surroundings.
/// Color manipulation config used to tune the output colors to specific surroundings.
#[derive(RustcDecodable, Clone)]
pub struct ColorsManipulation {
/// A list of color transforms
Expand Down Expand Up @@ -168,7 +168,7 @@ pub struct LedsConfig {
/// Color manipulation configuration used to tune the output colors to specific
/// surroundings. The configuration contains a list of color-transforms.
pub color: ColorsManipulation,
/// The configuration for each individual led. This contains the specification of the area
/// The configuration for each individual led. This contains the specification of the area
/// averaged of an input image for each led to determine its color.
pub leds: Vec<Region>,
/// The configuration for the frame-grabber
Expand Down Expand Up @@ -250,4 +250,4 @@ fn parse_led_indices_test() {
assert_eq!(parse_led_indices("*", 10), vec![0..10]);
assert_eq!(parse_led_indices("0, 1 - 5", 10), vec![0..1]);
assert_eq!(parse_led_indices("1-A", 10), vec![]);
}
}
39 changes: 25 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,42 @@

// TODO: TESTS!

#![feature(core)]

extern crate rustc_serialize as rustc_serialize;
extern crate time;
extern crate se_rs_ial as serial;
extern crate dxgcap;

use config::parse_led_indices;
use color::{RGB8,
RgbTransformer,
Pixel};
use capture::{Capturer, ImageAnalyzer };
use color::{ RGB8, RgbTransformer, Pixel };
use capture::{ Capturer, ImageAnalyzer };

use dxgcap::CaptureError;
use std::iter::repeat;
use std::sync::mpsc::{Sender,
Receiver,
channel};
use std::sync::mpsc::{ Sender, Receiver, channel };
use std::thread;
use std::cmp::{max, partial_max};
use std::cmp::{ max, Ordering };

pub mod config;
pub mod color;
pub mod capture;

/// Returns smallest of `a` and `b` if there is one, else returns `expect`
fn partial_min<T: PartialOrd>(a: T, b: T, expect: T) -> T {
match a.partial_cmp(&b) {
Some(Ordering::Less) | Some(Ordering::Equal) => a,
Some(Ordering::Greater) => b,
None => expect,
}
}
/// Returns greatest of `a` and `b` if there is one, else returns `expect`
fn partial_max<T: PartialOrd>(a: T, b: T, expect: T) -> T {
match a.partial_cmp(&b) {
Some(Ordering::Greater) | Some(Ordering::Equal) => a,
Some(Ordering::Less) => b,
None => expect,
}
}

/// A special header is expected by the corresponding LED streaming code running on the Arduino.
/// This only needs to be initialized once since the number of LEDs remains constant.
fn new_pixel_buf_header(n_leds: u16) -> Vec<u8> {
Expand Down Expand Up @@ -94,7 +105,7 @@ impl FrameTimer {
/// An update/frame/refresh has occured; take the time.
fn tick(&mut self) {
let now = time::precise_time_s();
self.last_frame_dt = partial_max(now - self.before, 0.0).unwrap_or(0.0);
self.last_frame_dt = partial_max(now - self.before, 0.0, 0.0);
self.before = now;
}
}
Expand All @@ -111,7 +122,7 @@ fn init_write_thread(port: &str, baud_rate: u32, header: Vec<u8>, pixel_buf: Vec

let (from_write_thread_tx, from_write_thread_rx) = channel();
let (to_write_thread_tx, to_write_thread_rx) = channel::<Vec<RGB8>>();

thread::spawn(move || loop {
let pixel_buf = color::rgbs_to_bytes(to_write_thread_rx.recv().unwrap());

Expand Down Expand Up @@ -172,7 +183,7 @@ fn main() {

init_write_thread(&config.device.output, config.device.rate, out_header, out_pixels)
};

let mut capturer = Capturer::new();
let capture_frame_interval = 1.0 / config.framegrabber.frequency_Hz;
capturer.set_timeout_ms((1_000.0 * capture_frame_interval) as u32);
Expand Down Expand Up @@ -272,4 +283,4 @@ fn main() {
thread::sleep_ms(if time_left > 0.0 { time_left * 1_000.0 } else { 0.0 } as u32);
}
}
}
}

0 comments on commit f9ec082

Please sign in to comment.