Exemplo n.º 1
0
def runProgOutput(console, cmdline):
	sout = ""
	logging.debug("CMD:-%s", cmdline)
	try:
		p = subprocess.Popen(cmdline,
			stdout = subprocess.PIPE,
			stderr = subprocess.STDOUT,
			stdin = subprocess.PIPE,
			close_fds = True)
		poll = select.poll()
		poll.register(p.stdout, select.POLLIN)
		while gtk.events_pending():
			gtk.main_iteration()
		while True:
			o = p.stdout.readline()
			if o == '' and p.poll() != None: break
			pr = prefs.preferences()
			if pr.getBoolValue("build.verbose"):
				printMessageLn(console, o)
				sys.stderr.write(o)
			sout += o
		if p.poll()==1: raise
	except:
		logging.debug("ERR:%s", sout)
		return False
	return True
Exemplo n.º 2
0
def runProgOutput(console, cmdline):
    sout = ""
    logging.debug("CMD:-%s", cmdline)
    try:
        p = subprocess.Popen(
            cmdline, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, close_fds=True
        )
        poll = select.poll()
        poll.register(p.stdout, select.POLLIN)
        while gtk.events_pending():
            gtk.main_iteration()
        while True:
            o = p.stdout.readline()
            if o == "" and p.poll() != None:
                break
            pr = prefs.preferences()
            if pr.getBoolValue("build.verbose"):
                printMessageLn(console, o)
                sys.stderr.write(o)
            sout += o
        if p.poll() == 1:
            raise
    except:
        logging.debug("ERR:%s", sout)
        return False
    return True
Exemplo n.º 3
0
 def __init__(self):
     global client
     self.board = 0
     self.boards = []
     self.programmers = []
     self.defaults = []
     try:
         self.boards.extend(self.readCustomBoards())
     except:
         pass
     try:
         self.boards.extend(self.readArduinoBoards())
     except:
         self.boards.extend(misc.readGnoduinoConfFile("BOARDS"))
     #renumber ids in case we grown with customs
     for i in range(len(self.boards)):
         self.boards[i]['id'] = i + 1
     self.p = prefs.preferences()
     if config.cur_board == -1:
         """error can occur when placing different types of hardware in sketchdir"""
         try:
             config.cur_board = self.getBoardIdByName(
                 self.p.getSafeValue("board", "uno")) - 1
         except:
             config.cur_board = self.getBoardIdByName("uno") - 1
Exemplo n.º 4
0
    def __init__(self):
        self.programmers = []
        self.defaults = []

        try:
            self.programmers.extend(self.readCustomProgrammers())
        except:
            pass
        try:
            self.programmers.extend(self.readArduinoProgrammers())
        except:
            self.programmers.extend(misc.readGnoduinoConfFile("PROGRAMMERS"))

        #renumber ids in case we grown with customs
        for i in range(len(self.programmers)):
            self.programmers[i]['id'] = i + 1

        self.p = prefs.preferences()
        if config.cur_programmer == -1:
            try:
                config.cur_programmer = self.getProgrammerIdByName(
                    self.p.getSafeValue("programmer",
                                        "arduino:avrispmkii")) - 1
            except:
                config.cur_programmer = self.getProgrammerIdByName(
                    "arduino:avrispmkii") - 1
Exemplo n.º 5
0
def createsrcview(status, f=None):
	sbuffer = gtksourceview2.Buffer()
	if f:
		content = file(f).read()
		sbuffer.set_language(get_lang_for_content(content))
		text = unicode(content, 'utf-8', 'ignore')
		sbuffer.set_text(text)
	else:
		manager = gtksourceview2.language_manager_get_default()
		sbuffer.set_language(manager.get_language("c"))
	sv = gtksourceview2.View(sbuffer)
	p = prefs.preferences()
	misc.set_widget_font(sv, config.cur_editor_font)
	manager = gtksourceview2.StyleSchemeManager()
	manager.append_search_path(misc.getArduinoUiPath())
	manager.force_rescan()
	scheme =  manager.get_scheme("arduino")
	sbuffer.set_style_scheme(scheme);
	sv.set_size_request(300, 100)
	sv.set_editable(True)
	sv.set_auto_indent(True)
	if config.show_numbers == 'true':
		sv.set_show_line_numbers(True)
	sv.set_cursor_visible(True)
	sv.set_wrap_mode(gtk.WRAP_CHAR)
	sv.set_right_margin_position(80)
	updatePos(sbuffer, status)
	sbuffer.connect("mark_set", markCb, status)
	sbuffer.connect("insert_text", instextCallback)
	sv.set_highlight_current_line(True)
	resetCursor(sbuffer)
	return sbuffer, sv
