-
Notifications
You must be signed in to change notification settings - Fork 11
/
Uploader.py
59 lines (48 loc) · 1.75 KB
/
Uploader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#-*- coding: utf-8 -*-
from PyQt4.QtCore import QObject, SIGNAL
import const
import os
import threading
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell."""
pipe = os.popen(cmd + ' 2>&1', 'r')
text = pipe.read()
sts = pipe.close()
if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text
class Uploader(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.qobj = QObject()
self.avrdude = const.avrdude
self.avrdude_conf = const.avrconf
self.mcu = 'atmega328p'
self.speed = "115200"
self.protocol = "arduino"
self.comport = "COM3"
self.flash_bin = ''
self.__buildUploadCmd()
def __buildUploadCmd(self):
self.upload_cmd = "%s -C%s -v -p%s -c%s -P%s -b%s -D -Uflash:w:%s:i 2>%s" % (
self.avrdude,
self.avrdude_conf,
self.mcu,
self.protocol,
self.comport,
self.speed,
self.flash_bin,
const.arduloader_log)
def resetUploadArgs(self, argsdict):
assert type(argsdict) is dict
self.mcu = argsdict["mcu"]
self.speed = argsdict["speed"]
self.protocol = argsdict["protocol"]
self.comport = argsdict["comport"]
self.flash_bin = argsdict["flash_bin"]
self.__buildUploadCmd()
def run(self):
self.upload()
def upload(self):
ret, text = getstatusoutput(self.upload_cmd)
self.qobj.emit(SIGNAL(const.finish_sig), ret, text)