Ejemplo n.º 1
0
class MainWindow(QMainWindow, Ui_MainWindow):
    BUS_NAME = "com.tinkerforge"
    OBJECT_PATH_START = "/com/tinkerforge"
    INTERFACE_START = "com.tinkerforge"

    callback_enumerate_signal = pyqtSignal(str, str, int, bool)

    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setWindowIcon(QIcon("brickv-icon.png"))
        signal.signal(signal.SIGINT, self.exit_brickv)
        signal.signal(signal.SIGTERM, self.exit_brickv)

        self.setWindowTitle("Brick Viewer")

        self.table_view_header = ['#', 'Device Name', 'UID', 'FW Version']

        # Remove dummy tab
        self.tab_widget.removeTab(1)
        self.last_tab = 0

        self.plugins = [(self, None, None, None)]
        self.ipcon = None
        self.reset_view()
        self.button_advanced.setDisabled(True)

        self.callback_enumerate_signal.connect(self.callback_enumerate)

        self.tab_widget.currentChanged.connect(self.tab_changed)
        self.connect.pressed.connect(self.connect_pressed)
        self.button_advanced.pressed.connect(self.advanced_pressed)
        self.plugin_manager = PluginManager()

    def closeEvent(self, event):
        self.exit_brickv()

    def exit_brickv(self, signl=None, frme=None):
        if self.ipcon != None:
            self.reset_view()

        if signl != None and frme != None:
            print "Received SIGINT or SIGTERM, shutting down."
            sys.exit()

    def start(self):
        pass

    def stop(self):
        pass

    def destroy(self):
        pass

    def tab_changed(self, i):
        self.plugins[i][0].start()
        self.plugins[self.last_tab][0].stop()
        self.last_tab = i

    def reset_view(self):
        self.tab_widget.setCurrentIndex(0)
        for i in reversed(range(1, len(self.plugins))):
            try:
                self.plugins[i][0].stop()
                self.plugins[i][0].destroy()
            except AttributeError:
                pass

            self.tab_widget.removeTab(i)

        self.plugins = [(self, None, None, None)]

        self.update_table_view()

        if self.ipcon:
            self.ipcon.destroy()
        self.ipcon = None

    def advanced_pressed(self):
        if len(self.plugins) < 2:
            QMessageBox.warning(self, "Error",
                                "You have to connect at least one Brick",
                                QMessageBox.Ok)
            return

        aw = AdvancedWindow(self)
        for plugin in self.plugins[1:]:
            if ' Brick ' in plugin[2]:
                aw.combo_brick.addItem(plugin[2])
                aw.devices.append(plugin[0].device)

        aw.setAttribute(Qt.WA_QuitOnClose)
        aw.update_calibration()
        aw.show()

    def connect_pressed(self):
        if not self.ipcon:
            try:
                self.ipcon = IPConnection(self.host.text(), self.port.value())
                self.ipcon.enumerate(self.callback_enumerate_signal.emit)
                self.connect.setText("Disconnect")
                self.button_advanced.setDisabled(False)
                self.port.setDisabled(True)
                self.host.setDisabled(True)
            except (Error, socket.error):
                self.ipcon = None
                box_head = 'Could not connect'
                box_text = 'Please check host, check port and ' + \
                           'check if brickd is running.'
                QMessageBox.critical(self, box_head, box_text)
        else:
            self.reset_view()

            self.connect.setText("Connect")
            self.button_advanced.setDisabled(True)
            self.port.setDisabled(False)
            self.host.setDisabled(False)

    def callback_enumerate(self, uid, name, stack_id, is_new):
        if is_new:
            for plugin in self.plugins:
                # Plugin already loaded
                if plugin[3] == uid:
                    return
            plugin = self.plugin_manager.get_plugin_from_name(
                name, self.ipcon, uid)
            self.tab_widget.addTab(plugin, name)
            self.plugins.append((plugin, stack_id, name, uid))
        else:
            for i in range(len(self.plugins)):
                if self.plugins[i][3] == uid:
                    self.tab_widget.setCurrentIndex(0)
                    self.plugins[i][0].stop()
                    self.plugins[i][0].destroy()
                    self.tab_widget.removeTab(i)
                    self.plugins.remove(self.plugins[i])
                    self.update_table_view()
                    return

        self.update_table_view()

    def update_table_view(self):
        data = []
        for p in self.plugins[1:]:
            data.append((p[1], p[2], p[3], p[0].version))

        mtm = MainTableModel(self.table_view_header, data)
        self.table_view.setModel(mtm)