Exemplo n.º 6
0
def upload(obj, serial, output, notify):
	p = prefs.preferences()
	pgm = programmer.Programmer()
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Flashing..."))
	b = board.Board()
	compline=[i for i in avr]
	protocol = b.getPGM(b.getBoard())
	# avrdude wants "stk500v1" to distinguish it from stk500v2
	if protocol == "stk500": protocol = "stk500v1"
	if protocol == "" or config.force_protocol is True:
		protocol =  pgm.getProtocol(pgm.getProgrammer())
		try:
			comm = pgm.getCommunication(pgm.getProgrammer())
			if comm == "serial":
				port = serial.getConfigSerialPort(notify, output)
				if port == -1:
					notify.pop(context)
					notify.push(context, _("Flashing error."))
					return
				serial.resetBoard()
				compline.append("-P" + port)
			else: compline.append("-P" + comm)
			try:
				compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
			except: pass
		except: pass
	else:
		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		serial.resetBoard()
	compline.append("-c" + protocol)
	try:
		compline.append("-b" + b.getPGMSpeed(b.getBoard()))
	except: pass
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-Uflash:w:"+obj+".hex:i")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Flashing Error"), _("Flash ERROR.\n"))
		return
	notify.pop(context)
	notify.push(context, _("Flashing complete."))
	misc.printMessageLn(output, \
		"Flash OK.");
Exemplo n.º 7
0
	def readCustomBoards(self):
		custom = []
		p = prefs.preferences()
		d = os.path.join(p.getValue("sketchbook.path"), "hardware")
		try:
			for i in os.listdir(d):
				if os.path.exists(os.path.join(d, i, "boards.txt")):
					custom.extend(misc.readArduinoConfFile(os.path.join(d, i, "boards.txt")))
			return custom
		except:	return None
Exemplo n.º 8
0
 def readCustomProgrammers(self):
     custom = []
     p = prefs.preferences()
     d = os.path.join(p.getValue("sketchbook.path"), "hardware")
     try:
         for i in os.listdir(d):
             if os.path.exists(os.path.join(d, i, "programmers.txt")):
                 custom.extend(
                     misc.readArduinoConfFile(
                         os.path.join(d, i, "programmers.txt")))
         return custom
     except:
         return None
Exemplo n.º 9
0
	def __init__(self):
		self.programmers = []
		self.defaults = []

		try:
			self.programmers.extend(self.readCustomProgrammers())
		except: pass
		try:
			self.programmers.extend(self.readArduinoProgrammers())
		except:	self.programmers.extend(misc.readGnoduinoConfFile("PROGRAMMERS"))

		#renumber ids in case we grown with customs
		for i in range(len(self.programmers)): self.programmers[i]['id'] = i+1

		self.p = prefs.preferences()
		if config.cur_programmer == -1:
			try:
				config.cur_programmer = self.getProgrammerIdByName(self.p.getSafeValue("programmer", "arduino:avrispmkii")) - 1
			except:
				config.cur_programmer = self.getProgrammerIdByName("arduino:avrispmkii") - 1
Exemplo n.º 10
0
	def __init__(self):
		global client
		self.board = 0
		self.boards = []
		self.programmers = []
		self.defaults = []
		try:
			self.boards.extend(self.readCustomBoards())
		except: pass
		try:
			self.boards.extend(self.readArduinoBoards())
		except:
			self.boards.extend(misc.readGnoduinoConfFile("BOARDS"))
		#renumber ids in case we grown with customs
		for i in range(len(self.boards)): self.boards[i]['id'] = i+1
		self.p = prefs.preferences()
		if config.cur_board == -1:
			"""error can occur when placing different types of hardware in sketchdir"""
			try:
				config.cur_board = self.getBoardIdByName(self.p.getSafeValue("board", "uno")) - 1
			except:
				config.cur_board = self.getBoardIdByName("uno") - 1
Exemplo n.º 11
0
def burnBootloader(serial, output, notify, id):
	p = prefs.preferences()
	misc.clearConsole(output)
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Burning bootloader..."))
	b = board.Board()
	compline=[i for i in avr_bl]
	pgm = programmer.Programmer()
	if pgm.getCommunication(id) == 'serial':
        	port = serial.getConfigSerialPort(notify, output)
	        if port != -1:
        	        serial.resetBoard()
        	"""De-fuse and erase board"""

		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-c" + pgm.getProtocol(id))
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
	if b.getBoardMCU(b.getBoard()) != 'atmega8':
		compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
	compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
	compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	"""Burn and fuse board"""
	compline=[i for i in avr_bl]
	compline.append("-c" + pgm.getProtocol(id))
	if pgm.getCommunication(id) == 'serial':
		port = serial.getConfigSerialPort(notify, output)
		if port == -1:
			notify.pop(context)
			notify.push(context, _("Flashing error."))
			return
		compline.append("-P" + port)
		if pgm.getSpeed(id) != 0:
			compline.append("-b" + pgm.getSpeed(id))
	elif pgm.getCommunication(id) == 'usb':
		compline.append("-Pusb")
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-e")
	if pgm.getForce(id) == 'true':
		compline.append("-F")
	compline.append("-Uflash:w:" + findBootLoader() + ":i")
	compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
		return
	notify.pop(context)
	notify.push(context, _("Burn complete."))
	misc.printMessageLn(output, \
		"Burn OK.");
