@@ -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,10 @@ 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+
187+ #if self.samplenum == (self.samplenum + (1/self.samplerate * 30e-6):
188+ print ((self .samplenum + (1 / self .samplerate * 30e-6 )))
189+
178190 #TODO: Increase skip to maximum time for effiency
179191 #TODO: Mark any changes in this time as errors? Option to reduce load?
180192
@@ -195,6 +207,8 @@ def decode(self):
195207 if result :
196208 self .display_dshot (dshot_value )
197209 self .state_dshot = State_Dshot .RESET
210+ #TODO: Change??
211+ dshot_value .packet .es = self .samplenum
198212 if result and self .dshot_cfg .bidirectional :
199213 self .state = State .TELEM
200214
@@ -221,10 +235,15 @@ def decode(self):
221235 self .state_telem = State_Dshot .START
222236
223237 case State_Dshot .START :
238+ if last_dshot_value .packet .es is not None :
239+ if self .samplenum >= last_dshot_value .packet .es + max_samples_before_telem :
240+ self .state_telem = State_Dshot .RESET
241+ self .state = State .CMD
242+ continue
224243 # First wait for falling edge (idle high)
225244 pins = self .wait ([{0 : 'f' }])
226245 # Save start pulse
227- tlm_start = self .samplenum
246+ telem_value . packet . ss = self .samplenum
228247 # Switch to receiving state
229248 self .state_telem = State_Dshot .RECV
230249 # TODO: Check if still low after 1/8 bitlength for error det?
0 commit comments