def generate(battery=None): global state, mode # Update battery's state if battery is not None: battery.update() # Generate ADC values ADC.generate(state, mode, battery) #Pet Watchdog WDTimer.Check_State() #Initialize Watchdog Timer WDTimer.WD_Enable() #Initialize Timer Timer.Enable()
def getWindSpeed(adc_pin): # Read the ADC pin windBits = ADC.readadc(adc_pin) # Get the 8-bit (voltage) output. Range from 0 to 1023 bits = int(windBits) # Convert the ADC output to a voltage value # If the ADC reading is above or below the expected threshold values # set them to the threshold values. Else calculate as normal if (bits < bitMin): voltage = 0.4 elif (bits > bitMax): voltage = 2 print ('Voltage at maximum, maximum wind speed reached\n') else: voltage = ((bits * 3.3) / 1024) # Shift bits for speed calculation. This is the actual increase in # speed (bits) as the anemometer will output a base of 125 bits (0.4V) # when not moving bitShift = bits - bitMin # If bitShift result is less than 0, change to 0 before wind speed # calculation if (bitShift < 0): bitShift = 0 # As the increase in speed is linear, multiply the number of bits by # the speed constant speedM = speedConst * bitShift # Speed increases linearly speedKm = speedM * 3.6 # Convert from metres to kilometres return bits, voltage, speedM, speedKm
def __init__(self, ground_ip): self.status_vector = dict() self.command_vector = dict() self.ground_ip = ground_ip self.info_logger = InfoLogger() self.data_logger = DataLogger() self.adcs_logger = AdcsLogger() #@TODO where antenna to start #self.adcs_logger.write_info(' {}, {}, {}, {}'.format(0, 0, 0, 0)) self.elink = elinkmanager.ELinkManager(self, self.ground_ip) self.thread_elink = None self.data_manager = DataManager(self, self.info_logger, self.data_logger) self.thread_data_manager = None self.dmc = dmc.DMC(self) self.thread_dmc = None self.heat = heat.HEAT(self) self.thread_heat = None self.adc = adc.ADC(self) self.thread_adc = None self.tx = tx.TX(self) self.thread_tx = None self.counterdown = CounterDown(self) self.paths = paths.Paths() GPIO.setmode(GPIO.BOARD) Master.__instance = self
def hygro_live(): #writes to live hygrometer reading global hygro readings = [0, 0, 0, 0, 0] i = 0 f = open("/var/www/html/hygrometer_readings.txt", "w") while i < len(hygro): temp = ADC.readadc(hygro[i]) percent = 100.0 - (temp / 10.23) readings[i] = percent #write temp and humidity to live file f.write(str(percent) + " ") i += 1 f.close() nowTime = datetime.datetime.now() if nowTime.month < 10: month = "0" + str(nowTime.month) else: month = str(nowTime.month) if nowTime.day < 10: day = "0" + str(nowTime.day) else: day = str(nowTime.day) #write to permanent history f3 = open("./SDPtestingOutputs/hygroDebug.txt", "a") f3.write("\n" + str(nowTime.year) + str(month) + str(day) + "\t" + str(nowTime.hour) + " " + str(nowTime.minute) + "\t" + str(readings[0]) + "\t" + str(readings[1]) + "\t" + str(readings[2]) + "\t" + str(readings[3]) + "\t" + str(readings[4])) f3.close()
def __init__(self): self.SPIPort = SPI.Port(mosi, miso, clock) self.ADConverter = ADC.MCP3008(self.SPIPort, ADConverterCS) self.VoltMeter = VoltMeter.Meter(self.ADConverter, VoltMeterCH) self.BoostSensor = PressureSensor.MPX2202AP(self.ADConverter, PressureSensorCH) self.EGTSensor = Thermocouple.MAX31855(self.SPIPort, ThermocoupleCS)
def display(battery=None): #print watchdog countdown global stdscr # Read ADC values adc_values = ADC.read() global frequency frequency = PLL.Get_Frequency() stdscr.addstr(0, 10, "Battery") stdscr.addstr(1, 0, "==============================") stdscr.addstr(2, 0, f"ADC:") stdscr.addstr(2, 10, f"Low Precision: {adc_values[0][0]}") stdscr.addstr(3, 10, f"High Precision: {adc_values[0][1]}") # Read Current values stdscr.addstr(4, 0, f"Current:") stdscr.addstr(4, 10, f"{adc_values[1]} A ") #Read CAN data CANdata = CAN.Get_CAN_Info() text = ' '.join(CANdata) #put elements of the list of CAN data bytes into a string CANbox.erase() #clear previous data in the box CANbox.addstr(4, 0, textwrap.fill(text, 40)) CANbox.addstr(3, 2, "CAN ID and Message:") # Display Watchdog ticks ticks = WDTimer.Tick() stdscr.addstr(10, 0, f" ") #clear previous tick stdscr.addstr(10, 0, f"WDTimer Countdown: {ticks}") #Display current frequency stdscr.addstr(6, 0, f" ") stdscr.addstr(6, 0, f"Clock Frequency: {frequency} Hz") # Read Module values stdscr.addstr(0, 54, "Modules") stdscr.addstr(1, 40, "====================================") module_values = SPI.read() for i, module in enumerate(module_values): stdscr.addstr(i+2, 37, f"{i+1}") stdscr.addstr(i+2, 40, f"| {'X' if module[0] else ' '} | {module[1]/10000:.4f}V | {module[2]/1000:.3f}°C | {module[3]/1000:.3f}°C |") # Read LED values stdscr.addstr(0, 90, "LEDs") stdscr.addstr(1, 80, "=======================") lights = Lights.read() curses.init_pair(1, curses.COLOR_RED, curses.COLOR_RED) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_GREEN) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLACK) for i in range(9): stdscr.addstr(i+2, 80, lights_names[i]) if lights & (0x1<<i): if i == 7: stdscr.addstr(i+2, 100, "[]", curses.color_pair(2)) else: stdscr.addstr(i+2, 100, "[]", curses.color_pair(1)) else: stdscr.addstr(i+2, 100, "[]", curses.color_pair(3)) strobe = Strobelight.read() stdscr.addstr(11, 80, 'S_PULSING') if strobe: stdscr.addstr(11, 100, "[]", curses.color_pair(2)) else: stdscr.addstr(11, 100, "[]", curses.color_pair(3)) stdscr.refresh()
def waterRelayOff(): global sensor1 global relayOn, waterThresh while threadsRunning['waterOff']: while (relayOn[0] == 'on'): sensor1 = ADC.adcMeasure(0) if sensor1 >= waterThresh[1]: relayOn[0] = 'off' else: continue
def foodRelayOff(): global sensor2 global relayOn, foodThresh while threadsRunning['foodOff']: while (relayOn[1] != 'off'): sensor2 = ADC.adcMeasure(1) if sensor2 >= foodThresh[1]: relayOn[1] = 'off' else: continue
def __init__(self): self._interrupted = False self._lock = threading.RLock() self._cmdThread = None self.motor = Motor.Motor() self.sonic = Ultrasonic.Ultrasonic() self.adc = ADC.Adc() self.servo = servo.Servo() self.stop() self.pointSonic()
def __init__(self, master): #General initialization GPIO.setwarnings(False) #disable runtime warnings GPIO.setmode(GPIO.BCM) #use Broadcom GPIO names #initialize 4 ports self._jp4 = ADC(i2cAddress, "JP4") self._jp5 = ADC(i2cAddress, "JP5") self._jp6 = ADC(i2cAddress, "JP6") self._jp7 = ADC(i2cAddress, "JP7") #GUI initialization Frame.__init__(self, master) self._master = master self._interviewing = False self._redButtonPressed = False self.pack() self._createWidgetsForCalibrateMode()
def record_ph(): #measures ph and records to file time = datetime.datetime.now() Offset = 1.03 temp = ADC.readadc(4) volt = temp * 5.0 / 1024.0 ph = (14.0 - (3.5 * volt)) * (1.536) + Offset #live reading f = open("/var/www/html/pH_readings.txt", "w") f.write(str(ph)) f.close() f2 = open("./SDPtestingOutputs/pHDebug.txt", "a") f2.write(str(time.hour) + "\t" + str(time.minute) + "\t" + str(ph) + "\n") f2.close()
def check_ph(): f_ph = open("./SDPtestingOutputs/pHDebug.txt", "a") time = datetime.datetime.now() Offset = 1.03 temp = ADC.readadc(4) volt = temp * 5.0 / 1024.0 ph = (14.0 - (3.5 * volt)) * (1.536) + Offset if (ph > 7.0): Valve.ph_down() f_ph.write( str(time.hour) + "\t" + str(time.minute) + "\t" + "pH down\n") elif (ph < 5.0): Valve.ph_up() f_ph.write(str(time.hour) + "\t" + str(time.minute) + "\t" + "pH up\n") f_ph.close()
def check_hygro( ): #checks hygrometer levels and writes to live file and history file global hygro readings = [0, 0, 0, 0, 0] i = 0 f = open("/var/www/html/hygrometer_readings.txt", "w") while i < len(hygro): temp = ADC.readadc(hygro[i]) percent = 100.0 - (temp / 10.23) readings[i] = percent #write temp and humidity to live file f.write(str(percent) + " ") i += 1 f.close() #write to history file f2 = open("/var/www/html/hygrometerHistory.tsv", "r") lines = f2.readlines() f2.close() f2 = open("/var/www/html/hygrometerHistory.tsv", "w") lineNum = 0 for line in lines: if lineNum != 1: f2.write(line) lineNum += 1 nowTime = datetime.datetime.now() if nowTime.month < 10: month = "0" + str(nowTime.month) else: month = str(nowTime.month) if nowTime.day < 10: day = "0" + str(nowTime.day) else: day = str(nowTime.day) readings[4] = (readings[0] + readings[1] + readings[2] + readings[3]) / 4.0 f2.write("\n" + str(nowTime.year) + str(month) + str(day) + "\t" + str(readings[0]) + "\t" + str(readings[1]) + "\t" + str(readings[2]) + "\t" + str(readings[3]) + "\t" + str(readings[4])) f2.close() '''#write to permanent history
def __init__(self, ground_ip): self.status_vector = dict() self.command_vector = dict() self.ground_ip = ground_ip self.info_logger = InfoLogger() self.data_logger = DataLogger() self.adcs_logger = AdcsLogger() self.elink = elinkmanager.ELinkManager(self, self.ground_ip) self.thread_elink = None #self.data_manager = DataManager(self, self.info_logger, self.data_logger) #self.thread_data_manager = None self.adc = adc.ADC(self) self.thread_adc = None self.counterdown = CounterDown(self) self.paths = paths.Paths() self.pin_powerB = pins.Pins( ).pin_powerB # @TODO change it in boot/config.txt #GPIO.setmode(GPIO.BOARD) #GPIO.setup(self.pin_powerB, GPIO.OUT) Master.__instance = self
import OUT import time import Float import Valve import ADC time.sleep(2) f = open("/var/www/html/hygrometer_readings.txt","w") #create file to write to change!!! temp = ADC.readadc(0) #read hygrometer value percent = 100.0 - (temp / 10.23) #print(str(percent)) f.write("First reading: " + str(percent) + '\n') #write first to file #f.write("First reading: 43.3456542345" + "\n") f.close() OUT.ON(6) #turn on the lights time.sleep(3) #wait 3 seconds OUT.ON(3) #start filling bucket time.sleep(10)#wait 10 seconds Float.pumpOff() #waits for switch to turn off pump time.sleep(3) #wait 3 seconds Valve.nute() #dispenses nutrients OUT.ON(5) #turn on air pump time.sleep(2) OUT.ON(4) #turn on hyrdroponic pump time.sleep(30) OUT.OFF(4) #turn off hydroponic pump #OUT.ON(2) time.sleep(10) OUT.OFF(6) #turn off the lights time.sleep(1) OUT.OFF(5) #turn off air pump'''
def polling(seconds): global sensor1 while threadsRunning['polling']: sensor1 = ADC.adcMeasure(0) sleep(seconds)
if __name__ == '__main__': print('Initialize gamepad control...') myPad = gamepad.Gamepad() myPad.set_scale(.05, 800, .95, 4095) print('Initialize motor control...') myEngine = Motor.Motor() print('Initialize servo control ... ') myServo = ServoControl(debug = True) print('Initialize Buzzer Driver...') myBuzzer = Buzzer.Buzzer() print('Initialize ADC Driver...') myAdc = ADC.Adc() Thread_Monitor = threading.Thread(target = monitorBattery, args=[myAdc, myBuzzer]) Thread_Monitor.start() print('Initialize LED Driver...') myLed = Led.Led() try: print('Center camera head...') myServo.center() time.sleep(2) print('Enter 50ms control loop...') disableMotor = False while True: # 1st stick controls the wheel motors
def readings(channel): global readingsList for x in range(0, 50): readingsList.append(ADC.adcMeasure(channel)) sleep(.1)
import threading import RPi.GPIO as GPIO from time import sleep from datetime import datetime, time, timedelta from configparser import ConfigParser as cp GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pins = [2, 3] waterThresh = [] foodThresh = [] feedingTimers = [] relayOn = ['off', 'off'] running = 'y' sensor1 = ADC.adcMeasure(0) sensor2 = ADC.adcMeasure(1) delay = 0 threadsRunning = { 'relay': False, 'polling': False, 'waterOn': False, 'waterOff': False, 'foodOn': False, 'foodOff': False } #Relay pin setup #Must be set up as inputs, so relays stay off GPIO.setup(pins[0], GPIO.IN) GPIO.setup(pins[1], GPIO.IN)
self.windturbine_id = row['windturbine'] self.motor.changespeed(self.wind_speed, self.wing_angle) if self.brake: self.motor.brake() if self.state == 0: self.motor.stop() elif self.state == 1: self.motor.run() GPIO.cleanup() # ADC channel, clock_pin, miso_pin, mosi_pin, cs_pin adc = ADC.ADC(0, 23, 21, 19, 24) # ADC channel, clock_pin, miso_pin, mosi_pin, cs_pin adc2 = ADC.ADC(1, 23, 21, 19, 24) # IR sensor pin ir_sensor = IRSensor.IRSensor(7) # PWM pin, Standby pin, AIN1 pin, PWM Frequincy, Duty motor = Motor.Motor(3,5,11,1000, 0) # Motor, state, brake, wind_speed, wing_angle windturbine = Windturbine(motor, 0, 0, 0.0, 0.0, 0) # Database connection cnx = pymysql.connect(user='******', password='******', host='127.0.0.1', database='control_db') cursor = cnx.cursor(pymysql.cursors.DictCursor) # Windturbine data insertion statement add_data = ("INSERT INTO windturbine_data_windturbinedata (windturbine, timestamp, state, temp_gearbox, temp_generator, rpm_generator, wind_speed) VALUES (%s, %s, %s, %s, %s, %s, %s)")
def setupGUIclicked(self): ''' Control content from setup_GUI by attempting to initiate instances of the LiCor and SpectraSensor''' global comLC, comSS dlg = HardwareGUI(self) dlg.buttonBox.accepted.connect(dlg.accept) dlg.buttonBox.rejected.connect(dlg.reject) # The following executes the dialog box and returns whether it was # accepted or rejected result = dlg.exec_() if result == QtWidgets.QDialog.Accepted: '''Try to accept the changes and initialize COM ports. If unsuccessful, show a message box that request cannot be completed''' self.active = False try: # Activate DataQ DI145 comLC = dlg.lineLC.text() self.s = ADC.DataQ_DI145(comLC) self.active = True # Triggers to activate record button if one is true for button in self.lcRbuttons: button.setEnabled(True) # Look for Checkboxes # Dew Point Generator if dlg.dpGenChkBox.isChecked(): self.dpGenActive = True # use dew point generator humdity value else: # warn users if hum generator is not selected self.dpGenActive = False msg = common_def.error_msg() msg.setText( 'DataQ DI-145 is connected but Dew Point Generator is not selected' ) msg.exec_() # Temperature if dlg.tempChkBox.isChecked(): self.setTempActive = True else: self.setTempActive = False except: self.dpGenActive = False self.setTempActive = False msg = common_def.error_msg() msg.setText( 'Could NOT initialize DataQ DI-145 from port {}'.format( comLC)) msg.exec_() try: comSS = dlg.lineWVSS.text() self.ss = WVSS.WVSS_II(comSS) self.active = True # Triggers to activate record button if one is true for button in self.ssRbuttons: button.setEnabled(True) # Look for Pressure Checkbox if dlg.pressChkBox.isChecked(): self.setPressActive = True else: self.setPressActive = False except: self.setPressActive = False msg = common_def.error_msg() msg.setText( 'Could NOT initialize Water Vapor Monitor System from port {}' .format(comSS)) msg.exec_()
class GUI(Frame): def __init__(self, master): #General initialization GPIO.setwarnings(False) #disable runtime warnings GPIO.setmode(GPIO.BCM) #use Broadcom GPIO names #initialize 4 ports self._jp4 = ADC(i2cAddress, "JP4") self._jp5 = ADC(i2cAddress, "JP5") self._jp6 = ADC(i2cAddress, "JP6") self._jp7 = ADC(i2cAddress, "JP7") #GUI initialization Frame.__init__(self, master) self._master = master self._interviewing = False self._redButtonPressed = False self.pack() self._createWidgetsForCalibrateMode() ############################# # # Calibrate Mode # ############################# #Create Calibrate Widgets def _createWidgetsForCalibrateMode(self): #clean up for widget in self.winfo_children(): widget.destroy() #Set resolution self._master.geometry(str(calibrateWindowWidth)+"x"+str(calibrateWindowHeight)) #draw common widgets self._createCommonWidgets(0) self._modeMenu.place(x=self.winfo_width()/2-self._modeMenu.winfo_reqwidth()/2, y=10) #draw calibrate widgets #2 labels for SCR and RR JP5Label = Label(self) JP5Label["text"] = "SCR" JP5Label.place(x=calibrateWindowWidth/3.0-JP5Label.winfo_reqwidth()/2.0, y=self.winfo_height()/2.0 - 20) JP4Label = Label(self) JP4Label["text"] = "RR" JP4Label.place(x=2*calibrateWindowWidth/3.0-JP4Label.winfo_reqwidth()/2.0, y=self.winfo_height()/2.0 - 20) #2 labels for showing data self._JP5CaliLabel = Label(self) self._JP5CaliLabel["text"] = "No Data" self._JP5CaliLabel.place(x=calibrateWindowWidth/3.0-self._JP5CaliLabel.winfo_reqwidth()/2.0-10, y=self.winfo_height()/2.0) self._JP4CaliLabel = Label(self) self._JP4CaliLabel["text"] = "No Data" self._JP4CaliLabel.place(x=2*calibrateWindowWidth/3.0-self._JP4CaliLabel.winfo_reqwidth()/2.0+10, y=self.winfo_height()/2.0) #Thread for SCR and RR self._threadCaliRun = True self._threadUpdateJP5CaliData = Thread(target = self._updateJP5CaliLabel, args=()) self._threadUpdateJP5CaliData.start() self._threadUpdateJP4CaliData = Thread(target = self._updateJP4CaliLabel, args=()) self._threadUpdateJP4CaliData.start() #GPIO.setup(heartRatePin, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.add_event_detect(heartRatePin, GPIO.RISING, callback=self._updateHeartRateCaliData) #Thread for HR for i in ledPins: GPIO.setup(i, GPIO.OUT) GPIO.output(i, False) self._currentLED = 0 self._threadUpdateHeartRateCaliData = Thread(target = self._updateHeartRateCaliData, args=()) self._threadUpdateHeartRateCaliData.start() #RR def _updateJP5CaliLabel(self): #Loop start if self._threadCaliRun: data = self._jp5.readData() if data < 2048 - thereHold: self._JP5CaliLabel["fg"] = "red" self._JP5CaliLabel["text"] = "Decrease "+str(data-2048) elif data > 2048 + thereHold: self._JP5CaliLabel["fg"] = "red" self._JP5CaliLabel["text"] = "Increase "+str(data-2048) else: self._JP5CaliLabel["fg"] = "green" self._JP5CaliLabel["text"] = "Calibreated "+str(data-2048) self._JP5CaliLabel.place(x=calibrateWindowWidth/3.0-self._JP5CaliLabel.winfo_reqwidth()/2.0-10, y=self.winfo_height()/2.0) #Loop end self._JP5CaliLabel.after(1000, self._updateJP5CaliLabel) #SCR def _updateJP4CaliLabel(self): #Loop start if self._threadCaliRun: data = self._jp4.readData() if data < 2048 - thereHold: self._JP4CaliLabel["fg"] = "red" self._JP4CaliLabel["text"] = "Decrease "+str(data-2048) elif data > 2048 + thereHold: self._JP4CaliLabel["fg"] = "red" self._JP4CaliLabel["text"] = "Increase "+str(data-2048) else: self._JP4CaliLabel["fg"] = "green" self._JP4CaliLabel["text"] = "Calibreated "+str(data-2048) self._JP4CaliLabel.place(x=2*calibrateWindowWidth/3.0-self._JP4CaliLabel.winfo_reqwidth()/2.0+10, y=self.winfo_height()/2.0) #Loop end self._JP4CaliLabel.after(1000, self._updateJP4CaliLabel) #HR def _updateHeartRateCaliData(self): #Loop start if self._threadCaliRun: data = self._jp7.readData() self._lightUp(int(round(data/4096.0 *8))) #Loop end self.after(125, self._updateHeartRateCaliData) #Set Pi LED to ledLength def _lightUp(self, ledLength): #Error detecting if ledLength > 8: print "ledLength too large" return #Turn on or off the LED if ledLength > self._currentLED: for i in range(self._currentLED, ledLength): LED = ledPins[i] GPIO.output(LED, True) elif ledLength < self._currentLED: for i in range(ledLength, self._currentLED): LED = ledPins[ledLength + self._currentLED - 1 - i] GPIO.output(LED, False) self._currentLED = ledLength ############################# # # Interview Mode # ############################# #Create Interview Widgets def _createWidgetsForInterviewMode(self): #clean up for widget in self.winfo_children(): widget.destroy() #Set resolution self._master.geometry(str(interviewWindowWidth)+"x"+str(interviewWindowHeight)) #draw common widgets self._createCommonWidgets(1) self._modeMenu.place(x=self.winfo_width()/2-self._modeMenu.winfo_reqwidth()/2, y=10) #Set up GPIO Event GPIO.setup(redButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(redButtonPin, GPIO.RISING, callback=self._questionAsked, bouncetime=500) GPIO.setup(yellowButtonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(yellowButtonPin, GPIO.RISING, callback=self._responseGiven, bouncetime=500) self._SCRDataLabel = Label(self) self._SCRDataLabel["text"] = "SCR Data" self._SCRDataLabel.place(x=20, y=50) self._RRDataLabel = Label(self) self._RRDataLabel["text"] = "RR Data" self._RRDataLabel.place(x=20, y=75) self._HRDataLabel = Label(self) self._HRDataLabel["text"] = "HR Data" self._HRDataLabel.place(x=20, y=100) self._SSTDataLabel = Label(self) self._SSTDataLabel["text"] = "SST Data" self._SSTDataLabel.place(x=20, y=125) self._SCRFilter = IntVar() SCRFilterChk = Checkbutton(self, text="Filter", variable=self._SCRFilter) SCRFilterChk.place(x=90, y=50) self._SCRChangeRate = IntVar() SCRChangeRateChk = Checkbutton(self, text="Change Rate", variable=self._SCRChangeRate) SCRChangeRateChk.place(x=145, y=50) self._RRFilter = IntVar() RRFilterChk = Checkbutton(self, text="Filter", variable=self._RRFilter) RRFilterChk.place(x=90, y=75) self._HRInterpolate = IntVar() HRInterpolateChk = Checkbutton(self, text="Interpolate", variable=self._HRInterpolate) HRInterpolateChk.place(x=90, y=100) self._SSTFilter = IntVar() SSTFilterChk = Checkbutton(self, text="Filter", variable=self._SSTFilter) SSTFilterChk.place(x=90, y=125) #Start Button self._startInterview = Button(self) self._startInterview["text"] = "Start" self._startInterview["command"] = self._startTheInterview self._startInterview.place(x=self.winfo_width()/2-self._startInterview.winfo_reqwidth()/2, y=self.winfo_height()-35) def _startTheInterview(self): tmpSCR = [] tmpRR = [] tmpHR = [] tmpSST = [] if self._SCRFilter.get()==1: tmpSCR.append("FILTER") if self._SCRChangeRate.get()==1: tmpSCR.append("CHANGERATE") if self._RRFilter.get()==1: tmpRR.append("FILTER") if self._HRInterpolate.get()==1: tmpHR.append("INTERPOLATE") if self._SSTFilter.get()==1: tmpSST.append("FILTER") self._p = Plotter({"SCR":tmpSCR, "RR":tmpRR, "HR":tmpHR, "SST":tmpSST}) self._interviewing = True self._readData() def _readData(self): if self._interviewing: if self._redButtonPressed: self._p.addData(self._jp5.readData(), "SCR") self._p.addData(self._jp4.readData(), "RR") self._p.addData(self._jp7.readData(), "HR") self._p.addData(self._jp6.readData(), "SST") self.after(125, self._readData) else: self._p.stopPlotting() def _questionAsked(self, pin): self._redButtonPressed = True def _responseGiven(self, pin): self._redButtonPressed = False self._interviewing = False ############################# # # Common stuff # ############################# def _createCommonWidgets(self, mode): self.pack(fill=BOTH, expand=1) #Quit button self._QUIT = Button(self) self._QUIT["text"] = "Quit" self._QUIT["command"] = self._quit self.update() #update frame to get current resolution self._QUIT.place(x=self.winfo_width() - 60, y=self.winfo_height() - 35) #set at bottom right #Switch mode option menu items = ["Calibreate Mode", "Interview Mode"] self._choice = StringVar() self._choice.set(items[mode]) self._choice.trace("w", self._switchMode) self._modeMenu = OptionMenu(self, self._choice, *items) self._modeMenu.command = self._switchMode #Quit function override def _quit(self): self._threadCaliRun = False self._master.destroy() #Switch mode def _switchMode(self, *args): if self._choice.get() == "Interview Mode": self._threadCaliRun = False self._createWidgetsForInterviewMode() elif self._choice.get() == "Calibreate Mode": self._createWidgetsForCalibrateMode()