Exemplo n.º 12
0
def upload(obj, serial, output, notify, force_protocol):
	p = prefs.preferences()
	pgm = programmer.Programmer()
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Flashing..."))
	b = board.Board()
	compline=[i for i in avr]
	protocol = b.getPGM(b.getBoard())
	# avrdude wants "stk500v1" to distinguish it from stk500v2
	if protocol == "stk500": protocol = "stk500v1"
	# if we do not get any protocol back probably means board doesn't
	# enforce any particular programmer
	if protocol == "" or force_protocol is True:
		#try selected programmer (via menu)
		protocol =  pgm.getProtocol(pgm.getProgrammer())
		try:
			comm = pgm.getCommunication(pgm.getProgrammer())
			if comm:
				if comm == "serial":
					port = serial.getConfigSerialPort(notify, output)
					if port == -1:
						notify.pop(context)
						notify.push(context, _("Flashing error."))
						return
					serial.resetBoard()
					compline.append("-P" + port)
				else: compline.append("-P" + comm)
				try:
					compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
				except: pass
		except: pass
	else:
		if protocol != "usbtiny":	#usbtiny works via spi, need to do some device parsing here
			port = serial.getConfigSerialPort(notify, output)
			if port == -1:
				notify.pop(context)
				notify.push(context, _("Flashing error."))
				return
			compline.append("-P" + port)
			serial.resetBoard(b.getPath(b.getBoard()))
	compline.append("-c" + protocol)
	try:
		compline.append("-b" + b.getPGMSpeed(b.getBoard()))
	except: pass
	compline.append("-p" + b.getBoardMCU(b.getBoard()))
	compline.append("-Uflash:w:"+obj+".hex:i")
	try:
		if p.getBoolValue("upload.verbose"):
			sys.stderr.write(' '.join(compline)+"\n")
			misc.printMessageLn(output, ' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"), 'false')
		if p.getBoolValue("upload.verbose"): sys.stderr.write(sout+"\n")
		if run == False: raise
	except:
		misc.printErrorLn(notify, output, _("Flashing Error"), _("Flash ERROR.\n"))
		return
	notify.pop(context)
	notify.push(context, _("Flashing complete."))
	misc.printMessageLn(output, \
		"Flash OK.");
Exemplo n.º 13
0
def run():
    try:
        global gui
        global mainwin
        global sb2
        global ser
        global id
        global nb
        global tw
        global sctw
        global sb
        global sertime
        global vbox
        global con
        global scon
        global p
        global b
        global pgm
        global recentmanager
        locale_path = _search_locales()
        gettext.bindtextdomain(APP_NAME, locale_path)
        gettext.textdomain(APP_NAME)
        locale.bindtextdomain(APP_NAME, locale_path)
        #global spinner
        #perform cleanup prior to this
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        id = misc.makeWorkdir()
        ser = serialio.sconsole()
        p = prefs.preferences()
        recentmanager = gtk.recent_manager_get_default()
        sertime = None
        gui = gtk.Builder()
        gui.set_translation_domain(APP_NAME)
        try:
            path = os.path.join(os.getcwd(), "ui", "main.ui")
            if os.path.exists(path):
                gui.add_from_file(path)
            else:
                raise NameError(_("System error"))
        except:
            try:
                path = os.path.join(sys.prefix, "local", "share", "gnoduino",
                                    "ui", "main.ui")
                if os.path.exists(path):
                    gui.add_from_file(path)
                else:
                    raise NameError(_("System error"))
            except:
                try:
                    path = os.path.join(sys.prefix, "share", "gnoduino", "ui",
                                        "main.ui")
                    if os.path.exists(path):
                        gui.add_from_file(path)
                    else:
                        raise NameError(_("System error"))
                except Exception, e:
                    print(e)
                    raise SystemExit(_("Cannot load ui file"))
        mainwin = gui.get_object("top_win")
        mainwin.set_icon_from_file(misc.getPixmapPath("gnoduino.png"))
        mw = int(p.getSafeValue("default.window.width", 640))
        mh = int(p.getSafeValue("default.window.height", 480))
        if (mw and mh):
            mainwin.set_default_size(mw, mh)
        mainwin.connect("configure-event", cb_configure_event)
        mainwin.connect("key-press-event", getKeyPEvent)
        mainwin.connect("key-release-event", getKeyREvent)
        vbox = gui.get_object("vpan")
        sb = gui.get_object("statusbar1")
        sb.set_has_resize_grip(False)
        sb2 = gui.get_object("statusbar2")
        sb2.set_has_resize_grip(False)
        setupSpinner()
        config.cur_editor_font = p.getSafeValue(
            "editor.font", p.getDefaultValue("editor.font")).replace(",", " ")
        config.cur_console_font = p.getSafeValue(
            "console.font",
            p.getDefaultValue("console.font")).replace(",", " ")
        config.build_verbose = p.getSafeValue(
            "build.verbose", p.getDefaultValue("build.verbose"))
        config.show_numbers = p.getSafeValue("show.numbers",
                                             p.getDefaultValue("show.numbers"))
        config.user_library = p.getValue("user.library")
        menu(gui)
        """build menus"""
        sub = gtk.Menu()
        b = board.Board()
        pgm = programmer.Programmer()
        maingroup = gtk.RadioMenuItem(None, None)
        for i in b.getBoards():
            menuItem = gtk.RadioMenuItem(maingroup, i['desc'])
            if i['id'] == b.getBoard() + 1:
                menuItem.set_active(True)
            menuItem.connect('toggled', selectBoard, i['id'])
            sub.append(menuItem)
        gui.get_object("board").set_submenu(sub)
        (con, tw) = createCon()
        misc.setConsoleTags(tw)
        """setup default serial port"""
        if config.serial_baud_rate == -1:
            config.serial_baud_rate = p.getSafeValue(
                "serial.debug_rate", p.getDefaultValue("serial.debug_rate"))
        getSerialPorts()
        populateSerialPortMenu()
        glib.timeout_add(1000, getSerialPorts)
        createRecentMenu()
        populateExamples()
        populateImport()

        sub = gtk.Menu()
        maingroup = gtk.RadioMenuItem(None, None)
        for i in pgm.getProgrammers():
            menuItem = gtk.RadioMenuItem(maingroup, i['desc'])
            if i['id'] == pgm.getProgrammer() + 1:
                menuItem.set_active(True)
            menuItem.connect('activate', selectProgrammer, i['id'])
            sub.append(menuItem)
        gui.get_object("programmer").set_submenu(sub)
        gui.get_object("burn").connect('activate', burnBootloader)

        nb = gtk.Notebook()
        nb.connect("switch-page", setupPage)
        sv = createPage(nb)
        vbox.pack1(nb, shrink=True, resize=True)
        (scon, sctw) = createScon()
        vbox.pack2(con, shrink=False, resize=False)
        vbox.connect("notify::position", vbox_move_handle)
        cpos = int(p.getSafeValue("console.height", mh - 120))
        vbox.set_position(cpos)

        mainwin.set_focus(sv)
        mainwin.show_all()
        mainwin.connect("delete-event", quit)
        gui.get_object("ser_monitor").connect("activate", cserial, sertime,
                                              sctw)
        gui.get_object("serial").connect("clicked", cserial, sertime, sctw)
        gui.get_object("upload").connect("clicked", upload, ser)
        for i in buttons:
            w = gtk.Image()
            w.set_from_file(misc.getPixmapPath(i[1]))
            o = gui.get_object(i[0])
            o.set_icon_widget(w)
            o.show_all()
            if i[2] != None:
                o.connect("clicked", i[2])
        if (sys.argv[1:]):
            if sys.argv[1:][0] == "--help" or sys.argv[1:][0] == "-h":
                print _("--help    Print the command line options")
                print _("--version Output version information and exit")
                sys.exit(0)
            if sys.argv[1:][0] == "--version" or sys.argv[1:][0] == "-v":
                print "gnoduino %s" % gnoduino.__version__
                sys.exit(0)
            for f in sys.argv[1:]:
                processFile(f)
        gtk.main()
Exemplo n.º 14
0
def preferences(widget, data=None):
    pref = gui.get_object("preferences")
    fe = gui.get_object("fontbutton1")
    fc = gui.get_object("fontbutton2")
    bv = gui.get_object("build.verbose")
    uv = gui.get_object("upload.verbose")
    sn = gui.get_object("show.numbers")
    ul = gui.get_object("user.library")
    sd = gui.get_object("sketchdir")
    p = prefs.preferences()
    fe.set_font_name(misc.merge_font_name(fe, config.cur_editor_font))
    fc.set_font_name(misc.merge_font_name(fc, config.cur_console_font))
    val = 0
    if config.build_verbose != -1:
        if config.build_verbose == 'true':
            val = 1
    else:
        if p.getSafeValue("build.verbose", "false") == 'true':
            val = 1
    bv.set_active(val)
    val = 0
    if config.upload_verbose != -1:
        if config.upload_verbose == 'true':
            val = 1
    else:
        if p.getSafeValue("upload.verbose", "false") == 'true':
            val = 1
    uv.set_active(val)
    val = 0
    if config.show_numbers != -1:
        if config.show_numbers == 'true':
            val = 1
    else:
        if p.getSafeValue("show.numbers", "false") == 'true':
            val = 1
    sn.set_active(val)
    if (config.user_library != None and config.user_library != -1):
        ul.set_text(str(config.user_library))
    else:
        ul.set_text(str(p.getSafeValue("user.library", "")))

    if (config.sketchdir != None and config.sketchdir != -1):
        sd.set_filename(str(config.sketchdir))
    else:
        sd.set_filename(str(p.getSafeValue("sketchbook.path", "")))
    r = pref.run()
    if r == 1:
        config.cur_editor_font = fe.get_font_name()
        p.setValue("editor.font", config.cur_editor_font.replace(" ", ","))
        config.cur_console_font = fc.get_font_name()
        p.setValue("console.font", config.cur_console_font.replace(" ", ","))
        config.user_library = ul.get_text()
        if bv.get_active() == 1:
            config.build_verbose = 'true'
        else:
            config.build_verbose = 'false'
        p.setValue("build.verbose", config.build_verbose)
        if uv.get_active() == 1:
            config.upload_verbose = 'true'
        else:
            config.upload_verbose = 'false'
        p.setValue("upload.verbose", config.upload_verbose)
        if sn.get_active() == 1:
            config.show_numbers = 'true'
        else:
            config.show_numbers = 'false'
        p.setValue("show.numbers", config.show_numbers)
        for i in range(nb.get_n_pages()):
            sv = nb.get_nth_page(i).get_data("view")
            if (config.show_numbers == 'true'):
                sv.set_show_line_numbers(True)
            else:
                sv.set_show_line_numbers(False)
        p.setValue("user.library", config.user_library)
        p.setValue("sketchbook.path", sd.get_filename())
        p.saveValues()
        misc.set_widget_font(tw, config.cur_console_font)
        misc.set_widget_font(sctw, config.cur_console_font)
        misc.set_widget_font(getCurrentView(), config.cur_editor_font)
    pref.hide()
Exemplo n.º 15
0
def compile(tw, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.extend(["-I"+os.getcwd()])
		try:
			localDir = os.path.dirname(tw.get_data("file"))
			compline.extend(["-I"+localDir])
			compline.extend(["-I"+os.path.abspath(os.path.join(localDir, ".."))])
		except: pass
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj
Exemplo n.º 16
0
def preferences(widget, data=None):
	pref = gui.get_object("preferences")
	fe = gui.get_object("fontbutton1")
	fc = gui.get_object("fontbutton2")
	bv = gui.get_object("build.verbose")
	uv = gui.get_object("upload.verbose")
	sn = gui.get_object("show.numbers")
	ul = gui.get_object("user.library")
	sd = gui.get_object("sketchdir")
	p = prefs.preferences()
	fe.set_font_name(misc.merge_font_name(fe, config.cur_editor_font))
	fc.set_font_name(misc.merge_font_name(fc, config.cur_console_font))
	val = 0
	if config.build_verbose != -1:
		if config.build_verbose == 'true':
			val = 1
	else:
		if p.getSafeValue("build.verbose", "false") == 'true':
			val = 1
	bv.set_active(val)
	val = 0
	if config.upload_verbose != -1:
		if config.upload_verbose == 'true':
			val = 1
	else:
		if p.getSafeValue("upload.verbose", "false") == 'true':
			val = 1
	uv.set_active(val)
	val = 0
	if config.show_numbers != -1:
		if config.show_numbers == 'true':
			val = 1
	else:
		if p.getSafeValue("show.numbers", "false") == 'true':
			val = 1
	sn.set_active(val)
	if (config.user_library != None and config.user_library != -1):
		ul.set_text(str(config.user_library))
	else:
		ul.set_text(str(p.getSafeValue("user.library", "")))

	if (config.sketchdir != None and config.sketchdir != -1):
		sd.set_filename(str(config.sketchdir))
	else:
		sd.set_filename(str(p.getSafeValue("sketchbook.path", "")))
	r = pref.run()
	if r == 1:
		config.cur_editor_font = fe.get_font_name()
		p.setValue("editor.font", config.cur_editor_font.replace(" ", ","))
		config.cur_console_font = fc.get_font_name()
		p.setValue("console.font", config.cur_console_font.replace(" ", ","))
		config.user_library = ul.get_text()
		if bv.get_active() == 1:
			config.build_verbose = 'true'
		else:
			config.build_verbose = 'false'
		p.setValue("build.verbose", config.build_verbose)
		if uv.get_active() == 1:
			config.upload_verbose = 'true'
		else:
			config.upload_verbose = 'false'
		p.setValue("upload.verbose", config.upload_verbose)
		if sn.get_active() == 1:
			config.show_numbers = 'true'
		else:
			config.show_numbers = 'false'
		p.setValue("show.numbers", config.show_numbers)
		for i in range(nb.get_n_pages()):
			sv = nb.get_nth_page(i).get_data("view")
			if (config.show_numbers == 'true'):
				sv.set_show_line_numbers(True)
			else:
				sv.set_show_line_numbers(False)
		p.setValue("user.library", config.user_library)
		p.setValue("sketchbook.path", sd.get_filename())
		p.saveValues()
		misc.set_widget_font(tw, config.cur_console_font)
		misc.set_widget_font(sctw, config.cur_console_font)
		misc.set_widget_font(getCurrentView(), config.cur_editor_font)
	pref.hide()
Exemplo n.º 17
0
def run():
	try:
		global gui
		global mainwin
		global sb2
		global ser
		global id
		global nb
		global tw
		global sctw
		global sb
		global sertime
		global vbox
		global con
		global scon
		global p
		global b
		global pgm
		global recentmanager
		locale_path = _search_locales()
		gettext.bindtextdomain(APP_NAME, locale_path)
		gettext.textdomain(APP_NAME)
		locale.bindtextdomain(APP_NAME, locale_path)
		#global spinner
		#perform cleanup prior to this
		signal.signal(signal.SIGINT, signal.SIG_DFL)
		id = misc.makeWorkdir()
		ser = serialio.sconsole()
		p = prefs.preferences()
		recentmanager = gtk.recent_manager_get_default()
		sertime = None
		gui = gtk.Builder()
		gui.set_translation_domain(APP_NAME)
		try:
			path = os.path.join(os.getcwd(), "ui", "main.ui")
			if os.path.exists(path):
				gui.add_from_file(path)
			else: raise NameError(_("System error"))
		except:
			try:
				path = os.path.join(sys.prefix, "local", "share", "gnoduino", "ui", "main.ui")
				if os.path.exists(path):
					gui.add_from_file(path)
				else: raise NameError(_("System error"))
			except:
				try:
					path = os.path.join(sys.prefix, "share", "gnoduino", "ui", "main.ui")
					if os.path.exists(path):
						gui.add_from_file(path)
					else: raise NameError(_("System error"))
				except Exception,e:
					print(e)
					raise SystemExit(_("Cannot load ui file"))
		mainwin = gui.get_object("top_win")
		mainwin.set_icon_from_file(misc.getPixmapPath("gnoduino.png"))
		mw = int(p.getSafeValue("default.window.width", 640))
		mh = int(p.getSafeValue("default.window.height", 480))
		if (mw and mh):
			mainwin.set_default_size(mw, mh)
		mainwin.connect("configure-event", cb_configure_event)
		mainwin.connect("key-press-event", getKeyPEvent)
		mainwin.connect("key-release-event", getKeyREvent)
		vbox = gui.get_object("vpan")
		sb = gui.get_object("statusbar1")
		sb.set_has_resize_grip(False)
		sb2 = gui.get_object("statusbar2")
		sb2.set_has_resize_grip(False)
		setupSpinner()
		config.cur_editor_font = p.getSafeValue("editor.font", p.getDefaultValue("editor.font")).replace(",", " ")
		config.cur_console_font = p.getSafeValue("console.font", p.getDefaultValue("console.font")).replace(",", " ")
		config.build_verbose = p.getSafeValue("build.verbose", p.getDefaultValue("build.verbose"))
		config.show_numbers = p.getSafeValue("show.numbers", p.getDefaultValue("show.numbers"))
		config.user_library = p.getValue("user.library")
		menu(gui)
		"""build menus"""
		sub = gtk.Menu()
		b = board.Board()
		pgm = programmer.Programmer()
		maingroup = gtk.RadioMenuItem(None, None)
		for i in b.getBoards():
			menuItem = gtk.RadioMenuItem(maingroup, i['desc'])
			if i['id'] == b.getBoard() + 1:
				menuItem.set_active(True)
			menuItem.connect('toggled', selectBoard, i['id'])
			sub.append(menuItem)
		gui.get_object("board").set_submenu(sub)
		(con, tw) = createCon()
		misc.setConsoleTags(tw)

		"""setup default serial port"""
		sub = gtk.Menu()
		maingroup = gtk.RadioMenuItem(None, None)
		defport = p.getValue("serial.port")
		validport = False
		activePort = False
		"""validate serial ports - this should really be moved to serialio"""
		for i in ser.scan():
			if i == defport:
				validport = True

		for i in ser.scan():
			menuItem = gtk.RadioMenuItem(maingroup, i)
			if defport and validport:
				if i == defport:
					menuItem.set_active(True)
					if config.cur_serial_port == -1:
						config.cur_serial_port = i
					setSerial(None, i)
			else:
				if config.cur_serial_port == -1:
					config.cur_serial_port = i
				try:
					s = ser.tryPort(i)
					s.close()
				except: continue
				menuItem.set_active(True)
				setSerial(None, i)
			menuItem.connect('activate', setSerial, i)
			sub.append(menuItem)
			activePort = True

		if config.serial_baud_rate == -1:
			config.serial_baud_rate = p.getSafeValue("serial.debug_rate", p.getDefaultValue("serial.debug_rate"))

		gui.get_object("serial_port").set_submenu(sub)
		gui.get_object("serial_port").set_sensitive(activePort)
		createRecentMenu()
		populateExamples()

		sub = gtk.Menu()
		maingroup = gtk.RadioMenuItem(None, None)
		for i in pgm.getProgrammers():
			menuItem = gtk.RadioMenuItem(maingroup, i['desc'])
			if i['id'] == pgm.getProgrammer() + 1:
				menuItem.set_active(True)
			menuItem.connect('activate', selectProgrammer, i['id'])
			sub.append(menuItem)
		gui.get_object("programmer").set_submenu(sub)
		gui.get_object("burn").connect('activate', burnBootloader)

		nb = gtk.Notebook()
		nb.connect("switch-page", setupPage)
		sv = createPage(nb)
		vbox.pack1(nb, shrink=True, resize=True)
		(scon,sctw) = createScon()
		vbox.pack2(con, shrink=False, resize=False)
		vbox.connect("notify::position", vbox_move_handle)
		cpos = int(p.getSafeValue("console.height", -1))
		vbox.set_position(cpos)

		mainwin.set_focus(sv)
		mainwin.show_all()
		mainwin.set_title("Gnoduino")
		mainwin.connect("delete-event", quit)
		gui.get_object("ser_monitor").connect("activate", cserial, sertime, sctw)
		gui.get_object("serial").connect("clicked", cserial, sertime, sctw)
		gui.get_object("upload").connect("clicked", upload, ser)
		for i in buttons:
			w = gtk.Image()
			w.set_from_file(misc.getPixmapPath(i[1]))
			o = gui.get_object(i[0])
			o.set_icon_widget(w)
			o.show_all()
			if i[2] != None:
				o.connect("clicked", i[2])
		if (sys.argv[1:]):
			if sys.argv[1:][0] == "--help" or sys.argv[1:][0] == "-h":
				print _("--help    Print the command line options")
				print _("--version Output version information and exit")
				sys.exit(0)
			if sys.argv[1:][0] == "--version" or sys.argv[1:][0] == "-v":
				print "gnoduino %s" % gnoduino.__version__
				sys.exit(0)
			for f in sys.argv[1:]:
				processFile(f)
		gtk.main()
Exemplo n.º 18
0
def upload(obj, serial, output, notify, force_protocol):
    p = prefs.preferences()
    pgm = programmer.Programmer()
    context = notify.get_context_id("main")
    notify.pop(context)
    notify.push(context, _("Flashing..."))
    b = board.Board()
    compline = [i for i in avr]
    protocol = b.getPGM(b.getBoard())
    # avrdude wants "stk500v1" to distinguish it from stk500v2
    if protocol == "stk500": protocol = "stk500v1"
    # if we do not get any protocol back probably means board doesn't
    # enforce any particular programmer
    if protocol == "" or force_protocol is True:
        #try selected programmer (via menu)
        protocol = pgm.getProtocol(pgm.getProgrammer())
        try:
            comm = pgm.getCommunication(pgm.getProgrammer())
            if comm:
                if comm == "serial":
                    port = serial.getConfigSerialPort(notify, output)
                    if port == -1:
                        notify.pop(context)
                        notify.push(context, _("Flashing error."))
                        return
                    serial.resetBoard()
                    compline.append("-P" + port)
                else:
                    compline.append("-P" + comm)
                try:
                    compline.append("-b" + pgm.getSpeed(pgm.getProgrammer()))
                except:
                    pass
        except:
            pass
    else:
        if protocol != "usbtiny":  #usbtiny works via spi, need to do some device parsing here
            port = serial.getConfigSerialPort(notify, output)
            if port == -1:
                notify.pop(context)
                notify.push(context, _("Flashing error."))
                return
            compline.append("-P" + port)
            serial.resetBoard(b.getPath(b.getBoard()))
    compline.append("-c" + protocol)
    try:
        compline.append("-b" + b.getPGMSpeed(b.getBoard()))
    except:
        pass
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-Uflash:w:" + obj + ".hex:i")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Flashing Error"),
                          _("Flash ERROR.\n"))
        return
    notify.pop(context)
    notify.push(context, _("Flashing complete."))
    misc.printMessageLn(output, \
     "Flash OK.")
