Skip to content

Commit

Permalink
protection for wrong arguments added
Browse files Browse the repository at this point in the history
  • Loading branch information
w84death committed Jul 28, 2023
1 parent 9d53fd9 commit 8f61128
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 6 additions & 7 deletions pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]}")
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions smolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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")

Expand Down

0 comments on commit 8f61128

Please sign in to comment.