diff --git a/radio/src/Makefile b/radio/src/Makefile
index 04019da69..88ef5c2fc 100644
--- a/radio/src/Makefile
+++ b/radio/src/Makefile
@@ -388,21 +388,14 @@ LUA_COMPILER = NO
# Define programs and commands.
SHELL = sh
-# Make sure python is Python 2
-ifeq ($(findstring Python 2,$(shell python --version 2>&1)), Python 2)
- PYTHON := python
-else
- PYTHON := python2
-endif
-
-IMG2LBM = -$(PYTHON) ../util/img2lbm.py
-BIN2LBM = -$(PYTHON) ../util/bin2lbm.py
+IMG2LBM = -python ../util/img2lbm.py
+BIN2LBM = -python ../util/bin2lbm.py
ifeq ($(OS), Windows_NT)
- FONT2PNG = -$(PYTHON) ../util/font2png.py
+ FONT2PNG = -python ../util/font2png.py
else
- FONT2PNG = -xvfb-run --server-args="-screen 0 1024x768x24" $(PYTHON) ../util/font2png.py
+ FONT2PNG = -xvfb-run --server-args="-screen 0 1024x768x24" python ../util/font2png.py
endif
-TRANSLATE = -$(PYTHON) ../util/translate.py
+TRANSLATE = -python ../util/translate.py
VERSION_MAJOR = 2
VERSION_MINOR = 2
@@ -1953,28 +1946,28 @@ lua/lua_exports_taranis.inc: myeeprom.h ../util/luaexport.py
@echo "Generating a list of Lua exported constants in lua/lua_exports_taranis.txt"
@$(PARSER) -DEXPORT -DPCBTARANIS -DLUA -DVIRTUALINPUTS myeeprom.h | grep LEXP > lua/lua_exports_taranis.txt
@echo "Parsing and generating C Lua exports in lua/lua_exports_taranis.inc"
- @$(PYTHON) ../util/luaexport.py $(VERSION) lua/lua_exports_taranis.txt lua/lua_exports_taranis.inc lua/lua_fields_taranis.txt
+ @python ../util/luaexport.py $(VERSION) lua/lua_exports_taranis.txt lua/lua_exports_taranis.inc lua/lua_fields_taranis.txt
@rm lua/lua_exports_taranis.txt
lua/lua_exports_taranis_x9e.inc: myeeprom.h ../util/luaexport.py
@echo "Generating a list of Lua exported constants in lua/lua_exports_taranis_x9e.txt"
@$(PARSER) -DEXPORT -DPCBTARANIS -DREVPLUS -DREV9E -DLUA -DVIRTUALINPUTS myeeprom.h | grep LEXP > lua/lua_exports_taranis_x9e.txt
@echo "Parsing and generating C Lua exports in lua/lua_exports_taranis_x9e.inc"
- @$(PYTHON) ../util/luaexport.py $(VERSION) lua/lua_exports_taranis_x9e.txt lua/lua_exports_taranis_x9e.inc lua/lua_fields_taranis_x9e.txt
+ @python ../util/luaexport.py $(VERSION) lua/lua_exports_taranis_x9e.txt lua/lua_exports_taranis_x9e.inc lua/lua_fields_taranis_x9e.txt
@rm lua/lua_exports_taranis_x9e.txt
lua/lua_exports_horus.inc: myeeprom.h ../util/luaexport.py
@echo "Generating a list of Lua exported constants in lua/lua_exports_horus.txt"
@$(PARSER) -DEXPORT -DPCBHORUS -DLUA -DVIRTUALINPUTS myeeprom.h | grep LEXP > lua/lua_exports_horus.txt
@echo "Parsing and generating C Lua exports in lua/lua_exports_horus.inc"
- @$(PYTHON) ../util/luaexport.py $(VERSION) lua/lua_exports_horus.txt lua/lua_exports_horus.inc lua/lua_fields_horus.txt
+ @python ../util/luaexport.py $(VERSION) lua/lua_exports_horus.txt lua/lua_exports_horus.inc lua/lua_fields_horus.txt
@rm lua/lua_exports_horus.txt
lua/lua_exports_flamenco.inc: myeeprom.h ../util/luaexport.py
@echo "Generating a list of Lua exported constants in lua/lua_exports_flamenco.txt"
@$(PARSER) -DEXPORT -DPCBFLAMENCO -DLUA -DVIRTUALINPUTS myeeprom.h | grep LEXP > lua/lua_exports_flamenco.txt
@echo "Parsing and generating C Lua exports in lua/lua_exports_flamenco.inc"
- @$(PYTHON) ../util/luaexport.py $(VERSION) lua/lua_exports_flamenco.txt lua/lua_exports_flamenco.inc lua/lua_fields_flamenco.txt
+ @python ../util/luaexport.py $(VERSION) lua/lua_exports_flamenco.txt lua/lua_exports_flamenco.inc lua/lua_fields_flamenco.txt
@rm lua/lua_exports_flamenco.txt
# Eye candy.
diff --git a/radio/util/add-issue-links.py b/radio/util/add-issue-links.py
index e66ad56a7..582809885 100755
--- a/radio/util/add-issue-links.py
+++ b/radio/util/add-issue-links.py
@@ -1,49 +1,46 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import print_function
import sys
-import os
-import traceback
-import time
-import re
import re
if len(sys.argv) > 1:
- inputFile = sys.argv[1]
- inp = open(inputFile, "r")
+ inputFile = sys.argv[1]
+ inp = open(inputFile, "r")
else:
- inp = sys.stdin
+ inp = sys.stdin
pattern = re.compile("#\d+")
while True:
- skip = False
- line = inp.readline()
- if len(line) == 0:
- break
- line = line.strip('\r\n')
+ skip = False
+ line = inp.readline()
+ if len(line) == 0:
+ break
+ line = line.strip('\r\n')
- if len(line) == 0:
- skip = True
- if line.startswith("<"):
- skip = True
- if line.startswith("["):
- skip = True
+ if len(line) == 0:
+ skip = True
+ if line.startswith("<"):
+ skip = True
+ if line.startswith("["):
+ skip = True
- if not skip:
- #line = line.strip()
- #print "line: %s" % line
- found = re.findall(pattern, line)
- if len(found) > 0:
- for issue in found:
- line = line.replace(issue, '')
- #add issues
- issue_links = ["#%d" % (int(issue[1:]), int(issue[1:])) for issue in found]
- links = "(" + ", ".join(issue_links) + ")"
- line = "
" + line + " " + links + ""
+ if not skip:
+ # line = line.strip()
+ # print("line: %s" % line)
+ found = re.findall(pattern, line)
+ if len(found) > 0:
+ for issue in found:
+ line = line.replace(issue, '')
+ # add issues
+ issue_links = ["#%d" % (int(issue[1:]), int(issue[1:])) for issue in found]
+ links = "(" + ", ".join(issue_links) + ")"
+ line = "" + line + " " + links + ""
- print line
+ print(line)
inp.close()
diff --git a/radio/util/addtr.py b/radio/util/addtr.py
index 3a3b30e52..d31ca3ad8 100755
--- a/radio/util/addtr.py
+++ b/radio/util/addtr.py
@@ -1,37 +1,45 @@
#!/bin/env python
-import sys, glob
+from __future__ import print_function
+
+import sys
+import glob
+
def addLine(filename, newline, after):
- print filename, newline
- lines = file(filename, 'r').readlines()
- for i, line in enumerate(lines):
- if after in line:
- lines.insert(i+1, newline + '\n')
- break
- file(filename, 'w').writelines(lines)
+ print(filename, newline)
+ with open(filename, 'r') as f:
+ lines = f.readlines()
+ for i, line in enumerate(lines):
+ if after in line:
+ lines.insert(i + 1, newline + '\n')
+ break
+ with open(filename, 'w') as f:
+ f.writelines(lines)
+
def modifyTranslations(constant, translation, after):
- for filename in glob.glob('translations/*.h.txt'):
- newline = "#define " + constant + " "*max(1, 23-len(constant)) + '"' + translation + '"'
- addLine(filename, newline, after+" ")
+ for filename in glob.glob('translations/*.h.txt'):
+ newline = "#define " + constant + " " * max(1, 23 - len(constant)) + '"' + translation + '"'
+ addLine(filename, newline, after + " ")
+
def modifyDeclaration(constant, after):
- newline = "extern const pm_char S" + constant + "[];"
- filename = "translations.h"
- addLine(filename, newline, after+"[];")
+ newline = "extern const pm_char S" + constant + "[];"
+ filename = "translations.h"
+ addLine(filename, newline, after + "[];")
+
def modifyDefinition(constant, after):
- newline = "const pm_char S" + constant + "[] PROGMEM = " + constant + ";"
- filename = "translations.cpp"
- addLine(filename, newline, after+"[] ")
+ newline = "const pm_char S" + constant + "[] PROGMEM = " + constant + ";"
+ filename = "translations.cpp"
+ addLine(filename, newline, after + "[] ")
after = sys.argv[-1]
for arg in sys.argv[1:-1]:
- constant, translation = arg.split("=")
- modifyTranslations(constant, translation, after)
- modifyDeclaration(constant, after)
- modifyDefinition(constant, after)
- after = constant
-
+ constant, translation = arg.split("=")
+ modifyTranslations(constant, translation, after)
+ modifyDeclaration(constant, after)
+ modifyDefinition(constant, after)
+ after = constant
diff --git a/radio/util/bin2lbm.py b/radio/util/bin2lbm.py
index 19b3bf0cf..f34999b34 100755
--- a/radio/util/bin2lbm.py
+++ b/radio/util/bin2lbm.py
@@ -1,20 +1,20 @@
#!/usr/bin/env python
+from __future__ import division
import sys
filename = sys.argv[1]
fileout = sys.argv[2]
-fr = open(filename, "rb")
-fw = open(fileout, "w")
+# Read entire file
+with open(filename, "rb") as fr:
+ sts = fr.read()
+# Parse into chunks of 16 bytes
+sts = [sts[i * 16:(i + 1) * 16] for i in range(len(sts) // 16)]
-st = fr.read(16)
-
-while st:
- for b in st:
- fw.write("0x%02x," % ord(b))
- fw.write("\n")
- st = fr.read(16)
-
-fw.write("\n")
-fw.close()
+with open(fileout, "w") as fw:
+ for st in sts:
+ for b in st:
+ fw.write("0x%02x," % ord(b))
+ fw.write("\n")
+ fw.write("\n")
diff --git a/radio/util/capitalize.py b/radio/util/capitalize.py
index 941cafb6b..ac087168d 100755
--- a/radio/util/capitalize.py
+++ b/radio/util/capitalize.py
@@ -1,8 +1,9 @@
#!/usr/bin/env python
-import glob, os
+import glob
+import os
for f in glob.glob("*.bmp") + glob.glob("*.BMP"):
- t = f.title()
- if f != t:
- os.rename(f, t)
+ t = f.title()
+ if f != t:
+ os.rename(f, t)
diff --git a/radio/util/codecs.py b/radio/util/codecs.py
index 4c75a6ed6..fdc88f4fe 100755
--- a/radio/util/codecs.py
+++ b/radio/util/codecs.py
@@ -1,51 +1,58 @@
#!/bin/env python
-SIGN_BIT = (0x80) # Sign bit for a A-law byte.
-QUANT_MASK = (0xf) # Quantization field mask.
-SEG_SHIFT = (4) # Left shift for segment number.
-SEG_MASK = (0x70) # Segment field mask.
-BIAS = (0x84) # Bias for linear code.
+from __future__ import print_function
+
+SIGN_BIT = (0x80) # Sign bit for a A-law byte.
+QUANT_MASK = (0xf) # Quantization field mask.
+SEG_SHIFT = (4) # Left shift for segment number.
+SEG_MASK = (0x70) # Segment field mask.
+BIAS = (0x84) # Bias for linear code.
+
def alaw2linear(a_val):
a_val ^= 0x55
-
+
t = a_val & QUANT_MASK
seg = (a_val & SEG_MASK) >> SEG_SHIFT
if (seg):
t = (t + t + 1 + 32) << (seg + 2)
else:
- t = (t + t + 1 ) << 3
-
+ t = (t + t + 1) << 3
+
if a_val & SIGN_BIT:
return t
else:
return -t
-def ulaw2linear(u_val):
+
+def ulaw2linear(u_val):
# Complement to obtain normal u-law value.
u_val = ~u_val
-
+
# Extract and bias the quantization bits. Then
# shift up by the segment number and subtract out the bias.
t = ((u_val & QUANT_MASK) << 3) + BIAS
t <<= (u_val & SEG_MASK) >> SEG_SHIFT
-
+
if u_val & SIGN_BIT:
return (BIAS - t)
else:
return (t - BIAS)
+
def pcmTable(fn):
result = []
for i in range(256):
result.append(fn(i))
return result
-def tableToString(name, table):
- result = 'const int16_t ' + name + '[256] = { '
- result += ', '.join([str(i) for i in table])
+
+def tableToString(name, table):
+ result = 'const int16_t ' + name + '[256] = { '
+ result += ', '.join(str(i) for i in table)
result += ' };'
return result
-
-print tableToString('alawTable', pcmTable(alaw2linear))
-print tableToString('ulawTable', pcmTable(ulaw2linear))
+
+
+print(tableToString('alawTable', pcmTable(alaw2linear)))
+print(tableToString('ulawTable', pcmTable(ulaw2linear)))
diff --git a/radio/util/copyright.py b/radio/util/copyright.py
index 9a12c285d..13f25cb2b 100755
--- a/radio/util/copyright.py
+++ b/radio/util/copyright.py
@@ -1,52 +1,53 @@
#!/usr/bin/env python
-import os
-import re
+from __future__ import print_function
+
import sys
-def writeheader(filename,header):
+
+def writeheader(filename, header):
"""
- write a header to filename,
+ write a header to filename,
skip files where first line after optional shebang matches the skip regex
filename should be the name of the file to write to
header should be a list of strings
skip should be a regex
"""
- f = open(filename,"r")
- inpt =f.readlines()
- f.close()
+ with open(filename, "r") as f:
+ inpt = f.readlines()
output = []
- #comment out the next 3 lines if you don't wish to preserve shebangs
- if len(inpt) > 0 and inpt[0].startswith("#!"):
+ # comment out the next 3 lines if you don't wish to preserve shebangs
+ if len(inpt) > 0 and inpt[0].startswith("#!"):
output.append(inpt[0])
inpt = inpt[1:]
if inpt[0].strip().startswith("/*"):
for i, line in enumerate(inpt):
if line.strip().endswith("*/"):
- inpt = inpt[i+1:]
+ inpt = inpt[i + 1:]
break
while not inpt[0].strip():
inpt = inpt[1:]
- output.extend(header) #add the header
+ output.extend(header) # add the header
for line in inpt:
output.append(line)
try:
- f = open(filename,'w')
- f.writelines(output)
- f.close()
- print "added header to %s" %filename
- except IOError,err:
- print "something went wrong trying to add header to %s: %s" % (filename,err)
+ with open(filename, 'w') as f:
+ f.writelines(output)
+ print("added header to %s" % filename)
+ except IOError as err:
+ print("something went wrong trying to add header to %s: %s" % (filename, err))
+
def main(args=sys.argv):
- headerfile = open(args[1])
- header = headerfile.readlines()
- headerfile.close()
+ with open(args[1]) as headerfile:
+ header = headerfile.readlines()
writeheader(args[2], header)
-#call the main method
-main()
+
+if __name__ == '__main__':
+ # call the main method
+ main()
diff --git a/radio/util/dsm2.py b/radio/util/dsm2.py
index 1d1d77006..ede556211 100755
--- a/radio/util/dsm2.py
+++ b/radio/util/dsm2.py
@@ -1,21 +1,25 @@
+from __future__ import print_function
+
BITLEN_DSM2 = 16
+
def sendByteDsm2(b):
- print "%02x:" % b,
+ print("%02x:" % b, end=' ')
lev = 0
len = BITLEN_DSM2
for i in range(9):
nlev = b & 1
- if (lev == nlev):
- len += BITLEN_DSM2
+ if lev == nlev:
+ len += BITLEN_DSM2
else:
- print len,
- # _send_1(nlev ? len-5 : len+3);
- len = BITLEN_DSM2
- lev = nlev
- b = (b>>1) | 0x80
+ print(len, end=' ')
+ # _send_1(nlev ? len-5 : len+3);
+ len = BITLEN_DSM2
+ lev = nlev
+ b = (b >> 1) | 0x80
# _send_1(len+BITLEN_DSM2+3); // 2 stop bits
- print len+BITLEN_DSM2
+ print(len + BITLEN_DSM2)
+
sendByteDsm2(24)
sendByteDsm2(17)
diff --git a/radio/util/fat12.py b/radio/util/fat12.py
index 13889f3c7..9c83a7baa 100755
--- a/radio/util/fat12.py
+++ b/radio/util/fat12.py
@@ -1,50 +1,57 @@
#!/bin/env python
+from __future__ import division, print_function
+
curr = 0
idx = 0
byte = 0
+
def push4bits(val):
- global curr, idx, byte
- val = val & 0x0f
- curr += val << idx
- idx += 4
- if idx == 8:
- print "0x%02X," % curr,
- idx = 0
- curr = 0
- byte += 1
- if byte % 16 == 0:
- print
+ global curr, idx, byte
+ val = val & 0x0f
+ curr += val << idx
+ idx += 4
+ if idx == 8:
+ print("0x%02X," % curr, end=' ')
+ idx = 0
+ curr = 0
+ byte += 1
+ if byte % 16 == 0:
+ print()
+
cluster = 0
+
def pushCluster(val):
- global cluster
- push4bits(val)
- push4bits(val >> 4)
- push4bits(val >> 8)
- cluster += 1
+ global cluster
+ push4bits(val)
+ push4bits(val >> 4)
+ push4bits(val >> 8)
+ cluster += 1
+
def pushFile(size):
- sectors = size / 512
- count = sectors / 8
- for i in range(count-1):
- pushCluster(cluster+1)
- pushCluster(0xFFF)
+ sectors = size // 512
+ count = sectors // 8
+ for i in range(count - 1):
+ pushCluster(cluster + 1)
+ pushCluster(0xFFF)
+
def pushDisk(eeprom, flash):
- global curr, idx, byte, cluster
- curr = idx = byte = cluster = 0
- print "Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash)
- pushCluster(0xFF8)
- pushCluster(0xFFF)
- pushFile(eeprom*1024)
- pushFile(flash*1024)
- while byte < 512:
- push4bits(0)
- print
+ global curr, idx, byte, cluster
+ curr = idx = byte = cluster = 0
+ print("Disk with %dk EEPROM and %dk FLASH:" % (eeprom, flash))
+ pushCluster(0xFF8)
+ pushCluster(0xFFF)
+ pushFile(eeprom * 1024)
+ pushFile(flash * 1024)
+ while byte < 512:
+ push4bits(0)
+ print()
+
pushDisk(32, 512)
pushDisk(64, 512)
-
diff --git a/radio/util/font2png.py b/radio/util/font2png.py
index a07a02a05..302ed6659 100755
--- a/radio/util/font2png.py
+++ b/radio/util/font2png.py
@@ -12,6 +12,7 @@ for f in glob.glob("fonts/*.ttf"):
chars = u""" !"#$%&'()*+,-./0123456789:;<=>?°ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~ ≥→←↑↓↗↘↙↖△"""
+
def getCharWidth(fontsize, metrics, index):
if index == 0:
return 4
@@ -24,39 +25,42 @@ def getCharWidth(fontsize, metrics, index):
else:
return rect.width() + 1
+
def getFontTopBottom(fontsize, metrics):
top, bottom = 0, 0
for i, c in enumerate(chars):
- rect = metrics.boundingRect(chars[i])
- top = min(top, rect.top())
- bottom = max(bottom, rect.bottom())
+ rect = metrics.boundingRect(chars[i])
+ top = min(top, rect.top())
+ bottom = max(bottom, rect.bottom())
return top, bottom
+
def getFontWidth(fontsize, metrics):
width = 0
for i, c in enumerate(chars):
width += getCharWidth(fontsize, metrics, i)
return width
-
+
+
def createFontBitmap(filename, fontname, fontsize, fontbold, foreground, background, coordsfile=True):
- coords = [ ]
+ coords = []
font = QtGui.QFont(fontname)
font.setPixelSize(fontsize)
font.setBold(fontbold)
font.setHintingPreference(QtGui.QFont.PreferNoHinting)
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
metrics = QtGui.QFontMetrics(font)
-
+
width = getFontWidth(fontsize, metrics)
top, bottom = getFontTopBottom(fontsize, metrics)
extraFilename = "fonts/extra_%dpx.png" % fontsize
extraImage = QtGui.QImage(extraFilename)
if extraImage.isNull():
- print "No extra font file", extraFilename
+ print("No extra font file", extraFilename)
extraWidth = 0
else:
extraWidth = extraImage.size().width()
- image = QtGui.QImage(width + extraWidth, fontsize+2, QtGui.QImage.Format_RGB32)
+ image = QtGui.QImage(width + extraWidth, fontsize + 2, QtGui.QImage.Format_RGB32)
image.fill(background)
painter = QtGui.QPainter()
painter.begin(image)
@@ -69,31 +73,30 @@ def createFontBitmap(filename, fontname, fontsize, fontbold, foreground, backgro
if i == 0:
pass
elif i == 14 and fontsize <= 8:
- painter.drawPoint(width, fontsize);
+ painter.drawPoint(width, fontsize)
else:
rect = metrics.boundingRect(c)
if fontsize >= 24:
- painter.drawText(width-rect.left()+1, fontsize-2, c) # fontsize-bottom+1 -17 / 7
+ painter.drawText(width - rect.left() + 1, fontsize - 2, c) # fontsize-bottom+1 -17 / 7
else:
- painter.drawText(width-rect.left(), fontsize-1, c) # fontsize-bottom+1 -17 / 7
+ painter.drawText(width - rect.left(), fontsize - 1, c) # fontsize-bottom+1 -17 / 7
width += getCharWidth(fontsize, metrics, i)
if extraWidth:
- painter.drawImage(QtCore.QPoint(width, 0), extraImage)
-
+ painter.drawImage(QtCore.QPoint(width, 0), extraImage)
+
coords.append(width)
painter.end()
image.save(filename + ".png")
if coordsfile:
- f = file(filename + ".specs", "w")
- f.write("{ ")
- f.write(",".join(str(tmp) for tmp in coords))
- if extraWidth:
- for i in range(1, 14):
- f.write(", %d" % (int(coords[-1])+i*(extraWidth/12)))
- # f.write(file("fonts/extra_%dpx.specs" % fontsize).read())
- f.write(" }")
- f.close()
+ with open(filename + ".specs", "w") as f:
+ f.write("{ ")
+ f.write(",".join(str(tmp) for tmp in coords))
+ if extraWidth:
+ for i in range(1, 14):
+ f.write(", %d" % (int(coords[-1]) + i * (extraWidth / 12)))
+ # f.write(file("fonts/extra_%dpx.specs" % fontsize).read())
+ f.write(" }")
return coords
if __name__ == "__main__":
- createFontBitmap(sys.argv[4], sys.argv[1], float(sys.argv[2]), sys.argv[3] == "True", QtGui.QColor(0x00, 0x00, 0x00), QtGui.QColor(0xFF, 0xFF, 0xFF))
+ createFontBitmap(sys.argv[4], sys.argv[1], float(sys.argv[2]), sys.argv[3] == "True", QtGui.QColor(0x00, 0x00, 0x00), QtGui.QColor(0xFF, 0xFF, 0xFF))
diff --git a/radio/util/img2lbm.py b/radio/util/img2lbm.py
index e02ac7a25..56bc9e1ff 100755
--- a/radio/util/img2lbm.py
+++ b/radio/util/img2lbm.py
@@ -1,151 +1,154 @@
#!/usr/bin/env python
+from __future__ import division, print_function
+
import sys
from PyQt4 import Qt, QtGui
image = QtGui.QImage(sys.argv[1])
width, height = image.size().width(), image.size().height()
-f = open(sys.argv[2], "w")
-lcdwidth = int(sys.argv[3])
-
-if len(sys.argv) > 4:
- what = sys.argv[4]
-else:
- for s in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"):
- if s in sys.argv[2]:
- what = s
- break
def writeSize(f, width, height):
if lcdwidth > 255:
- f.write("%d,%d,%d,%d,\n" % (width%256, width/256, height%256, height/256))
+ f.write("%d,%d,%d,%d,\n" % (width % 256, width // 256, height % 256, height // 256))
else:
f.write("%d,%d,\n" % (width, height))
-
-if what == "1bit":
- rows = 1
- if len(sys.argv) > 5:
- rows = int(sys.argv[5])
- writeSize(f, width, height/rows)
- for y in range(0, height, 8):
- for x in range(width):
- value = 0
- for z in range(8):
- if y+z < height and image.pixel(x, y+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- f.write("0x%02x," % value)
- f.write("\n")
-elif what == "4/4/4/4":
- colors = []
- f.write("%d,%d,\n" % (width, height))
- for y in range(height):
- for x in range(width):
- pixel = image.pixel(x, y)
- f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel)/16, Qt.qRed(pixel)/16, Qt.qGreen(pixel)/16, Qt.qBlue(pixel)/16))
- f.write("\n")
-elif what == "5/6/5/8":
- colors = []
- writeSize(f, width, height)
- for y in range(height):
- for x in range(width):
- pixel = image.pixel(x, y)
- val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)
- # f.write("%d,%d,%d," % (val%256, val/256, Qt.qAlpha(pixel) >> 4))
- f.write("%d,%d," % (val%256, val/256))
- f.write("\n")
-elif what == "4bits":
- colors = []
- writeSize(f, width, height)
- for y in range(0, height, 2):
- for x in range(width):
- value = 0xFF;
- gray1 = Qt.qGray(image.pixel(x, y))
- if y+1 < height:
- gray2 = Qt.qGray(image.pixel(x, y+1))
- else:
- gray2 = Qt.qRgb(255, 255, 255)
- for i in range(4):
- if (gray1 & (1<<(4+i))):
- value -= 1<> 4)
- f.write("0x%02x," % value)
- f.write("\n")
-elif what == "03x05":
- for y in range(0, height, 5):
- for x in range(width):
- value = 0
- for z in range(5):
- if image.pixel(x, y+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- f.write("0x%02x," % value)
- f.write("\n")
-elif what == "04x06":
- for y in range(0, height, 7):
- for x in range(width):
- value = 0
- for z in range(7):
- if image.pixel(x, y+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- if value == 0x7f:
- value = 0xff
- f.write("0x%02x," % value)
- f.write("\n")
-elif what == "05x07":
- for y in range(0, height, 8):
- for x in range(width):
- value = 0
- for z in range(8):
- if image.pixel(x, y+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- f.write("0x%02x," % value)
- f.write("\n")
-elif what == "08x10":
- for y in range(0, height, 12):
- for x in range(width):
- skip = True
- for l in range(0, 12, 8):
+
+
+with open(sys.argv[2], "w") as f:
+ lcdwidth = int(sys.argv[3])
+
+ if len(sys.argv) > 4:
+ what = sys.argv[4]
+ else:
+ for s in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"):
+ if s in sys.argv[2]:
+ what = s
+ break
+
+ if what == "1bit":
+ rows = 1
+ if len(sys.argv) > 5:
+ rows = int(sys.argv[5])
+ writeSize(f, width, height // rows)
+ for y in range(0, height, 8):
+ for x in range(width):
value = 0
for z in range(8):
- if l+z < 12:
- if image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- else:
- skip = False
- if skip and l==8:
+ if y + z < height and image.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "4/4/4/4":
+ colors = []
+ f.write("%d,%d,\n" % (width, height))
+ for y in range(height):
+ for x in range(width):
+ pixel = image.pixel(x, y)
+ f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel) // 16, Qt.qRed(pixel) // 16, Qt.qGreen(pixel) // 16, Qt.qBlue(pixel) // 16))
+ f.write("\n")
+ elif what == "5/6/5/8":
+ colors = []
+ writeSize(f, width, height)
+ for y in range(height):
+ for x in range(width):
+ pixel = image.pixel(x, y)
+ val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)
+ # f.write("%d,%d,%d," % (val%256, val/256, Qt.qAlpha(pixel) >> 4))
+ f.write("%d,%d," % (val % 256, val // 256))
+ f.write("\n")
+ elif what == "4bits":
+ colors = []
+ writeSize(f, width, height)
+ for y in range(0, height, 2):
+ for x in range(width):
+ value = 0xFF
+ gray1 = Qt.qGray(image.pixel(x, y))
+ if y + 1 < height:
+ gray2 = Qt.qGray(image.pixel(x, y + 1))
+ else:
+ gray2 = Qt.qRgb(255, 255, 255)
+ for i in range(4):
+ if (gray1 & (1 << (4 + i))):
+ value -= 1 << i
+ if (gray2 & (1 << (4 + i))):
+ value -= 1 << (4 + i)
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "8bits":
+ colors = []
+ writeSize(f, width, height)
+ for y in range(height):
+ for x in range(width):
+ value = Qt.qGray(image.pixel(x, y))
+ value = 0x0f - (value >> 4)
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "03x05":
+ for y in range(0, height, 5):
+ for x in range(width):
+ value = 0
+ for z in range(5):
+ if image.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "04x06":
+ for y in range(0, height, 7):
+ for x in range(width):
+ value = 0
+ for z in range(7):
+ if image.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ if value == 0x7f:
value = 0xff
f.write("0x%02x," % value)
- f.write("\n")
-elif what == "10x14":
- for y in range(0, height, 16):
- for x in range(width):
- for l in range(0, 16, 8):
+ f.write("\n")
+ elif what == "05x07":
+ for y in range(0, height, 8):
+ for x in range(width):
value = 0
for z in range(8):
- if image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0):
+ if image.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
value += 1 << z
f.write("0x%02x," % value)
- f.write("\n")
-elif what == "22x38":
- for y in range(0, height, 40):
- for x in range(width):
- for l in range(0, 40, 8):
- value = 0
- for z in range(8):
- if image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0):
- value += 1 << z
- f.write("0x%02x," % value)
- f.write("\n")
-else:
- print("wrong argument", sys.argv[4])
-
+ f.write("\n")
+ elif what == "08x10":
+ for y in range(0, height, 12):
+ for x in range(width):
+ skip = True
+ for l in range(0, 12, 8):
+ value = 0
+ for z in range(8):
+ if l + z < 12:
+ if image.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ else:
+ skip = False
+ if skip and l == 8:
+ value = 0xff
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "10x14":
+ for y in range(0, height, 16):
+ for x in range(width):
+ for l in range(0, 16, 8):
+ value = 0
+ for z in range(8):
+ if image.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ f.write("0x%02x," % value)
+ f.write("\n")
+ elif what == "22x38":
+ for y in range(0, height, 40):
+ for x in range(width):
+ for l in range(0, 40, 8):
+ value = 0
+ for z in range(8):
+ if image.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
+ value += 1 << z
+ f.write("0x%02x," % value)
+ f.write("\n")
+ else:
+ print("wrong argument", sys.argv[4])
diff --git a/radio/util/include-guard.py b/radio/util/include-guard.py
index 53d3bdb9e..5a60f6b27 100755
--- a/radio/util/include-guard.py
+++ b/radio/util/include-guard.py
@@ -1,11 +1,13 @@
#!/usr/bin/env python
-import sys, os
+from __future__ import print_function
+
+import sys
+import os
for filename in sys.argv[1:]:
- f = file(filename, "r")
- lines = f.readlines()
- f.close()
+ with open(filename, "r") as f:
+ lines = f.readlines()
newguard = "_" + os.path.basename(filename).upper().replace(".", "_") + "_"
@@ -13,16 +15,14 @@ for filename in sys.argv[1:]:
line = line.strip()
if line.startswith("#ifndef "):
guard = line[8:]
- if lines[i+1].strip() == "#define %s" % guard:
- print filename, ":", guard, "=>", newguard
+ if lines[i + 1].strip() == "#define %s" % guard:
+ print(filename, ":", guard, "=>", newguard)
lines[i] = "#ifndef %s\n" % newguard
- lines[i+1] = "#define %s\n" % newguard
+ lines[i + 1] = "#define %s\n" % newguard
end = -1
while not lines[end].strip().startswith("#endif"):
end -= 1
lines[end] = "#endif // %s\n" % newguard
- f = file(filename, "w")
- f.write("".join(lines))
- f.close()
- break
-
+ with open(filename, "w") as f:
+ f.write("".join(lines))
+ break
diff --git a/radio/util/luaexport.py b/radio/util/luaexport.py
index 5b785e8bb..fdc86dd41 100755
--- a/radio/util/luaexport.py
+++ b/radio/util/luaexport.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import print_function
import sys
import os
@@ -21,154 +22,150 @@ exports_script_outputs = []
warning = None
error = None
+
def checkName(name):
- global warning
- if name in dups_name:
- print "WARNING: Duplicate name %s found for constant %s" % (name, CONSTANT_VALUE)
- warning = True
- dups_name.append(name)
- if name != name.lower():
- print "WARNING: Name not in lower case %s found for constant %s" % (name, CONSTANT_VALUE)
- warning = True
+ global warning
+ if name in dups_name:
+ print("WARNING: Duplicate name %s found for constant %s" % (name, CONSTANT_VALUE))
+ warning = True
+ dups_name.append(name)
+ if name != name.lower():
+ print("WARNING: Name not in lower case %s found for constant %s" % (name, CONSTANT_VALUE))
+ warning = True
def LEXP(name, description):
- # print "LEXP %s, %s" % (name, description)
- checkName(name)
- exports.append( (CONSTANT_VALUE, name, description) )
+ # print "LEXP %s, %s" % (name, description)
+ checkName(name)
+ exports.append((CONSTANT_VALUE, name, description))
+
def LEXP_MULTIPLE(nameFormat, descriptionFormat, valuesCount):
- # print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
- for v in range(valuesCount):
- name = nameFormat + str(v)
- # print name
- checkName(name)
- exports_multiple.append( (CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount) )
+ # print "LEXP_MULTIPLE %s, %s, %s" % (nameFormat, descriptionFormat, valuesCount)
+ for v in range(valuesCount):
+ name = nameFormat + str(v)
+ # print name
+ checkName(name)
+ exports_multiple.append((CONSTANT_VALUE, nameFormat, descriptionFormat, valuesCount))
+
if len(sys.argv) < 3:
- print "Error: not enough arguments!"
- print "Usage:"
- print " luaexport.py