Ejemplo n.º 2
0
class MainWindow(QMainWindow, Ui_MainWindow):
    BUS_NAME = "com.tinkerforge"
    OBJECT_PATH_START = "/com/tinkerforge"
    INTERFACE_START = "com.tinkerforge"
    
    callback_enumerate_signal = pyqtSignal(str, str, int, bool)
    
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.setWindowIcon(QIcon("brickv-icon.png"))
        signal.signal(signal.SIGINT, self.exit_brickv) 
        signal.signal(signal.SIGTERM, self.exit_brickv) 
        
        self.setWindowTitle("Brick Viewer")
        
        self.table_view_header = ['#', 'Device Name', 'UID', 'FW Version']

        # Remove dummy tab
        self.tab_widget.removeTab(1)
        self.last_tab = 0
        
        self.plugins = [(self, None, None, None)]
        self.ipcon = None
        self.reset_view()
        self.button_advanced.setDisabled(True)
        
        self.callback_enumerate_signal.connect(self.callback_enumerate)
        
        self.tab_widget.currentChanged.connect(self.tab_changed)
        self.connect.pressed.connect(self.connect_pressed)
        self.button_advanced.pressed.connect(self.advanced_pressed)
        self.plugin_manager = PluginManager()
        
    def closeEvent(self, event):
        self.exit_brickv()
        
    def exit_brickv(self, signl=None, frme=None):
        if self.ipcon != None:
            self.reset_view()
            
        if signl != None and frme != None:
            print "Received SIGINT or SIGTERM, shutting down."
            sys.exit() 

    def start(self):
        pass
    
    def stop(self):
        pass
    
    def destroy(self):
        pass
        
    def tab_changed(self, i):
        self.plugins[i][0].start()
        self.plugins[self.last_tab][0].stop()
        self.last_tab = i
        
    def reset_view(self):
        self.tab_widget.setCurrentIndex(0)
        for i in reversed(range(1, len(self.plugins))):
            try:
                self.plugins[i][0].stop()
                self.plugins[i][0].destroy()
            except AttributeError:
                pass
        
            self.tab_widget.removeTab(i)
            
        self.plugins = [(self, None, None, None)]
        
        self.update_table_view()
        
        if self.ipcon:
            self.ipcon.destroy()
        self.ipcon = None
            
    def advanced_pressed(self):
        if len(self.plugins) < 2:
            QMessageBox.warning(self, "Error", "You have to connect at least one Brick", QMessageBox.Ok)
            return
        
        aw = AdvancedWindow(self)
        for plugin in self.plugins[1:]:
            if ' Brick ' in plugin[2]:
                aw.combo_brick.addItem(plugin[2])
                aw.devices.append(plugin[0].device)
        
        aw.setAttribute(Qt.WA_QuitOnClose)
        aw.update_calibration()
        aw.show()
         
    def connect_pressed(self):
        if not self.ipcon:
            try:
                self.ipcon = IPConnection(self.host.text(), self.port.value())
                self.ipcon.enumerate(self.callback_enumerate_signal.emit)
                self.connect.setText("Disconnect")
                self.button_advanced.setDisabled(False)
                self.port.setDisabled(True)
                self.host.setDisabled(True)
            except (Error, socket.error):
                self.ipcon = None
                box_head = 'Could not connect'
                box_text = 'Please check host, check port and ' + \
                           'check if brickd is running.'
                QMessageBox.critical(self, box_head, box_text)
        else:
            self.reset_view()
            
            self.connect.setText("Connect")
            self.button_advanced.setDisabled(True)
            self.port.setDisabled(False)
            self.host.setDisabled(False)
        
    def callback_enumerate(self, uid, name, stack_id, is_new):
        if is_new:
            for plugin in self.plugins:
                # Plugin already loaded
                if plugin[3] == uid:
                    return
            plugin = self.plugin_manager.get_plugin_from_name(name, 
                                                              self.ipcon, 
                                                              uid)
            self.tab_widget.addTab(plugin, name)
            self.plugins.append((plugin, stack_id, name, uid))
        else:
            for i in range(len(self.plugins)):
                if self.plugins[i][3] == uid:
                    self.tab_widget.setCurrentIndex(0)
                    self.plugins[i][0].stop()
                    self.plugins[i][0].destroy()
                    self.tab_widget.removeTab(i)
                    self.plugins.remove(self.plugins[i])
                    self.update_table_view()
                    return
                
        self.update_table_view()
    
    def update_table_view(self):
        data = []
        for p in self.plugins[1:]:
            data.append((p[1], p[2], p[3], p[0].version))
            
        mtm = MainTableModel(self.table_view_header, data)
        self.table_view.setModel(mtm)
