Skip to content

Commit

Permalink
Use avr-as to list devices
Browse files Browse the repository at this point in the history
Also fix project file save(), f.seek() and truncate() don't have return value
  • Loading branch information
Kim Blomqvist committed Mar 2, 2014
1 parent 42e1675 commit 265814c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions SublimeAVR.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def run(self, *args, **kwargs):
if self.pm.install("SublimeClang") == False:
return

self.mcus = avrgcc.mmcu(self.avrgcc)
self.window.show_quick_panel(self.mcus, self.mcu)
self.devices = avrgcc.devices(self.avrgcc)
self.window.show_quick_panel(self.devices, self.mcu)

def mcu(self, index):
if index == -1:
return

self.settings.set("mcu", self.mcus[index])
self.settings.set("mcu", self.devices[index])

initial_location = os.path.expanduser('~')
if self.window.folders():
Expand Down Expand Up @@ -158,8 +158,10 @@ def save(self):
project = self.template()

# Save SublimeAVR.sublime-project
f.seek(0).write(json.dumps(project, sort_keys=False, indent=4))
f.truncate().close()
f.seek(0)
f.write(json.dumps(project, sort_keys=False, indent=4))
f.truncate()
f.close()
return True

def template(self):
Expand Down
12 changes: 6 additions & 6 deletions avrgcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
import os, subprocess
import string, re

def mmcu(location = None, gcc = "avr-gcc"):
def devices(location = None):
p = subprocess.Popen(
gcc + " -mmcu=asd",
"avr-as -mlist-devices",
shell = True,
cwd = location,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
out, err = p.communicate()

m = re.search(r"are: (.*)", err.decode())
if not m:
return []
return m.group(1).split(' ')
devices = []
for line in out.decode().split(os.linesep)[1:]:
devices.extend(line.strip().split(" "))
return devices

0 comments on commit 265814c

Please sign in to comment.