From 25d64ca5e649838e36a278121237f5290d989c81 Mon Sep 17 00:00:00 2001 From: Krzysztof Krystian Jankowski Date: Sat, 19 Aug 2023 15:17:20 +0200 Subject: [PATCH] update, ready for 0.9 release --- buzz.py | 2 +- bytebeat.py | 2 +- smolos.py | 65 +++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/buzz.py b/buzz.py index cd15939..c75ea73 100644 --- a/buzz.py +++ b/buzz.py @@ -81,7 +81,7 @@ def stop(self): time.sleep(0.1) self.buzzer.duty_u16(0) - def msg(self, message) + def msg(self, message): print(f"{self.name} : {message}") def run(self, note_duration=NOTE_DURATION): diff --git a/bytebeat.py b/bytebeat.py index b7a0210..fc68dea 100644 --- a/bytebeat.py +++ b/bytebeat.py @@ -11,7 +11,7 @@ import neopixel -BUZZER_PIN = 4 +BUZZER_PIN = 3 BUZZER_DUTY = 32768 PI = 3.1415926535 PI2 = PI*2 diff --git a/smolos.py b/smolos.py index c40fc9f..8bca012 100644 --- a/smolos.py +++ b/smolos.py @@ -3,8 +3,8 @@ ------------------------------------------------- Specialized Microcontroller-Oriented Lightweight Operating System -(c)2023/07 Krzysztof Krystian Jankowski -Homepage: https://smol.p1x.in/os/ +(c)2023/08 Krzysztof Krystian Jankowski +Homepage: http(s)://smol.p1x.in/os/ """ import machine @@ -15,12 +15,12 @@ import math import random -CPU_SPEED_SLOW = 40 # Mhz +CPU_SPEED_SLOW = 66 # Mhz CPU_SPEED_TURBO = 133 # Mhz SYSTEM_LED_PIN = 25 OS_NAME = "smolOS" -OS_VERSION = "almost-0.9" +OS_VERSION = "0.9" OS_VARIANT = "xiao" OS_BOARD_NAME = "Seeed XIAO RP2040" OS_PROMPT = "\nsmol $: " @@ -46,27 +46,34 @@ def __init__(self): "list": self.list,"ls": self.list,"dir": self.list, "print": self.show,"cat": self.show, "remove": self.remove,"rm": self.remove, + "rename": self.move,"move": self.move, "clear": self.clear,"cls": self.clear, "stats": self.stats, "turbo": self.toggle_turbo, "edit": self.edit,"ed": self.edit, "info": self.info, "led": self.led, - "exe": self.exe + "exe": self.exe, + "free": self.free, + ".": self.repeat_last } self.user_commands_manual = { "list": "list files (alias: ls, dir)", - "show ": "print filename content (alias: cat)", + "print ": "print filename content (alias: cat)", "info ": "information about a file", + "reanme ": "reanmes a file (alias move)", "remove ": "remove a file (be careful!) (alias: rm)", "edit ": "text editor, filename is optional (alias ed)", "clear": "clears the screen (alias cls)", "turbo": "toggles turbo mode (100% vs 50% CPU speed)", "stats": "system statistics", + "free": "available memory", "led ": "manipulating on-board LED. Commands: `on`, `off`", "exe ": "Running exec(code)", - "": "runs user program (without .py)" + "": "runs user program (without .py)", + ".": "repeats last command" } + self.last_command = "" def boot(self): machine.freq(self.cpu_speed_range["turbo"] * 1000000) @@ -74,12 +81,15 @@ def boot(self): self.welcome() while True: try: - self.REPL() + self.REPL(input(self.prompt)) except KeyboardInterrupt: break - def REPL(self): - user_input = input(self.prompt) + def REPL(self,user_input): + if user_input == ".": + user_input = self.last_command + else: + self.last_command = user_input parts = user_input.split() if len(parts) > 0: command = parts[0] @@ -154,6 +164,19 @@ def show(self, filename=""): else: self.print_err("No filename provided.") + def move(self, file_a="", file_b=""): + if not(file_a=="" or file_b==""): + if file_b not in self.protected_files: + try: + uos.rename(file_a,file_b) + print(f"File {file_a} renamed to {file_b}.") + except OSError: + self.print_err("Cannot rename file!") + else: + self.print_err("Cannot rename protected file!") + else: + self.print_err("No filename provided.") + def remove(self, filename=""): if filename: if filename not in self.protected_files: @@ -184,6 +207,10 @@ def stats(self): print("\t\033[0mFree space:\033[1m",uos.statvfs("/")[0] * uos.statvfs("/")[3],"bytes") print("\033[0m") + def free(self): + print("Free memory:\n\t\033[1m",gc.mem_free(),"bytes\033[0m") + print("\033[0mFree disk space:\n\t\033[1m",uos.statvfs("/")[0] * uos.statvfs("/")[3],"bytes\033[0m") + def toggle_turbo(self): self.turbo = not self.turbo if self.turbo: @@ -236,6 +263,9 @@ def run(self, command): except OSError: self.print_err(f"Problem with loading {command} program.") + def repeat_last(self): + self.REPL(self.last_command) + def unknown_function(self): self.print_err("Unknown function. Type 'help' for list of functions.") @@ -316,7 +346,7 @@ def edit(self, filename=""): elif show_help: self.man(ed_commands_manual) print("\n\033[7mHit [return] button\033[0m (or command) to go back to editing.\n") - + user_ed_input = input("\ned $: ") if user_ed_input =="quit": @@ -357,11 +387,11 @@ def edit(self, filename=""): elif user_ed_input == "<<": start_index = 0 - + elif user_ed_input == ">>": if line_count>UI_PAGE_SIZE: start_index = line_count-UI_PAGE_SIZE - + elif user_ed_input in ("save","write"): if filename == "": self.print_err("Your new file has no name. Use `name` followed by a file name and save again.") @@ -390,12 +420,12 @@ def edit(self, filename=""): new_file = True filename = "" file_edited = False - + elif user_ed_input[0]=="!" and len(user_ed_input)>1: line_count += 1 lines.append(user_ed_input[1:]+"\n") file_edited = True - else: + else: parts = user_ed_input.split(" ",1) if len(parts) == 1: try: @@ -425,7 +455,7 @@ def edit(self, filename=""): try: line_number = int(parts[0]) new_content = parts[1] - if line_number > 0: + if line_number > 0: if line_number <= line_count: lines[line_number - 1] = new_content + "\n" file_edited = True @@ -437,7 +467,7 @@ def edit(self, filename=""): file_edited = True else: self.print_err("Invalid line number.") - + except: self.print_err("Invalid command.") except KeyboardInterrupt: @@ -452,3 +482,4 @@ def edit(self, filename=""): os = smolOS() os.boot() +