From 8f611280566632d8d10c40f0b19cf125ce04a530 Mon Sep 17 00:00:00 2001 From: Krzysztof Krystian Jankowski Date: Fri, 28 Jul 2023 23:37:53 +0200 Subject: [PATCH] protection for wrong arguments added --- pixel.py | 13 ++++++------- smolos.py | 7 +++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pixel.py b/pixel.py index af78219..0323a55 100644 --- a/pixel.py +++ b/pixel.py @@ -20,6 +20,7 @@ class Pixel: def __init__(self, pin=12): """ Initialize the NeoPixel object. + Changes power on pin 11 for XIAO board """ self.name = "Pixel" self.power = machine.Pin(11, machine.Pin.OUT) @@ -28,15 +29,9 @@ def __init__(self, pin=12): self.msg("Initialized.") def msg(self, message): - """ - Print a message from the program. - """ print(f"{self.name} : {message}") def color(self, color=((0,0,0))): - """ - Set the color of the NeoPixel. - """ self.pixel.fill(color) self.pixel.write() self.msg(f"Color set to: \n\t* Red {color[0]}\n\t* Green {color[1]}\n\t* Blue {color[2]}") @@ -80,7 +75,11 @@ def breath(self): break def run(self, color=(64, 64, 255)): - self.color(color) + if type(color) is tuple: + self.color(color) + else: + self.msg("Wrong color argument. Expected format: (0,0,0)\n") + if __name__ == '__main__': pixel = Pixel() diff --git a/smolos.py b/smolos.py index 5ab9020..a9ea326 100644 --- a/smolos.py +++ b/smolos.py @@ -284,7 +284,7 @@ def exe(self, code=""): else: self.print_err("No code provided.") - def run(self, command, arguments=""): + def run(self, command, argument=""): """ Run a program in the system. """ @@ -294,7 +294,10 @@ def run(self, command, arguments=""): #exec(code) exec(f"from {command} import {command[0].upper()+command[1:]}") exec(f"app={command[0].upper()+command[1:]}()") - exec(f"app.run({arguments})") + try: + exec(f"app.run({argument})") + except: + self.print_err("Wrong argument") except OSError: self.print_err(f"Problem with running {command} program")