@@ -40,7 +40,7 @@ pub struct ModeDoesNotExistError(Mode);
40
40
41
41
#[ derive( Debug ) ]
42
42
pub struct SequenceExecutionHelper {
43
- target_mode : Mode ,
43
+ target_mode : Option < Mode > ,
44
44
state : SequenceExecutionHelperStates ,
45
45
request_id : RequestId ,
46
46
current_sequence_index : Option < usize > ,
@@ -49,7 +49,7 @@ pub struct SequenceExecutionHelper {
49
49
impl Default for SequenceExecutionHelper {
50
50
fn default ( ) -> Self {
51
51
Self {
52
- target_mode : 0 ,
52
+ target_mode : None ,
53
53
state : SequenceExecutionHelperStates :: Idle ,
54
54
request_id : 0 ,
55
55
current_sequence_index : None ,
@@ -67,12 +67,16 @@ impl SequenceExecutionHelper {
67
67
if !sequence_tables. 0 . contains_key ( & mode) {
68
68
return Err ( ModeDoesNotExistError ( mode) ) ;
69
69
}
70
- self . target_mode = mode;
70
+ self . target_mode = Some ( mode) ;
71
71
self . request_id = request_id;
72
72
self . current_sequence_index = None ;
73
73
Ok ( ( ) )
74
74
}
75
75
76
+ pub fn target_mode ( & self ) -> Option < Mode > {
77
+ self . target_mode
78
+ }
79
+
76
80
pub fn confirm_sequence_done ( & mut self ) {
77
81
if let SequenceExecutionHelperStates :: AwaitingCheckSuccess = self . state {
78
82
self . state = SequenceExecutionHelperStates :: Idle ;
@@ -103,10 +107,13 @@ impl SequenceExecutionHelper {
103
107
if self . state == SequenceExecutionHelperStates :: AwaitingCheckSuccess {
104
108
return Ok ( SequenceHandlerResult :: AwaitingSuccessCheck ) ;
105
109
}
110
+ if self . target_mode . is_none ( ) {
111
+ return Ok ( SequenceHandlerResult :: SequenceDone ) ;
112
+ }
106
113
match self . current_sequence_index {
107
114
Some ( idx) => {
108
115
// Execute the sequence.
109
- let seq_table_value = table. 0 . get ( & self . target_mode ) . unwrap ( ) ;
116
+ let seq_table_value = table. 0 . get ( & self . target_mode . unwrap ( ) ) . unwrap ( ) ;
110
117
self . execute_sequence_and_map_to_result (
111
118
seq_table_value,
112
119
idx,
@@ -116,7 +123,7 @@ impl SequenceExecutionHelper {
116
123
}
117
124
None => {
118
125
// Find the first sequence
119
- let seq_table_value = table. 0 . get ( & self . target_mode ) . unwrap ( ) ;
126
+ let seq_table_value = table. 0 . get ( & self . target_mode . unwrap ( ) ) . unwrap ( ) ;
120
127
if seq_table_value. entries . is_empty ( ) {
121
128
Ok ( SequenceHandlerResult :: SequenceDone )
122
129
} else {
0 commit comments