From af2d66f9e7a604cfec51d6e7b66d5f90827fe7bb Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Tue, 18 Oct 2016 12:46:55 +0200 Subject: Added functions, error-handling Added errorhandeler Added try-catch --- Raspberry Pi/python.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'Raspberry Pi/python.py') diff --git a/Raspberry Pi/python.py b/Raspberry Pi/python.py index 57cf380..6ebb805 100644 --- a/Raspberry Pi/python.py +++ b/Raspberry Pi/python.py @@ -1,6 +1,7 @@ """ Imports """ import logging import smbus +import sys import time import json import i2cPixel @@ -28,13 +29,38 @@ def lightStaircase(direction): return true +def errorHandler(type, errorMsg): + if type = 1: # Debug + logging.debug(errorMsg) + print("Debug Message: See logfile") + else if type = 2: # info + logging.info(errorMsg) + else if type = 3: # Warning + logging.warning(errorMsg) + else if type = 4: # Error + logging.error(errorMsg) + print("Error: See logfile") + else if type = 5: # Error + logging.critical(errorMsg) + print("Critical Error: See logfile") + else: + logging.critical(errorMsg) + print("Something went terribly wrong! Not even the errorhandler was able to find out what. Which basically means 'You are doomed'") + def setup(): - + + """ Setup Log File """ + logging.basicConfig(filename='error.log',level=logging.DEBUG) + + """ Print first line of log file """ + logging.info('Starting App') + """ Setup i2c communication """ i2cPixel.version() i2cPixel.setBus(1) i2cPixel.setAddress(0x04) + def main(): """ Wait for heartbeat from Arduino """ -- cgit v1.2.3