Skip to content

Commit d93e57f

Browse files
committed
refactor: Remove utils module
1 parent f1366e9 commit d93e57f

File tree

8 files changed

+38
-42
lines changed

8 files changed

+38
-42
lines changed

src/api/flat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use std::sync::Arc;
44

55
use thiserror::Error;
66

7+
use super::types::i32_to_duration;
8+
79
use crate::{
810
component::ComponentName,
911
global::{Global, InputMessage, InputMessageData, InputSourceHandle, InputSourceName},
1012
image::{RawImage, RawImageError},
1113
models::Color,
12-
utils::i32_to_duration,
1314
};
1415

1516
/// Schema definitions as Serde serializable structures and enums

src/api/proto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::sync::Arc;
33

44
use thiserror::Error;
55

6+
use super::types::i32_to_duration;
7+
68
use crate::{
79
component::ComponentName,
810
global::{InputMessage, InputMessageData, InputSourceHandle},
911
image::{RawImage, RawImageError},
1012
models::Color,
11-
utils::i32_to_duration,
1213
};
1314

1415
/// Schema definitions as Serde serializable structures and enums

src/api/types.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ use crate::{
44
component::ComponentName,
55
global::{InputMessageData, Message},
66
models::Color,
7-
utils::color_to_hsl,
87
};
98

109
fn not_positive(x: &i64) -> bool {
1110
!(*x > 0)
1211
}
1312

13+
fn color_to_hsl(color: Color) -> palette::Hsl {
14+
let (r, g, b) = color.into_components();
15+
palette::Hsl::from(palette::LinSrgb::new(
16+
r as f32 / 255.0,
17+
g as f32 / 255.0,
18+
b as f32 / 255.0,
19+
))
20+
}
21+
1422
#[derive(Debug, Serialize)]
1523
pub struct PriorityInfo {
1624
pub priority: i32,
@@ -90,3 +98,15 @@ impl From<&Color> for LedColor {
9098
}
9199
}
92100
}
101+
102+
pub fn i32_to_duration(d: Option<i32>) -> Option<chrono::Duration> {
103+
if let Some(d) = d {
104+
if d <= 0 {
105+
None
106+
} else {
107+
Some(chrono::Duration::milliseconds(d as _))
108+
}
109+
} else {
110+
None
111+
}
112+
}

src/color.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use std::{convert::TryFrom, num::ParseIntError};
22

33
use slotmap::{DefaultKey, SlotMap};
44

5-
use crate::{
6-
models::{Color, Color16},
7-
utils::{color_to16, color_to8},
8-
};
5+
use crate::models::{Color, Color16};
96

107
#[derive(Default, Debug, Clone, Copy)]
118
struct RgbChannelAdjustment {
@@ -358,3 +355,13 @@ impl ChannelAdjustments {
358355
}
359356
}
360357
}
358+
359+
pub fn color_to8(color: Color16) -> Color {
360+
let (r, g, b) = color.into_components();
361+
Color::from_components(((r >> 8) as u8, (g >> 8) as u8, (b >> 8) as u8))
362+
}
363+
364+
pub fn color_to16(color: Color) -> Color16 {
365+
let (r, g, b) = color.into_components();
366+
Color16::from_components(((r as u16) << 8, (g as u16) << 8, (b as u16) << 8))
367+
}

src/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Instance {
6565
}
6666

6767
fn handle_color(&mut self, color: models::Color) {
68-
let color = crate::utils::color_to16(color);
68+
let color = crate::color::color_to16(color);
6969
self.color_data.iter_mut().map(|x| *x = color).count();
7070
}
7171

src/instance/smoothing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Smoothing {
8080

8181
// Convert current data to led data
8282
for (src, dst) in self.current_data.iter().zip(self.led_data.iter_mut()) {
83-
*dst = crate::utils::color_to8(*src);
83+
*dst = crate::color::color_to8(*src);
8484
}
8585
}
8686

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ pub mod instance;
1111
pub mod models;
1212
pub mod serde;
1313
pub mod servers;
14-
pub mod utils;

src/utils.rs

-32
This file was deleted.

0 commit comments

Comments
 (0)