def api_lradc_data(self, mode, dat, req_method, req_args): resp = copy.deepcopy(self.CHIP_INFO) resp["connected"] = True resp["mode"] = mode # Get Sample Rate if mode == "sample_rate" and dat == None and req_method == 'GET': resp["message"] = LRADC.get_sample_rate() # Set Sample Rate elif mode == "sample_rate" and dat != None and req_method in [ 'GET', 'PUT', 'POST' ]: dat = float(dat) if dat in [32.25, 62.5, 125, 250]: resp["message"] = "Setting LRADC Sample Rate to " + str(dat) LRADC.set_sample_rate(dat) # Scale Factor elif mode == "scale_factor" and req_method == 'GET': resp["message"] = LRADC.get_scale_factor() # Get Data elif (mode == "full" or mode == "raw") and req_method == 'GET': dat = int(dat) if dat not in [0, 1]: resp["message"] = "Invalid ADC Channel Specified" elif dat == 0: if mode == "full": resp["message"] = LRADC.get_chan0() elif mode == "raw": resp["message"] = LRADC.get_chan0_raw() elif dat == 1: if mode == "full": resp["message"] = LRADC.get_chan1() elif mode == "raw": resp["message"] = LRADC.get_chan1_raw() else: resp["message"] = "invalid command" return jsonify(resp)
def test_scale_factor(self): assert LRADC.get_scale_factor() == 31.25
import CHIP_IO.LRADC as ADC # == ENABLE DEBUG == print("ENABLING LRADC DEBUG OUTPUT") ADC.toggle_debug() # == SETUP == print("LRADC SETUP WITH SAMPLE RATE OF 125") ADC.setup(125) # == SCALE FACTOR == print("GETTING SCALE FACTOR") scalefactor = ADC.get_scale_factor() print(scalefactor) print("") # == ALLOWABLE SAMPLING RATES == print("GETTING ALLOWABLE SAMPLE RATES") rates = ADC.get_allowable_sample_rates() print(rates) print("IS 32.25 IN RATE TUPLE") print(ADC.SAMPLE_RATE_32P25 in rates) print("") # == CURRENT SAMPLE RATE == print("CURRENT SAMPLING RATE") crate = ADC.get_sample_rate() print(crate) print("") # == SET SAMPLE RATE ==