@@ -2,18 +2,6 @@ use crate::params::Param;
2
2
3
3
use self :: fixedptc:: Fixedpt ;
4
4
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
-
17
5
pub struct Params {
18
6
sens_mult : i32 ,
19
7
accel : i32 ,
@@ -62,18 +50,13 @@ pub fn sensitivity(s_in: f32, params: Params) -> f64 {
62
50
}
63
51
64
52
pub mod fixedptc {
65
- use std:: ffi:: c_char;
66
53
use std:: ffi:: CStr ;
67
54
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;
73
56
74
57
fn fixedpt_as_str ( num : & i32 ) -> anyhow:: Result < & str > {
75
58
unsafe {
76
- let s = CStr :: from_ptr ( fixedpt_to_str ( * num) ) ;
59
+ let s = CStr :: from_ptr ( c_lib :: fixedpt_to_str ( * num) ) ;
77
60
let s = core:: str:: from_utf8 ( s. to_bytes ( ) ) ?;
78
61
return Ok ( s) ;
79
62
}
@@ -83,14 +66,14 @@ pub mod fixedptc {
83
66
84
67
impl From < Fixedpt > for f32 {
85
68
fn from ( value : Fixedpt ) -> Self {
86
- unsafe { fixedpt_to_float ( value. 0 ) }
69
+ unsafe { c_lib :: fixedpt_to_float ( value. 0 ) }
87
70
}
88
71
}
89
72
90
73
impl From < f32 > for Fixedpt {
91
74
fn from ( value : f32 ) -> Self {
92
75
unsafe {
93
- let i = fixedpt_from_float ( value) ;
76
+ let i = c_lib :: fixedpt_from_float ( value) ;
94
77
return Fixedpt ( i) ;
95
78
}
96
79
}
@@ -106,8 +89,28 @@ pub mod fixedptc {
106
89
107
90
pub fn fixedpt ( num : f32 ) -> Fixedpt {
108
91
unsafe {
109
- let i = fixedpt_from_float ( num) ;
92
+ let i = c_lib :: fixedpt_from_float ( num) ;
110
93
return Fixedpt ( i) ;
111
94
}
112
95
}
113
96
}
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
+ }
0 commit comments