@@ -155,7 +155,7 @@ def _get_masked_value(self, value, meas):
155155 def _handle_raw_data (self , adc_value ):
156156 """Convert raw value to analog value"""
157157 current_measurement_range = min (self ._get_masked_value (
158- adc_value , self .MEAS_RANGE ), 5 ) # 5 is the number of parameters
158+ adc_value , self .MEAS_RANGE ), 4 ) # 5 is the number of parameters
159159 adc_result = self ._get_masked_value (adc_value , self .MEAS_ADC ) * 4
160160 bits = self ._get_masked_value (adc_value , self .MEAS_LOGIC )
161161 analog_value = self .get_adc_result (
@@ -234,37 +234,33 @@ def _digital_to_analog(self, adc_value):
234234 """Convert discrete value to analog value"""
235235 return int .from_bytes (adc_value , byteorder = "little" , signed = False ) # convert reading to analog value
236236
237- def average_of_sampling_period (self , buf ):
237+ def get_samples (self , buf ):
238238 """
239- Calculates the average value of one sampling period.
239+ Returns list of samples read in one sampling period.
240240 The number of sampled values depends on the delay between serial reads.
241+ Manipulation of samples is left to the user.
241242 See example for more info.
242243 """
243244
244245 sample_size = 4 # one analog value is 4 bytes in size
245246 offset = self .remainder ["len" ]
246- measurement_avg = 0
247- num_samples = 0
247+ samples = []
248248
249249 first_reading = (self .remainder ["sequence" ] + buf [0 :sample_size - offset ])[:4 ]
250250 adc_val = self ._digital_to_analog (first_reading )
251- measurement_avg + = self ._handle_raw_data (adc_val )
252- num_samples += 1
251+ measurement = self ._handle_raw_data (adc_val )
252+ samples . append ( measurement )
253253
254254 offset = sample_size - offset
255255
256256 while offset <= len (buf ) - sample_size :
257257 next_val = buf [offset :offset + sample_size ]
258258 offset += sample_size
259259 adc_val = self ._digital_to_analog (next_val )
260-
261- measurement_avg += self ._handle_raw_data (adc_val )
262- num_samples += 1
263-
264- print ("Avg of {} samples: {} μA" .format (
265- num_samples , measurement_avg / num_samples ))
260+ measurement = self ._handle_raw_data (adc_val )
261+ samples .append (measurement )
266262
267263 self .remainder ["sequence" ] = buf [offset :len (buf )]
268264 self .remainder ["len" ] = len (buf )- offset
269265
270- return measurement_avg / num_samples
266+ return samples # return list of samples, handle those lists in PPK2 API wrapper
0 commit comments