Skip to content

Commit

Permalink
update, ready for 0.9 release
Browse files Browse the repository at this point in the history
  • Loading branch information
w84death committed Aug 19, 2023
1 parent ebf1bc8 commit 25d64ca
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion buzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion bytebeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import neopixel


BUZZER_PIN = 4
BUZZER_PIN = 3
BUZZER_DUTY = 32768
PI = 3.1415926535
PI2 = PI*2
Expand Down
65 changes: 48 additions & 17 deletions smolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 $: "
Expand All @@ -46,40 +46,50 @@ 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 <filename>": "print filename content (alias: cat)",
"print <filename>": "print filename content (alias: cat)",
"info <filename>": "information about a file",
"reanme <filename> <new-filename>": "reanmes a file (alias move)",
"remove <filename>": "remove a file (be careful!) (alias: rm)",
"edit <filename>": "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 <command>": "manipulating on-board LED. Commands: `on`, `off`",
"exe <code>": "Running exec(code)",
"<filename>": "runs user program (without .py)"
"<filename>": "runs user program (without .py)",
".": "repeats last command"
}
self.last_command = ""

def boot(self):
machine.freq(self.cpu_speed_range["turbo"] * 1000000)
self.clear()
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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -452,3 +482,4 @@ def edit(self, filename=""):
os = smolOS()
os.boot()


0 comments on commit 25d64ca

Please sign in to comment.