@@ -4,7 +4,7 @@ use bincode::error::{DecodeError, EncodeError};
4
4
use bincode:: { Decode , Encode } ;
5
5
use cu29:: clock:: { CuTime , RobotClock } ;
6
6
use cu29:: config:: ComponentConfig ;
7
- use cu29:: cutask:: { CuMsg , CuSinkTask , CuTaskLifecycle , Freezable } ;
7
+ use cu29:: cutask:: { CuMsg , CuSinkTask , Freezable } ;
8
8
use cu29:: { input_msg, CuResult } ;
9
9
use serde:: { Deserialize , Serialize } ;
10
10
@@ -126,7 +126,19 @@ impl SN754410 {
126
126
}
127
127
}
128
128
129
- impl CuTaskLifecycle for SN754410 {
129
+ impl Freezable for SN754410 {
130
+ fn freeze < E : Encoder > ( & self , encoder : & mut E ) -> Result < ( ) , EncodeError > {
131
+ Encode :: encode ( & self . current_power , encoder)
132
+ }
133
+
134
+ fn thaw < D : Decoder > ( & mut self , decoder : & mut D ) -> Result < ( ) , DecodeError > {
135
+ self . current_power = Decode :: decode ( decoder) ?;
136
+ Ok ( ( ) )
137
+ }
138
+ }
139
+
140
+ impl < ' cl > CuSinkTask < ' cl > for SN754410 {
141
+ type Input = input_msg ! ( ' cl, MotorPayload ) ;
130
142
fn new ( config : Option < & ComponentConfig > ) -> CuResult < Self >
131
143
where
132
144
Self : Sized ,
@@ -162,26 +174,6 @@ impl CuTaskLifecycle for SN754410 {
162
174
debug ! ( "Enabling SN754410." ) ;
163
175
self . enable_pwms ( )
164
176
}
165
- fn stop ( & mut self , _clock : & RobotClock ) -> CuResult < ( ) > {
166
- debug ! ( "Disabling SN754410." ) ;
167
- self . disable_pwms ( )
168
- }
169
- }
170
-
171
- impl Freezable for SN754410 {
172
- fn freeze < E : Encoder > ( & self , encoder : & mut E ) -> Result < ( ) , EncodeError > {
173
- Encode :: encode ( & self . current_power , encoder)
174
- }
175
-
176
- fn thaw < D : Decoder > ( & mut self , decoder : & mut D ) -> Result < ( ) , DecodeError > {
177
- self . current_power = Decode :: decode ( decoder) ?;
178
- Ok ( ( ) )
179
- }
180
- }
181
-
182
- impl < ' cl > CuSinkTask < ' cl > for SN754410 {
183
- type Input = input_msg ! ( ' cl, MotorPayload ) ;
184
-
185
177
fn process ( & mut self , clock : & RobotClock , input : Self :: Input ) -> CuResult < ( ) > {
186
178
if let Some ( power) = input. payload ( ) {
187
179
if self . dryrun {
@@ -224,27 +216,30 @@ impl<'cl> CuSinkTask<'cl> for SN754410 {
224
216
}
225
217
Ok ( ( ) )
226
218
}
219
+
220
+ fn stop ( & mut self , _clock : & RobotClock ) -> CuResult < ( ) > {
221
+ debug ! ( "Disabling SN754410." ) ;
222
+ self . disable_pwms ( )
223
+ }
227
224
}
228
225
229
226
pub mod test_support {
230
227
use crate :: MotorPayload ;
231
228
use cu29:: clock:: RobotClock ;
232
229
use cu29:: config:: ComponentConfig ;
233
- use cu29:: cutask:: { CuMsg , CuSrcTask , CuTaskLifecycle , Freezable } ;
230
+ use cu29:: cutask:: { CuMsg , CuSrcTask , Freezable } ;
234
231
use cu29:: { output_msg, CuResult } ;
235
232
236
233
pub struct SN754410TestSrc ;
237
234
238
235
impl Freezable for SN754410TestSrc { }
239
236
240
- impl CuTaskLifecycle for SN754410TestSrc {
237
+ impl < ' cl > CuSrcTask < ' cl > for SN754410TestSrc {
238
+ type Output = output_msg ! ( ' cl, MotorPayload ) ;
239
+
241
240
fn new ( _config : Option < & ComponentConfig > ) -> CuResult < Self > {
242
241
Ok ( Self { } )
243
242
}
244
- }
245
-
246
- impl < ' cl > CuSrcTask < ' cl > for SN754410TestSrc {
247
- type Output = output_msg ! ( ' cl, MotorPayload ) ;
248
243
249
244
fn process ( & mut self , _clock : & RobotClock , _new_msg : Self :: Output ) -> CuResult < ( ) > {
250
245
todo ! ( )
0 commit comments