def cb_bin_selector(self): #stop all motion before switching self.running=False self.cb_stop() # read configuration of target from qcombobox via header self.bin = read_bin_config(self.bin_selector.currentText()) if is_connected_to_device(int(self.bin['stepper_address'],16)): self.controls_group.setEnabled(True) self.bin_status.addItem('[info] {} ready.'.format(self.bin['name'])) self.stepper = Stepper(self.bin['name'], int(self.bin['stepper_address'], 16), self.bin['stepper_port'],int(self.bin['io_address'],16) ,self.bin['pin_low_limit_sns'], self.bin['pin_high_limit_sns']) else: self.controls_group.setEnabled(False) self.bin_status.addItem('[ERR ] {} not ready.'.format(self.bin['name'])) if self.bin['enabled']: self.controls_group.setEnabled(True) self.bin_status.addItem('[info] {} enabled.'.format(self.bin['name'])) else: self.controls_group.setEnabled(False) self.bin_status.addItem('[info] {} disabled'.format(self.bin['name']))
def __init__(self, dialog): Ui_Controller.__init__(self) self.setupUi(dialog) self.running=False # Step 1a : register callbacks for user interface events and sensors self.pb_to_top.clicked.connect(self.thread_to_top) self.pb_up.clicked.connect(self.cb_up) self.pb_cycle.clicked.connect(self.thread_cycle) self.pb_stop.clicked.connect(self.cb_stop) self.pb_down.clicked.connect(self.cb_down) self.pb_to_bottom.clicked.connect(self.thread_to_bottom) self.pb_clear.clicked.connect(self.cb_clear) self.pb_e_stop.clicked.connect(self.cb_e_stop) self.bin_selector.currentIndexChanged.connect(self.cb_bin_selector) # register 0 to 1 'rising edge' edge detector callback self.detector_high_limit_sns = EdgeTrigger(self.cb_high_limit_sns) self.detector_low_limit_sns = EdgeTrigger(self.cb_low_limit_sns) # create main hardware object # name, stepper_address, stepper_port,servo_address,servo_port,io_address pin_low_level_sns, pin_high_level_sns, pin_top_level_sns,enabled #read bin configuration of default target, default is Bin-1 self.bin=read_bin_config('Bin0') # check and create a list of dices self.i2c_list = list_of_i2c_steppers() self.bin_status.addItem('[info] {}'.format(self.i2c_list)) self.bin_status.addItem('[info] {} devices detected.'.format(len(self.i2c_list))) #check and create default setup if self.bin['enabled']: # from configuration self.controls_group.setEnabled(True) self.bin_status.addItem('[info] {} enabled'.format(self.bin['name'])) else: self.controls_group.setEnabled(False) self.bin_status.addItem('[info] {} disabled'.format(self.bin['name'])) if is_connected_to_device(int(self.bin['stepper_address'],16)): self.controls_group.setEnabled(True) self.bin_status.addItem('[info] {} ready.'.format(self.bin['name'])) self.stepper = Stepper(self.bin['name'],int(self.bin['stepper_address'],16),self.bin['stepper_port'],int(self.bin['io_address'],16) ,self.bin['pin_low_limit_sns'],self.bin['pin_high_limit_sns']) self.stepper.start() else: self.controls_group.setEnabled(False) self.bin_status.addItem('[ERR ] {} not ready.'.format(self.bin['name'])) # create IO object #TODO do as above self.expander = PCA9555(int(self.bin['io_address'],16)) # max counts interleaved mode for progress bar display self.cnt_max = 5650 # initil calibration value self.cnt = 0
def cb_input_selector(self): # read configuration of target from qcombobox via header # and convert to hex address self.address = int(self.input_selector.currentText(),16) if is_connected_to_device(self.address): self.led_status.addItem('[info] {} ready.'.format(hex(self.address))) self.ioExpander = PCA9555(self.address) #self.ioExpander.setInputDirection(0xFFFF) # all pins else: self.led_status.addItem('[ERR ] {} not ready.'.format(hex(self.address)))
def cb_bin_selector(self): # read configuration of target from qcombobox via header # and convert to hex address # add how to get from bin1 to object creation self.servo = read_bin_config(self.bin_selector.currentText()) if is_connected_to_device(int(self.servo['servo_address'], 16)): self.ejector_status.addItem('[info] {} ready.'.format( self.servo['name'])) self.ejector = Ejector(self.servo['name'], int(self.servo['servo_address'], 16), self.servo['servo_port']) self.led_ready.setEnabled(1) self.ejector.start() else: self.led_ready.setEnabled(0) self.ejector_status.addItem('[ERR ] {} not ready.'.format( self.servo['name']))
else: wiringpi.digitalWrite(PIFACE + 2,0) # Step 3c : register edge detection status changes for all 3 sensors self.detector_high_limit_sns(self.expander.digitalRead(self.bin['pin_high_limit_sns'])) self.detector_low_limit_sns(self.expander.digitalRead(self.bin['pin_low_limit_sns'])) # main program start # initalize the io hardware interfaces # expander.init() piface.init() #check if i2c bus devices are present if not is_connected_to_device(0x70): print "no stepper i2c device found!" #sys.exit(1) # create user interface MyBinControl app = QtWidgets.QApplication(sys.argv) dialog = QtWidgets.QTabWidget() prog = MyBinControl(dialog) dialog.show() # setup timers to run heartbeat every 1/2 sec timer = QtCore.QTimer() timer.timeout.connect(prog.watchdog) timer.start(500)