@@ -160,13 +160,21 @@ def decode(self):
160160 dshot_value = DshotCmd (self .dshot_cfg )
161161 telem_value = DshotTelem (self .dshot_cfg )
162162
163+ last_dshot_value = DshotCmd (self .dshot_cfg )
164+ last_telem_value = DshotTelem (self .dshot_cfg )
165+
166+ max_time_before_telem = 40e-6
167+ max_samples_before_telem = int (max_time_before_telem / (1 / self .samplerate ))
168+
163169 #bitseq = BitDshot()
164170 while True :
165171
166172 match self .state :
167173 case State .CMD :
168174 match self .state_dshot :
169175 case State_Dshot .RESET :
176+ if dshot_value .crc_ok :
177+ last_dshot_value = dshot_value
170178 dshot_value = DshotCmd (self .dshot_cfg )
171179 self .state_dshot = State_Dshot .START
172180
@@ -175,6 +183,7 @@ def decode(self):
175183 pins = self .wait ([{0 : 'r' }, {0 : 'f' }, {'skip' : self .dshot_cfg .samples_after_motorcmd }])
176184 else :
177185 pins = self .wait ([{0 : 'f' }, {0 : 'r' }, {'skip' : self .dshot_cfg .samples_after_motorcmd }])
186+
178187 #TODO: Increase skip to maximum time for effiency
179188 #TODO: Mark any changes in this time as errors? Option to reduce load?
180189
@@ -195,6 +204,8 @@ def decode(self):
195204 if result :
196205 self .display_dshot (dshot_value )
197206 self .state_dshot = State_Dshot .RESET
207+ #TODO: Change??
208+ dshot_value .packet .es = self .samplenum
198209 if result and self .dshot_cfg .bidirectional :
199210 self .state = State .TELEM
200211
@@ -221,10 +232,15 @@ def decode(self):
221232 self .state_telem = State_Dshot .START
222233
223234 case State_Dshot .START :
235+ if last_dshot_value .packet .es is not None :
236+ if self .samplenum >= last_dshot_value .packet .es + max_samples_before_telem :
237+ self .state_telem = State_Dshot .RESET
238+ self .state = State .CMD
239+ continue
224240 # First wait for falling edge (idle high)
225241 pins = self .wait ([{0 : 'f' }])
226242 # Save start pulse
227- tlm_start = self .samplenum
243+ telem_value . packet . ss = self .samplenum
228244 # Switch to receiving state
229245 self .state_telem = State_Dshot .RECV
230246 # TODO: Check if still low after 1/8 bitlength for error det?
0 commit comments