@@ -16,54 +16,26 @@ pub struct GasIndexAlgorithm {
1616}
1717
1818impl GasIndexAlgorithm {
19- pub fn new ( algorithm_type : AlgorithmType , sampling_interval : f32 ) -> Self {
20- let mut state = GasIndexAlgorithmParams {
21- algorithm_type,
22- sampling_interval : 0.0 ,
23- index_offset : 0.0 ,
24- sraw_minimum : 0 ,
25- gating_max_duration_minutes : 0.0 ,
26- init_duration_mean : 0.0 ,
27- init_duration_variance : 0.0 ,
28- gating_threshold : 0.0 ,
29- index_gain : 0.0 ,
30- tau_mean_hours : 0.0 ,
31- tau_variance_hours : 0.0 ,
32- sraw_std_initial : 0.0 ,
33- uptime : 0.0 ,
34- sraw : 0.0 ,
35- gas_index : 0.0 ,
36- mean_variance_estimator_initialized : false ,
37- mean_variance_estimator_mean : 0.0 ,
38- mean_variance_estimator_sraw_offset : 0.0 ,
39- mean_variance_estimator_std : 0.0 ,
40- mean_variance_estimator_gamma_mean : 0.0 ,
41- mean_variance_estimator_gamma_variance : 0.0 ,
42- mean_variance_estimator_gamma_initial_mean : 0.0 ,
43- mean_variance_estimator_gamma_initial_variance : 0.0 ,
44- mean_variance_estimator_gamma_mean2 : 0.0 ,
45- mean_variance_estimator_gamma_variance2 : 0.0 ,
46- mean_variance_estimator_uptime_gamma : 0.0 ,
47- mean_variance_estimator_uptime_gating : 0.0 ,
48- mean_variance_estimator_gating_duration_minutes : 0.0 ,
49- mean_variance_estimator_sigmoid_k : 0.0 ,
50- mean_variance_estimator_sigmoid_x0 : 0.0 ,
51- mox_model_sraw_std : 0.0 ,
52- mox_model_sraw_mean : 0.0 ,
53- sigmoid_scaled_k : 0.0 ,
54- sigmoid_scaled_x0 : 0.0 ,
55- sigmoid_scaled_offset_default : 0.0 ,
56- adaptive_lowpass_a1 : 0.0 ,
57- adaptive_lowpass_a2 : 0.0 ,
58- adaptive_lowpass_initialized : false ,
59- adaptive_lowpass_x1 : 0.0 ,
60- adaptive_lowpass_x2 : 0.0 ,
61- adaptive_lowpass_x3 : 0.0 ,
62- } ;
19+ /// SAFETY: must call 'init_with_sampling_interval' before processing
20+ pub const fn new_uninitialized ( algorithm_type : AlgorithmType ) -> Self {
21+ Self {
22+ state : GasIndexAlgorithmParams :: new_uninit ( algorithm_type) ,
23+ }
24+ }
6325
64- state. init_with_sampling_interval ( algorithm_type, sampling_interval) ;
26+ pub fn new ( algorithm_type : AlgorithmType , sampling_interval : f32 ) -> Self {
27+ let mut s = Self :: new_uninitialized ( algorithm_type) ;
28+ s. init_with_sampling_interval ( algorithm_type, sampling_interval) ;
29+ s
30+ }
6531
66- Self { state }
32+ pub fn init_with_sampling_interval (
33+ & mut self ,
34+ algorithm_type : AlgorithmType ,
35+ sampling_interval : f32 ,
36+ ) {
37+ self . state
38+ . init_with_sampling_interval ( algorithm_type, sampling_interval) ;
6739 }
6840
6941 /// Calculate the gas index value from the raw sensor value.
@@ -121,6 +93,52 @@ pub struct GasIndexAlgorithmParams {
12193}
12294
12395impl GasIndexAlgorithmParams {
96+ const fn new_uninit ( algorithm_type : AlgorithmType ) -> Self {
97+ GasIndexAlgorithmParams {
98+ algorithm_type,
99+ sampling_interval : 0.0 ,
100+ index_offset : 0.0 ,
101+ sraw_minimum : 0 ,
102+ gating_max_duration_minutes : 0.0 ,
103+ init_duration_mean : 0.0 ,
104+ init_duration_variance : 0.0 ,
105+ gating_threshold : 0.0 ,
106+ index_gain : 0.0 ,
107+ tau_mean_hours : 0.0 ,
108+ tau_variance_hours : 0.0 ,
109+ sraw_std_initial : 0.0 ,
110+ uptime : 0.0 ,
111+ sraw : 0.0 ,
112+ gas_index : 0.0 ,
113+ mean_variance_estimator_initialized : false ,
114+ mean_variance_estimator_mean : 0.0 ,
115+ mean_variance_estimator_sraw_offset : 0.0 ,
116+ mean_variance_estimator_std : 0.0 ,
117+ mean_variance_estimator_gamma_mean : 0.0 ,
118+ mean_variance_estimator_gamma_variance : 0.0 ,
119+ mean_variance_estimator_gamma_initial_mean : 0.0 ,
120+ mean_variance_estimator_gamma_initial_variance : 0.0 ,
121+ mean_variance_estimator_gamma_mean2 : 0.0 ,
122+ mean_variance_estimator_gamma_variance2 : 0.0 ,
123+ mean_variance_estimator_uptime_gamma : 0.0 ,
124+ mean_variance_estimator_uptime_gating : 0.0 ,
125+ mean_variance_estimator_gating_duration_minutes : 0.0 ,
126+ mean_variance_estimator_sigmoid_k : 0.0 ,
127+ mean_variance_estimator_sigmoid_x0 : 0.0 ,
128+ mox_model_sraw_std : 0.0 ,
129+ mox_model_sraw_mean : 0.0 ,
130+ sigmoid_scaled_k : 0.0 ,
131+ sigmoid_scaled_x0 : 0.0 ,
132+ sigmoid_scaled_offset_default : 0.0 ,
133+ adaptive_lowpass_a1 : 0.0 ,
134+ adaptive_lowpass_a2 : 0.0 ,
135+ adaptive_lowpass_initialized : false ,
136+ adaptive_lowpass_x1 : 0.0 ,
137+ adaptive_lowpass_x2 : 0.0 ,
138+ adaptive_lowpass_x3 : 0.0 ,
139+ }
140+ }
141+
124142 fn init_with_sampling_interval (
125143 & mut self ,
126144 algorithm_type : AlgorithmType ,
0 commit comments