Example #1
0
def init():
    global __json
    import ujson
    from play32sys import path
    __p = path.join(path.get_data_path(), "sys_config.json")
    with open(__p, "rb") as f:
        __json = ujson.load(f)
    del __p
Example #2
0
def get_app_info(app_name):
    app_path = path.get_app_path(app_name)
    manifest_path = path.join(app_path, MANIFEST_FILE)
    display_name = app_name
    try:
        with open(manifest_path, "rb") as f:
            manifest = ujson.load(f)
        display_name = manifest[MANIFEST_KEY_NAME]
        icon_path = path.join(app_path, manifest[MANIFEST_KEY_ICON])
        with open(icon_path, "rb") as f:
            w, h, _, data, _ = pbm.read_image(f)
            assert (w, h) == (ICON_SIZE_W, ICON_SIZE_H)
        return display_name, icon_path, framebuf.FrameBuffer(
            data, w, h, framebuf.MONO_HLSB)
    except:
        with open(DEFAULT_ICON_PATH, "rb") as f:
            w, h, _, data, _ = pbm.read_image(f)
        return display_name, DEFAULT_ICON_PATH, framebuf.FrameBuffer(
            data, w, h, framebuf.MONO_HLSB)
Example #3
0
def run_app(app_name, *args, **kws):
    curr = uos.getcwd()
    uos.chdir(get_app_path(app_name))
    usys.path.insert(0, get_app_path(app_name))
    usys.path.insert(0, join(get_app_path(app_name), "lib"))
    try:
        if "appmain" in usys.modules:
            del usys.modules["appmain"]
        module = __import__("appmain")
        res = module.main(app_name, *args, **kws)
        del module
        return res
    finally:
        uos.chdir(curr)
        usys.path.remove(get_app_path(app_name))
        gc.collect()
Example #4
0
def select_file_gen(cwd=None, title="Files", text_yes="OK", text_no="CANCEL", f_file=True, f_dir=True):
    if cwd == None:
        cwd = uos.getcwd()
    cwd = path.abspath(cwd)
    gen_loading = progress_gen("", title)
    while True:
        if f_dir:
            files = [(False, "."), (False, "..")]
        else:
            files = [(False, "..")]
        for item in uos.ilistdir(cwd):
            gen_loading.send(None)
            yield None
            name = item[0]
            file_type = item[1]
            if (not f_file) and file_type != 0x4000:
                continue # filter file
            files.append((file_type != 0x4000, name))
        files.sort()
        files_list = [ x[1] for x in files]
        gen_select_in_list = select_list_gen(title, files_list, text_yes, text_no)
        selected_file_is_file = False
        selected_file = "."
        for v in gen_select_in_list:
            yield None
            if v != None:
                if v < 0:
                    yield "" # cancel
                else:
                    selected_file_is_file = files[v][0]
                    selected_file = files[v][1]
                    break
        if selected_file == ".":
            yield cwd
        elif selected_file == "..":
            cwd = _get_parent_dir(cwd)
            # continue
        else:
            new_path = path.join(cwd, selected_file)
            if selected_file_is_file:
                yield new_path
            else:
                cwd = new_path
Example #5
0
def clear_root_dir():
    for file in uos.listdir("/"):
        if file not in ["resource", "data", "tmp", "apps"]:
            path.rmtree(path.join("/", file))
Example #6
0
import uos, usys, ujson
from play32sys.path import join, get_tmp_path, get_app_path, get_component_path, clear_temporary_dir
from buildin_resource.image import DEFAULT_BOOT_ICON
import gc

VERSION = (1, 16, 0)
KEY_BOOT_APP = 'bapp'
KEY_BOOT_APP_PARAMS = 'bappp'
KEY_BOOT_APP_KEYWORDS = 'bappk'
KEY_BOOT_IMAGE_PATH = 'bimg'
DICT_FILE_PATH = join(get_tmp_path(), 'boot.json')

__boot_dict = None


def __init_dict():
    global __boot_dict
    if __boot_dict == None:
        pass
    try:
        with open(DICT_FILE_PATH, 'r') as f:
            __boot_dict = ujson.load(f)
    except:
        __boot_dict = {}


def __save_dict():
    if __boot_dict == None:
        return
    try:
        with open(DICT_FILE_PATH, 'w') as f:
Example #7
0
def init():
    global DEFAULT_ICON_PATH
    DEFAULT_ICON_PATH = path.join(path.get_component_path(THIS_APP_NAME),
                                  "images", "fallback_icon.pbm")
Example #8
0
from play32sys import path
import hal_battery
BATTERY_RECORD_PATH = path.join(path.get_data_path(), "battery.dat")
DEFAULT_BATTERY_CACHE_SIZE = 256

__battery_level = []
__last_log = []


def load_battery_level():
    global __battery_level
    __battery_level = []
    with open(BATTERY_RECORD_PATH, "rb") as f:
        while True:
            data = f.read(2)
            if len(data) <= 0:
                break
            __battery_level.append(int.from_bytes(data, "big"))
    __battery_level.sort()  # from small to big


def init_battery_value_cache(size=DEFAULT_BATTERY_CACHE_SIZE):
    __last_log.clear()
    for _ in range(size):
        __last_log.append(hal_battery.get_raw_battery_value())


def measure():
    __last_log.append(hal_battery.get_raw_battery_value())
    __last_log.pop(0)