|
|
@ -5,19 +5,22 @@ from fibonaccios.apploader import get_app |
|
|
|
import fibonaccios.apploader # apploader hack |
|
|
|
import fibonaccios.apploader # apploader hack |
|
|
|
import time |
|
|
|
import time |
|
|
|
import usb_cdc |
|
|
|
import usb_cdc |
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
class App: |
|
|
|
class App: |
|
|
|
def __init__(self, os, pid, name, *argv): |
|
|
|
def __init__(self, os, pid, name, wd, *argv): |
|
|
|
self.os = os |
|
|
|
self.os = os |
|
|
|
self.pid = pid |
|
|
|
self.pid = pid |
|
|
|
self.name = name |
|
|
|
self.name = name |
|
|
|
self.store = {} |
|
|
|
self.store = {} |
|
|
|
self.next_function = 'main' |
|
|
|
self.next_function = 'main' |
|
|
|
self.run_at = -1 |
|
|
|
self.run_at = -1 |
|
|
|
|
|
|
|
self.wd = wd |
|
|
|
self.argv = (self,) + argv |
|
|
|
self.argv = (self,) + argv |
|
|
|
self.waiting_for = -1 |
|
|
|
self.waiting_for = -1 |
|
|
|
|
|
|
|
|
|
|
|
def iterate(self): |
|
|
|
def iterate(self): |
|
|
|
|
|
|
|
os.chdir(self.wd) |
|
|
|
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps: |
|
|
|
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps: |
|
|
|
getattr(self, f'F_{self.next_function}')() |
|
|
|
getattr(self, f'F_{self.next_function}')() |
|
|
|
|
|
|
|
|
|
|
@ -34,6 +37,10 @@ class App: |
|
|
|
else: |
|
|
|
else: |
|
|
|
raise NotConsoleController(self.os.controllers[-1]) |
|
|
|
raise NotConsoleController(self.os.controllers[-1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chdir(self, wd): |
|
|
|
|
|
|
|
os.chdir(wd) |
|
|
|
|
|
|
|
self.wd = os.getcwd() |
|
|
|
|
|
|
|
|
|
|
|
def jump(self, function): |
|
|
|
def jump(self, function): |
|
|
|
self.next_function = function |
|
|
|
self.next_function = function |
|
|
|
|
|
|
|
|
|
|
@ -41,7 +48,10 @@ class App: |
|
|
|
self.run_at = time.monotonic() + seconds |
|
|
|
self.run_at = time.monotonic() + seconds |
|
|
|
|
|
|
|
|
|
|
|
def exec(self, command, *argv): |
|
|
|
def exec(self, command, *argv): |
|
|
|
self.os.apps[self.pid] = get_app(command)(self.os, self.pid, command, *argv) |
|
|
|
self.os.apps[self.pid] = get_app(command)(self.os, self.pid, command, self.wd, *argv) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def launch(self, command, *argv): |
|
|
|
|
|
|
|
return self.os.launch(command, self.wd, *argv) |
|
|
|
|
|
|
|
|
|
|
|
def wait(self, pid): |
|
|
|
def wait(self, pid): |
|
|
|
self.waiting_for = pid |
|
|
|
self.waiting_for = pid |
|
|
@ -65,7 +75,7 @@ class OS: |
|
|
|
self.console = usb_cdc.console |
|
|
|
self.console = usb_cdc.console |
|
|
|
usb_cdc.console.timeout = 0 |
|
|
|
usb_cdc.console.timeout = 0 |
|
|
|
self.next_pidi = 0 |
|
|
|
self.next_pidi = 0 |
|
|
|
self.launch('init') |
|
|
|
self.launch('init', '/') |
|
|
|
|
|
|
|
|
|
|
|
def iterate(self): |
|
|
|
def iterate(self): |
|
|
|
pid = list(self.apps.keys())[self.next_pidi] |
|
|
|
pid = list(self.apps.keys())[self.next_pidi] |
|
|
@ -87,8 +97,8 @@ class OS: |
|
|
|
while not self.controllers[-1] in self.apps.keys(): |
|
|
|
while not self.controllers[-1] in self.apps.keys(): |
|
|
|
self.controllers.pop() |
|
|
|
self.controllers.pop() |
|
|
|
|
|
|
|
|
|
|
|
def launch(self, app, *argv): |
|
|
|
def launch(self, app, wd, *argv): |
|
|
|
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, *argv) |
|
|
|
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, wd, *argv) |
|
|
|
self.next_new += 1 |
|
|
|
self.next_new += 1 |
|
|
|
return self.next_new - 1 |
|
|
|
return self.next_new - 1 |
|
|
|
|
|
|
|
|
|
|
|