summaryrefslogtreecommitdiff
path: root/utilities/flasher.py
diff options
context:
space:
mode:
authorSebastian Muszytowski <sebastian@muszytowski.net>2016-02-27 21:16:59 +0100
committerSebastian Muszytowski <sebastian@muszytowski.net>2016-02-27 21:16:59 +0100
commiteb89bd002c5af7612f2aa24881312711667dcc3e (patch)
tree3991ed77a5c673518808a9f1f83aeafa82a3831b /utilities/flasher.py
parent5c959f7d7ec7b432c0b97ec70fa7410774f3bc06 (diff)
add makefile option for mass-programming with
"make massprogram" which utilized the flasher.py utility.
Diffstat (limited to 'utilities/flasher.py')
-rw-r--r--utilities/flasher.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/utilities/flasher.py b/utilities/flasher.py
new file mode 100644
index 0000000..67f8c08
--- /dev/null
+++ b/utilities/flasher.py
@@ -0,0 +1,79 @@
+#!/usr/bin/python
+
+import sys
+import os
+from termcolor import colored
+
+try:
+ import tty, termios
+except ImportError:
+ try:
+ import msvcrt
+ except ImportError:
+ raise ImportError('getch not available')
+ else:
+ getch = msvcrt.getch
+else:
+ def getch():
+ """getch() -> key character
+
+ Read a single keypress from stdin and return the resulting character.
+ Nothing is echoed to the console. This call will block if a keypress
+ is not already available, but will not wait for Enter to be pressed.
+
+ If the pressed key was a modifier key, nothing will be detected; if
+ it were a special function key, it may return the first character of
+ of an escape sequence, leaving additional characters in the buffer.
+ """
+ fd = sys.stdin.fileno()
+ old_settings = termios.tcgetattr(fd)
+ try:
+ tty.setraw(fd)
+ ch = sys.stdin.read(1)
+ finally:
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+ return ch
+
+code_okay = """
+ ####### ## ## ### ## ##
+## ## ## ## ## ## ## ##
+## ## ## ## ## ## ####
+## ## ##### ## ## ##
+## ## ## ## ######### ##
+## ## ## ## ## ## ##
+ ####### ## ## ## ## ##
+"""
+
+code_error = """
+######## ######## ######## ####### ########
+## ## ## ## ## ## ## ## ##
+## ## ## ## ## ## ## ## ##
+###### ######## ######## ## ## ########
+## ## ## ## ## ## ## ## ##
+## ## ## ## ## ## ## ## ##
+######## ## ## ## ## ####### ## ##
+"""
+
+def printOkay():
+ print colored(code_okay, 'green')
+
+def printError():
+ print colored(code_error, 'red')
+
+flash_command = sys.argv[1]
+
+print colored("Using the following command to flash: ", "green")
+print flash_command
+
+while True:
+ print colored("Press any key to continue or 'q' to quit.","yellow")
+ char = getch()
+ print char
+ if ord(char) is ord('q'):
+ sys.exit(0)
+ return_code = os.system(flash_command)
+ if return_code > 0:
+ printError()
+ else:
+ printOkay()
+