Exemplo n.º 19
0
def compile(tw, sourcefile, id, output, notify):
	buf =  tw.get_buffer()
	cont = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
	if cont is "": return -1
	context = notify.get_context_id("main")
	notify.pop(context)
	notify.push(context, _("Compiling..."))
	misc.printMessageLn(output, 'Compile start')
	misc.printLogMessageLn('Compile start')
	misc.clearConsole(output)
	tmpdir = id
	tempobj = tempfile.mktemp("", "Tempobj", id)
	global p
	global queue
	queue = []
	p = prefs.preferences()
	b = board.Board()
	#compile inter c objects
	try:
		"""preproces pde"""
		(pre_file, lines) = preproc.addHeaders(id, buf)
		"""compile C targets"""
		misc.printLogMessageLn('processing C targets')
		(run, sout) = compileObjects(cobj, defc, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			raise NameError("compile error")
		"""deprecated C targets (pre 1.0)"""
		if misc.getArduinoVersion() < 100:
			(run, sout) = compileObjects(cobj_deprecated, defc, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
		"""compile C++ targets"""
		misc.printLogMessageLn('processing C++ targets')
		(run, sout) = compileObjects(cppobj, defcpp, id, output)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), sout)
			raise NameError("compile error")
		"""compile C++ additional (1.0) targets"""
		if misc.getArduinoVersion() >= 100:
			misc.printLogMessageLn('processing C++ additional targets')
			(run, sout) = compileObjects(cppobj_additional, defcpp, id, output)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), sout)
				raise NameError("compile error")
		"""generate archive objects"""
		misc.printLogMessageLn('generating ar objects')
		objects = cobj + cppobj
		if misc.getArduinoVersion() >= 100:
			objects += cppobj_additional
		else:
			objects += cobj_deprecated
		for i in objects:
			compline = [j for j in defar]
			compline.append(id+"/core.a")
			compline.append(id+"/"+i+".o")
			misc.printMessageLn(output, ' '.join(compline)+"\n")
			misc.printLogMessageLn(' '.join(compline))
			(run, sout) = misc.runProg(compline)
			misc.printLogMessageLn(sout)
			if run == False:
				misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
				raise NameError("compile error")
			else:
				misc.printMessageLn(output, sout)
		"""precompile pde"""
		misc.printLogMessageLn('pde compile')
		misc.printLogMessageLn('-----------')
		compline=[j for j in defcpp]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-DF_CPU="+b.getBoardFCPU(b.getBoard()))
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		flags = []
		flags = preproc.generateCFlags(id, cont)
		compline.extend(flags)
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		compline.extend(misc.getArduinoIncludes())
		compline.append(pre_file)
		compline.append("-o"+pre_file+".o")
		compline.append("-I"+os.path.dirname(sourcefile))
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Compile Error"), stripOut(sout, pre_file))
			moveCursor(tw, int(getErrorLine(sout, lines)))
			raise NameError('compile-error')
		else:
			misc.printMessageLn(output, sout)

		"""compile all objects"""
		misc.printLogMessageLn('compile objects')
		misc.printLogMessageLn('---------------')
		compline = [i for i in link]
		compline.append("-mmcu="+b.getBoardMCU(b.getBoard()))
		compline.append("-o"+tempobj+".elf")
		compline.append(pre_file+".o")
		tmplibs = []
		for i in preproc.generateLibs(id, buf):
			tmplibs.extend(validateLib(os.path.basename(i), tempobj, flags, output, notify))
		compline.extend(list(set(tmplibs)))
		compline.extend(["-I" + i for i in preproc.generateLibs(id, buf)])
		compline.extend(["-I" + os.path.join(i, "utility") for i in preproc.generateLibs(id, buf)])
		if misc.getArduinoVersion() >= 100:
			compline.append("-DARDUINO=100")
		compline.extend(misc.getArduinoIncludes())
		compline.append(id+"/core.a")
		compline.append("-L"+id)
		compline.append("-lm")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Linking error"), stripOut(sout, pre_file))
			raise NameError('linking-error')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in eep]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".eep")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		compline=[i for i in hex]
		compline.append(tempobj+".elf")
		compline.append(tempobj+".hex")
		misc.printMessageLn(output, ' '.join(compline)+"\n")
		misc.printLogMessageLn(' '.join(compline))
		(run, sout) = misc.runProg(compline)
		misc.printMessageLn(output, sout)
		misc.printLogMessageLn(sout)
		if run == False:
			misc.printErrorLn(notify, output, _("Object error"), stripOut(sout, pre_file))
			raise NameError('obj-copy')
		else:
			misc.printMessageLn(output, sout)
		size = computeSize(tempobj+".hex")
		notify.pop(context)
		notify.push(context, _("Done compiling."))
		misc.printLogMessageLn("compile done.")

		misc.printMessageLn(output, \
			_("Binary sketch size: %s bytes (of a %s bytes maximum)\n") % (size, b.getBoardMemory(b.getBoard())), 'true')
	except StandardError as e:
		print "Error: %s" % e
		return -1
	except Exception as e:
		print "Error compiling. Op aborted!"
		print "Error: %s" % e
		return -1
	return tempobj
