Example #1
0
def main(serial_id):
    port = SerialPort(serial_id)
    monitor = DockerMonitor()

    signal.signal(signal.SIGINT, signal_handler)
    print('Welcome to TX')
    print_help()

    readline.parse_and_bind("tab:complete")
    readline.set_completer(completer)
    while True:
        user_input = input('#: ')
        tokens = user_input.split()
        global commands
        commands = commands + monitor.get_tags()

        if len(tokens) == 0:
            continue

        cmd = tokens[0]

        if cmd == 'help':
            print_help()
        elif cmd == 'tags':
            port.write(cmd)
        elif cmd == 'exit':
            break
        elif cmd == 'run':
            if len(tokens) < 2:
                tag = 'latest'
            else:
                tag = tokens[1]
            port.write(cmd + ' ' + tag)
        elif cmd == 'pull':
            if len(tokens) < 2:
                tag = 'latest'
            else:
                tag = tokens[1]
            port.write(cmd + ' ' + tag)
        elif cmd == 'clean':
            port.write(cmd)
        elif cmd == 'reboot':
            port.write(cmd)
        else:
            print('Unknown command: {}'.format(cmd))
            continue

        # Wait for and print all messages received from rx
        wait_for_end_of_message_or_print(port)

    # Close port on exit
    port.close()
    monitor.close()
Example #2
0
def main():
    port = SerialPort("/dev/acrobat/radio")
    monitor = DockerMonitor()

    print("Sending start up lights")
    port.send_start()
    time.sleep(1)
    print("Done. Ready for user input")

    while True:
        user_input = port.read()
        tokens = user_input.split()

        if len(tokens) == 0:
            continue

        cmd = tokens[0]

        if cmd == 'run':
            exec_run(port, monitor, tokens)
        elif cmd == 'pull':
            exec_pull(port, monitor, tokens)
        elif cmd == 'tags':
            exec_tags(port, monitor)
        elif cmd == 'clean':
            exec_clean(port, monitor)
        elif cmd == 'reboot':
            exec_reboot(port, monitor)
        else:
            port.write('Unknown command: {}'.format(cmd))

        # End of command execution
        port.send_end_of_command()

    port.close()
    monitor.close()
Example #3
0
class MainWindow(object):
    def __init__(self):
        # setup window
        self.window = QMainWindow()
        self.main_ui = Ui_mainWindow()
        self.main_ui.setupUi(self.window)
        self.main_ui.retranslateUi(self.window)

        self.imageModeWindow = ImageModeWindow(self.window, self.main_ui)
        self.videoModeWindow = VideoModeWindow(self.window, self.main_ui)
        self.screenModeWindow = ScreenModeWindow(self.window, self.main_ui)

        # BW image to bytes instance
        self.image_to_bw = BWImageToBytes()

        # image processing
        self.image_translator = ImageTranslate()
        self.image_translator.start()

        self.connectSignal()

        # show window
        self.window.show()

    def connectSignal(self):
        # connect serial port widgets
        self.main_ui.pbt_scanSerialPort.clicked.connect(self.portScan)
        self.main_ui.combox_serialPortList.activated.connect(self.portSelect)
        self.main_ui.pbt_serialOpen.clicked.connect(self.portOpen)
        self.portOpened = False
        # connect display setting
        self.main_ui.spinBox_displayRow.valueChanged.connect(self.displayColumnRowSetting)
        self.main_ui.spinBox_displayCol.valueChanged.connect(self.displayColumnRowSetting)
        self.main_ui.checkBox_displayFlipH.clicked.connect(self.displayFlipModeSetting)
        self.main_ui.checkBox_displayFlipV.clicked.connect(self.displayFlipModeSetting)
        self.main_ui.comboBox_displayScanDirection.activated.connect(self.displayScanDirectionSetting)
        self.main_ui.comboBox_displayByteDirection.activated.connect(self.displayByteDirectionSetting)
        self.main_ui.comboBox_displaySignBit.activated.connect(self.displaySignBitSetting)
        self.displaySettingInit()
        # connect binarization setting
        self.main_ui.radioButton_binarizationThreshold.clicked.connect(self.binarizationSetting)
        self.main_ui.radioButton_binarizationDither.clicked.connect(self.binarizationSetting)
        self.main_ui.comboBox_ditherBayerSize.activated.connect(self.binarizationSetting)
        self.binarizationSetting()

    def portScan(self):
        portList = SerialPort.getDeviceList()
        self.main_ui.combox_serialPortList.clear()
        for portInfo, port in portList:
            self.main_ui.combox_serialPortList.addItem(portInfo, port)

    def portSelect(self):
        self.port = self.main_ui.combox_serialPortList.currentData()
        self.baudrate = self.main_ui.spinBox_baudrate.value()

    def portOpen(self):
        if self.portOpened == False:
            try:
                self.serial = SerialPort(self.port, self.baudrate)
                self.portOpened = True
                self.main_ui.pbt_serialOpen.setText('Close')
                self.imageModeWindow.addSendMethod(self.serial)
                self.videoModeWindow.addSendMethod(self.serial)
                self.screenModeWindow.addSendMethod(self.serial)
            except Exception:
                print('Serial port open false.')
        else:
            try:
                self.serial.close()
                self.serial = None
                self.portOpened = False
                self.main_ui.pbt_serialOpen.setText('Open')
                self.imageModeWindow.addSendMethod(None)
            except Exception:
                print('Serial port close false.')

    def binarizationSetting(self):
        if self.main_ui.radioButton_binarizationThreshold.isChecked():
            self.image_translator.set_dither_enable(False)
        else:
            self.image_translator.set_dither_enable(True)
            size_str = self.main_ui.comboBox_ditherBayerSize.currentText()
            size = int(size_str[:-1])
            self.image_translator.set_dither_size(size)

    def displaySettingInit(self):
        self.displayColumnRowSetting()
        self.displayFlipModeSetting()
        self.displayScanDirectionSetting()
        self.displayByteDirectionSetting()
        self.displaySignBitSetting()

    def displayColumnRowSetting(self):
        col = self.main_ui.spinBox_displayCol.value()
        row = self.main_ui.spinBox_displayRow.value()
        self.image_translator.set_output_size(col, row)

    def displayFlipModeSetting(self):
        flip_h = self.main_ui.checkBox_displayFlipH.isChecked()
        flip_v = self.main_ui.checkBox_displayFlipV.isChecked()
        self.image_to_bw.setHorizontalFlip(flip_h)
        self.image_to_bw.setVerticalFlip(flip_v)

    def displayScanDirectionSetting(self):
        scan_direction = self.main_ui.comboBox_displayScanDirection.currentText()
        if scan_direction == 'Horizontal':
            dir = 'H'
        else:
            dir = 'V'
        self.image_to_bw.setScanDirection(dir)

    def displayByteDirectionSetting(self):
        byte_direction = self.main_ui.comboBox_displayByteDirection.currentText()
        if byte_direction == 'Horizontal':
            dir = 'H'
        else:
            dir = 'V'
        self.image_to_bw.setByteDirection(dir)

    def displaySignBitSetting(self):
        sign_bit = self.main_ui.comboBox_displaySignBit.currentText()
        self.image_to_bw.setSignBit(sign_bit)

    def exit(self):
        if self.portOpened:
            self.serial.close()
        self.imageModeWindow.exit()
        self.videoModeWindow.exit()
        self.screenModeWindow.exit()
        self.image_translator.stop()