Ejemplo n.º 3
0
    def __init__(self):
        ipcon = IPConnection()
        ipcon.connect(HOST, PORT)
            
        ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)

        ipcon.enumerate()
        i = 0
        while self.imu_uid == None:
            time.sleep(0.1)
            i += 1
            if i == 20:
                print "Didn't find IMU, exiting"
                return
        
        self.s = Servo('9TZyPftcTLE', ipcon)
        self.i = IMU(self.imu_uid, ipcon)
    
        self.s.set_output_voltage(self.SERVO_VOLTAGE)
        for servo in self.servos.values():
            self.s.set_pulse_width(servo[0], servo[1][0], servo[1][1])
            self.s.set_degree(servo[0], servo[2][0], servo[2][1])
            self.s.set_velocity(servo[0], 0xFFFF) 
            self.s.set_acceleration(servo[0], 0xFFFF) 
            self.s.set_position(servo[0], 0)
            self.s.enable(servo[0])
    
        time.sleep(1)
        
        self.write_gyr_bias()
        time.sleep(0.2)
        self.calibrate_gyr_bias()
        self.write_gyr_bias()

        self.write_gyr_gain()
        time.sleep(0.2)
        self.calibrate_gyr_gain()
        self.write_gyr_gain()
        
        self.write_acc() # default
        time.sleep(0.2)
        self.calibrate_acc()
        self.write_acc() # new calibration
        
        text = """# Each line starts with "calibration type:"
# followed by the x, y and z calibration, separated by a comma.
# Multiplier and Divider are written as "mul/div"

"""
        
        c = []
        for num in range(6):
            c.append(self.i.get_calibration(num))
            
            
        text += '0: ' + str(c[0][0]) + '/' + str(c[0][3]) + ', ' + str(c[0][1]) + '/' + str(c[0][4]) + ', ' + str(c[0][2]) + '/' + str(c[0][5])
        text += '\n'
        text += '1: ' + str(c[1][0]) + ', ' + str(c[1][1]) + ', ' + str(c[1][2])
        text += '\n'
        text += '2: ' + str(c[2][0]) + '/' + str(c[2][3]) + ', ' + str(c[2][1]) + '/' + str(c[2][4]) + ', ' + str(c[2][2]) + '/' + str(c[2][5])
        text += '\n'
        text += '3: ' + str(c[3][0]) + ', ' + str(c[3][1]) + ', ' + str(c[3][2])
        text += '\n'
        text += '4: ' + str(c[4][0]) + '/' + str(c[4][3]) + ', ' + str(c[4][1]) + '/' + str(c[4][4]) + ', ' + str(c[4][2]) + '/' + str(c[4][5])
        text += '\n'
        text += '5: ' + str(c[5][0]) + ', ' + str(c[5][1]) + ', ' + str(c[5][2]) + ', ' + str(c[5][3]) + ', ' + str(c[5][4]) + ', ' + str(c[5][5]) + ', ' + str(c[5][6]) + ', ' + str(c[5][7])
        
        f = file(self.imu_uid + '.txt', 'w')
        f.write(text)
        f.close()
Ejemplo n.º 4
0
    def __init__(self):
        ipcon = IPConnection()
        ipcon.connect(HOST, PORT)

        ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                self.cb_enumerate)

        ipcon.enumerate()
        i = 0
        while self.imu_uid == None:
            time.sleep(0.1)
            i += 1
            if i == 20:
                print "Didn't find IMU, exiting"
                return

        self.s = Servo('9TZyPftcTLE', ipcon)
        self.i = IMU(self.imu_uid, ipcon)

        self.s.set_output_voltage(self.SERVO_VOLTAGE)
        for servo in self.servos.values():
            self.s.set_pulse_width(servo[0], servo[1][0], servo[1][1])
            self.s.set_degree(servo[0], servo[2][0], servo[2][1])
            self.s.set_velocity(servo[0], 0xFFFF)
            self.s.set_acceleration(servo[0], 0xFFFF)
            self.s.set_position(servo[0], 0)
            self.s.enable(servo[0])

        time.sleep(1)

        self.write_gyr_bias()
        time.sleep(0.2)
        self.calibrate_gyr_bias()
        self.write_gyr_bias()

        self.write_gyr_gain()
        time.sleep(0.2)
        self.calibrate_gyr_gain()
        self.write_gyr_gain()

        self.write_acc()  # default
        time.sleep(0.2)
        self.calibrate_acc()
        self.write_acc()  # new calibration

        text = """# Each line starts with "calibration type:"
# followed by the x, y and z calibration, separated by a comma.
# Multiplier and Divider are written as "mul/div"

"""

        c = []
        for num in range(6):
            c.append(self.i.get_calibration(num))

        text += '0: ' + str(c[0][0]) + '/' + str(c[0][3]) + ', ' + str(
            c[0][1]) + '/' + str(c[0][4]) + ', ' + str(c[0][2]) + '/' + str(
                c[0][5])
        text += '\n'
        text += '1: ' + str(c[1][0]) + ', ' + str(c[1][1]) + ', ' + str(
            c[1][2])
        text += '\n'
        text += '2: ' + str(c[2][0]) + '/' + str(c[2][3]) + ', ' + str(
            c[2][1]) + '/' + str(c[2][4]) + ', ' + str(c[2][2]) + '/' + str(
                c[2][5])
        text += '\n'
        text += '3: ' + str(c[3][0]) + ', ' + str(c[3][1]) + ', ' + str(
            c[3][2])
        text += '\n'
        text += '4: ' + str(c[4][0]) + '/' + str(c[4][3]) + ', ' + str(
            c[4][1]) + '/' + str(c[4][4]) + ', ' + str(c[4][2]) + '/' + str(
                c[4][5])
        text += '\n'
        text += '5: ' + str(c[5][0]) + ', ' + str(c[5][1]) + ', ' + str(
            c[5][2]) + ', ' + str(c[5][3]) + ', ' + str(c[5][4]) + ', ' + str(
                c[5][5]) + ', ' + str(c[5][6]) + ', ' + str(c[5][7])

        f = file(self.imu_uid + '.txt', 'w')
        f.write(text)
        f.close()