Exemplo n.º 20
0
def burnBootloader(serial, output, notify, id):
    p = prefs.preferences()
    misc.clearConsole(output)
    context = notify.get_context_id("main")
    notify.pop(context)
    notify.push(context, _("Burning bootloader..."))
    b = board.Board()
    compline = [i for i in avr_bl]
    pgm = programmer.Programmer()
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port != -1:
            serial.resetBoard()
        """De-fuse and erase board"""

        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-c" + pgm.getProtocol(id))
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Ulock:w:" + b.getFuseUnlock(b.getBoard()) + ":m")
    if b.getBoardMCU(b.getBoard()) != 'atmega8':
        compline.append("-Uefuse:w:" + b.getFuseExtended(b.getBoard()) + ":m")
    compline.append("-Uhfuse:w:" + b.getFuseHigh(b.getBoard()) + ":m")
    compline.append("-Ulfuse:w:" + b.getFuseLow(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    """Burn and fuse board"""
    compline = [i for i in avr_bl]
    compline.append("-c" + pgm.getProtocol(id))
    if pgm.getCommunication(id) == 'serial':
        port = serial.getConfigSerialPort(notify, output)
        if port == -1:
            notify.pop(context)
            notify.push(context, _("Flashing error."))
            return
        compline.append("-P" + port)
        if pgm.getSpeed(id) != 0:
            compline.append("-b" + pgm.getSpeed(id))
    elif pgm.getCommunication(id) == 'usb':
        compline.append("-Pusb")
    compline.append("-p" + b.getBoardMCU(b.getBoard()))
    compline.append("-e")
    if pgm.getForce(id) == 'true':
        compline.append("-F")
    compline.append("-Uflash:w:" + findBootLoader() + ":i")
    compline.append("-Ulock:w:" + b.getFuseLock(b.getBoard()) + ":m")
    try:
        if p.getBoolValue("upload.verbose"):
            sys.stderr.write(' '.join(compline) + "\n")
            misc.printMessageLn(output, ' '.join(compline))
        (run, sout) = misc.runProg(compline)
        misc.printMessageLn(output, sout, p.getBoolValue("upload.verbose"),
                            'false')
        if p.getBoolValue("upload.verbose"): sys.stderr.write(sout + "\n")
        if run == False: raise
    except:
        misc.printErrorLn(notify, output, _("Burn Error"), _("Burn ERROR."))
        return
    notify.pop(context)
    notify.push(context, _("Burn complete."))
    misc.printMessageLn(output, \
     "Burn OK.")