Skip to content

Commit 3b78902

Browse files
committed
refactor: a bit more sens making
1 parent eb7dc49 commit 3b78902

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

maccel-cli/src/libmaccel.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ use crate::params::Param;
22

33
use self::fixedptc::Fixedpt;
44

5-
mod c_lib {
6-
extern "C" {
7-
pub fn sensitivity(
8-
speed_in: i32,
9-
param_sens_mult: i32,
10-
param_accel: i32,
11-
param_offset: i32,
12-
param_output_cap: i32,
13-
) -> i32;
14-
}
15-
}
16-
175
pub struct Params {
186
sens_mult: i32,
197
accel: i32,
@@ -62,18 +50,13 @@ pub fn sensitivity(s_in: f32, params: Params) -> f64 {
6250
}
6351

6452
pub mod fixedptc {
65-
use std::ffi::c_char;
6653
use std::ffi::CStr;
6754

68-
extern "C" {
69-
fn fixedpt_to_str(num: i32) -> *const c_char;
70-
fn fixedpt_from_float(value: f32) -> i32;
71-
fn fixedpt_to_float(value: i32) -> f32;
72-
}
55+
use super::c_lib;
7356

7457
fn fixedpt_as_str(num: &i32) -> anyhow::Result<&str> {
7558
unsafe {
76-
let s = CStr::from_ptr(fixedpt_to_str(*num));
59+
let s = CStr::from_ptr(c_lib::fixedpt_to_str(*num));
7760
let s = core::str::from_utf8(s.to_bytes())?;
7861
return Ok(s);
7962
}
@@ -83,14 +66,14 @@ pub mod fixedptc {
8366

8467
impl From<Fixedpt> for f32 {
8568
fn from(value: Fixedpt) -> Self {
86-
unsafe { fixedpt_to_float(value.0) }
69+
unsafe { c_lib::fixedpt_to_float(value.0) }
8770
}
8871
}
8972

9073
impl From<f32> for Fixedpt {
9174
fn from(value: f32) -> Self {
9275
unsafe {
93-
let i = fixedpt_from_float(value);
76+
let i = c_lib::fixedpt_from_float(value);
9477
return Fixedpt(i);
9578
}
9679
}
@@ -106,8 +89,28 @@ pub mod fixedptc {
10689

10790
pub fn fixedpt(num: f32) -> Fixedpt {
10891
unsafe {
109-
let i = fixedpt_from_float(num);
92+
let i = c_lib::fixedpt_from_float(num);
11093
return Fixedpt(i);
11194
}
11295
}
11396
}
97+
98+
mod c_lib {
99+
use std::ffi::c_char;
100+
101+
extern "C" {
102+
pub fn sensitivity(
103+
speed_in: i32,
104+
param_sens_mult: i32,
105+
param_accel: i32,
106+
param_offset: i32,
107+
param_output_cap: i32,
108+
) -> i32;
109+
}
110+
111+
extern "C" {
112+
pub fn fixedpt_to_str(num: i32) -> *const c_char;
113+
pub fn fixedpt_from_float(value: f32) -> i32;
114+
pub fn fixedpt_to_float(value: i32) -> f32;
115+
}
116+
}

maccel-cli/src/tui.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,10 @@ fn ui(frame: &mut Frame, app: &mut AppState) {
375375
fn bounds_and_labels(bounds: [f64; 2], div: usize) -> ([f64; 2], Vec<Span<'static>>) {
376376
let [o, f] = bounds;
377377
let d = f - o;
378-
// let gap = 1f64;
379-
let gap = d / (div as f64);
378+
let step = d / (div as f64);
380379

381380
let labels = (0..=div)
382-
.map(|i| o + i as f64 * gap)
381+
.map(|i| o + i as f64 * step)
383382
.map(|label| format!("{:.2}", label).into())
384383
.collect();
385384

0 commit comments

Comments
 (0)