Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 25, 2021. It is now read-only.

Commit 2eb7f92

Browse files
committed
Restore OpenPy OS v1.0
1 parent 66f678f commit 2eb7f92

File tree

211 files changed

+27679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+27679
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sys
2+
3+
from ucode import MICROPY_GIT_TAG, MICROPY_BUILD_DATE, MICROPY_HW_BOARD_NAME, MICROPY_HW_MCU_NAME
4+
from ucode import repl_input, repl_compile, repl_call
5+
6+
7+
def main():
8+
context = {"__name__": "<shell>"}
9+
10+
print("MicroPython",
11+
MICROPY_GIT_TAG,
12+
"on", MICROPY_BUILD_DATE + ";",
13+
MICROPY_HW_BOARD_NAME,
14+
"with", MICROPY_HW_MCU_NAME)
15+
16+
try:
17+
# noinspection PyStatementEffect
18+
help
19+
except NameError:
20+
pass
21+
else:
22+
print("Type \"help()\" for more information.")
23+
24+
while True:
25+
try:
26+
code = repl_input()
27+
except Exception as e:
28+
print(type(e).__name__, e)
29+
continue
30+
31+
if code == 'exit':
32+
break
33+
34+
try:
35+
func = repl_compile(code, context)
36+
except BaseException as e:
37+
sys.print_exception(e)
38+
continue
39+
40+
try:
41+
repl_call(func, context)
42+
except SystemExit as e:
43+
return e.args[0] if e.args else 0
44+
except BaseException as e:
45+
sys.print_exception(e)
46+
47+
48+
if __name__ == '__main__':
49+
main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import machine
2+
3+
import event
4+
import value
5+
6+
buf = []
7+
8+
9+
@machine.hook_stdin
10+
def input_handler():
11+
while not buf:
12+
event.wait(10)
13+
14+
return int(buf.pop(0))
15+
16+
17+
@event.register("key_down")
18+
def handle_key_down(_1, char, *_):
19+
buf.append(char)
20+
21+
22+
event.setup()
23+
value.setup()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import machine
2+
3+
from component import get_component, find_components
4+
from monitor import Monitor, _set_monitor
5+
6+
gpu = get_component("gpu")
7+
8+
screen = None
9+
for screen in find_components("screen"):
10+
if screen.getKeyboards():
11+
break
12+
13+
if gpu and screen:
14+
monitor = Monitor(gpu.address, gpu.type)
15+
monitor.bind(screen.address)
16+
w, h = monitor.maxResolution()
17+
monitor.w, monitor.h = w, h
18+
monitor.setResolution(w, h)
19+
monitor.setBackground(0x000000)
20+
monitor.setForeground(0xFFFFFF)
21+
monitor.fill(1, 1, w, h, " ")
22+
23+
24+
@machine.hook_stdout
25+
def print_handler(string):
26+
try:
27+
for char in string:
28+
monitor.put(char)
29+
except BaseException as e:
30+
machine.debug("print_handler exc =? %s: %s" % (type(e).__name__, e))
31+
32+
33+
_set_monitor(monitor)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import builtins
2+
import sys
3+
4+
5+
# noinspection PyShadowingBuiltins
6+
def input(prompt=None):
7+
if prompt is not None:
8+
print(prompt, end="")
9+
10+
read = sys.stdin.read
11+
write = sys.stdout.write
12+
buf = []
13+
ignore = 0
14+
while True:
15+
ch = read(1)
16+
if ignore > 0:
17+
ignore -= 1
18+
continue
19+
20+
if ch == '\n':
21+
write(ch)
22+
break
23+
elif ch == '\b':
24+
if buf:
25+
buf.pop()
26+
write(ch + "---")
27+
continue
28+
else:
29+
write(ch)
30+
buf.append(ch)
31+
32+
return ''.join(buf)
33+
34+
35+
builtins.input = input
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import uos
2+
3+
import computer
4+
from filesystem import FileSystem
5+
6+
uos.umount('/')
7+
uos.mount(FileSystem(__path__), '/')
8+
uos.mount(FileSystem(computer.get_tmp_address()), '/tmp')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error("This Operating System requires a CPU running the OpenPython architecture.")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""OpenPython Operating System"""
2+
3+
import sys
4+
5+
import machine
6+
import uos
7+
from ucomponent import invoke
8+
from uio import FileIO
9+
10+
11+
class FileSystem:
12+
def __init__(self, address):
13+
self.address = address
14+
15+
def mount(self, readonly, mkfs):
16+
pass
17+
18+
def umount(self):
19+
pass
20+
21+
def getcwd(self):
22+
return '/'
23+
24+
def ilistdir(self, dir):
25+
for name in invoke(self.address, 'list', dir):
26+
if invoke(self.address, 'isDirectory', dir + "/" + name):
27+
yield (name, 0x4000, 0, -1)
28+
else:
29+
yield (name, 0x8000, 0, 0)
30+
31+
def stat(self, path):
32+
if not invoke(self.address, 'exists', path):
33+
raise OSError(1)
34+
35+
return 0x4000 if invoke(self.address, 'isDirectory', path) else 0x8000, 0, 0, 0, 0, 0, 0, 0, 0, 0
36+
37+
def open(self, file, mode):
38+
return FileIO(self.address, file, mode)
39+
40+
41+
@machine.hook_stdin
42+
def input_handler():
43+
return 0
44+
45+
46+
@machine.hook_stdout
47+
def print_handler(string):
48+
machine.debug(string)
49+
50+
51+
def init():
52+
uos.mount(FileSystem(__path__), '/')
53+
sys.path.append('/lib')
54+
sys.path.append('/lib/micropython')
55+
56+
for filename in sorted(uos.listdir("/boot")):
57+
context = {'__name__': '__main__', '__path__': __path__}
58+
# noinspection PyUnresolvedReferences
59+
execfile("/boot/" + filename, context)
60+
61+
from shell import spawn
62+
spawn("/bin/python.py")
63+
64+
65+
if __name__ == "__main__":
66+
init()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from ucomponent import invoke, get_methods, get_doc, get_list
2+
3+
__all__ = ['Component', 'get_component', 'find_components', 'components']
4+
5+
PRIMARY_COMPONENTS = {}
6+
7+
8+
class ComponentMethod:
9+
def __init__(self, component, name):
10+
self.component = component
11+
self.name = name
12+
13+
def __call__(self, *args):
14+
return invoke(self.component.address, self.name, *args)
15+
16+
@property
17+
def __doc__(self):
18+
return get_doc(self.component.address, self.name)
19+
20+
def __repr__(self):
21+
doc = self.__doc__
22+
if doc:
23+
doc = "\n" + doc.replace(" -- ", "\n")
24+
else:
25+
doc = ""
26+
27+
return "ComponentMethod<{0!r}, {1!r}>{2}".format(self.component, self.name, doc)
28+
29+
30+
class Component:
31+
def __init__(self, address, type):
32+
self.address = address
33+
self.type = type
34+
35+
def __getattr__(self, name):
36+
return ComponentMethod(self, name)
37+
38+
def __dir__(self):
39+
return dir(object()) + ["address", "type"] + list(get_methods(self.address))
40+
41+
def __repr__(self):
42+
return "Component<{0}:{1}>".format(self.type, self.address)
43+
44+
45+
components = get_list # TODO: ?
46+
47+
48+
def set_primary(compoent):
49+
PRIMARY_COMPONENTS[compoent.type] = compoent
50+
51+
52+
def get_component(component_type):
53+
component = PRIMARY_COMPONENTS.get(component_type)
54+
if component:
55+
return component
56+
57+
for address in get_list(component_type):
58+
component = Component(address, component_type)
59+
set_primary(component)
60+
return component
61+
62+
return None
63+
64+
65+
# alias
66+
get = get_component
67+
68+
69+
def find_components(component_type):
70+
return [Component(address, component_type) for address in get_list(component_type)]
71+
72+
73+
# alias
74+
find = find_components
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# noinspection PyUnresolvedReferences
2+
from ucomputer import *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# noinspection PyUnresolvedReferences
2+
from uerrno import *

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /