# modeSelector # Contains the important URL endpoints for mode selection. Returns via AJAX the available modes and processes # requests via AJAX to switch the app across devices. import cv2 from app import app from flask import request, render_template import json from modules.kiwilog import kiwi import flask_login from flask.json import jsonify from modules.misc import list_apps from modules.globals import default_app from modules.kernel import switch log = kiwi.instance("modules.modeSelector") @app.route("/_app_change_request", methods=['GET', 'POST']) @flask_login.login_required def app_mod_process(): # TODO: Do this without restarting the device? app_req = request.args.get('app', 'Video Streaming', type=str) print("Requested to change app to ") print(app_req) switch(app_req) return '{}' @app.route("/_modeSelector", methods=['GET', 'POST']) @flask_login.login_required
from subprocess import Popen, PIPE from modules.kiwilog import kiwi log = kiwi.instance('modules.temp') from app import app import json @app.route('/measure_temp', methods=['POST', 'GET']) def get_temp(): command = 'cat /sys/class/thermal/thermal_zone0/temp' output = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) stdout, stderr = output.communicate() return str(int(int(stdout) / 1000)) + '°C'
from app import app import cv2 from app import app from flask import request, render_template import json from modules.kiwilog import kiwi import flask_login from flask.json import jsonify from modules.misc import list_apps from modules.globals import default_app from modules.camera import convert_size from random import randint from modules.camera import buffer_file import os log = kiwi.instance("modules.gallery") file_format = 'mp4' @app.route("/_delete_all", methods=['POST', 'GET']) def delete_img(): img_path = 'app/static/appstatic/simplestreamer/' thumb_path = 'app/static/appstatic/simplestreamer/thumbnails/' # Deletes all images in the gallery. This is a debug feature. FIXME delete_thumb_list = os.listdir(thumb_path) delete_img_list = os.listdir(img_path) delete_img_list = [x for x in delete_img_list if x != 'thumbnails'] # FIXME: This is trashy log.add_log(f"Deleting {delete_thumb_list} {delete_img_list}") for i in delete_img_list: os.remove(img_path + i) for j in delete_thumb_list:
# Copyright (c) 2020 Daniel Corcoran import os import urllib.request, json from modules.kiwilog import kiwi from app import app import requests import sys from flask import render_template, request import threading log = kiwi.instance("update") global_update_status = False # True if we are doing a system update update_pct = 0 update_size = 0 update_done = 0 total_size = 0 def request(url): try: global global_update_status global total_size global_update_status = True file_path = 'sys_flash.tar.xz' with open(file_path, 'wb') as f: log.add_log(f"Downloading {file_path}") response = requests.get(url, stream=True) total_size = int(response.headers.get('content-length'))
# Here we make OS calls to power off, or restart, the device. import os import sys import psutil import logging from modules.buzzer import disable_buzzer import threading import os from app import app import time from modules.kiwilog import kiwi log = kiwi.instance("modules.power") # FIXME: This is not secure. We don't want users to have sudo access. @app.route("/localAPI/power/off", methods=['POST', 'GET']) def power_off(): log.add_log("Power off command received") def power_off_command(): time.sleep(1) log.add_log("[* superuser *] invoking /bin/bash shutdown -h now") os.system('echo %s|sudo -S %s' % ('mendel', 'shutdown -h now')) thread = threading.Thread(target=power_off_command, args=()) thread.start() @app.route("/localAPI/power/reboot", methods=['POST', 'GET']) def reboot():
recording = False from os import listdir import os from modules.kiwilog import kiwi import datetime from threading import Thread, Lock from flask import jsonify import time import sys # TODO: Make the capture and record functions actually work. # Capture will probably be easiest. # save captures in /database/captures log = kiwi.instance('modules.camera') out = None eating_leftovers = False camera_mutex = Lock() fifo_queue = [] GLOBAL_FPS = 15 recording_start = datetime.datetime.now() file_format = 'mp4' import math frame = None buffer_file = '' # The name of a the buffering file (if there is one) buffer_pct = 0 # The percentage of a buffer that has been cleared
from app import app from flask import render_template from modules.kiwilog import kiwi log = kiwi.instance('exceptionhandler.ui') def main(): logs = log.get_exceptions() print(logs) print(len(logs)) html = '' for l in logs: html += render_template('exceptionhandler/err_frame.html', src=l, details=logs[l]) # If we reach this point, it means there was an exception. return render_template('exceptionhandler/import_err.html', html=html)
import cv2 from app import app from flask import request import json from modules.kiwilog import kiwi log = kiwi.instance("modules.orient_video") with open('database/see.json') as f: os_conf = json.load(f) orient = os_conf["counter_clockwise_rotation_count"] @app.route("/get_orient", methods=['POST', 'GET']) def get_orient(): # Return the orientation return json.dumps({"orient": orient, 'angle': 90*orient}) @app.route("/set_orient", methods=['POST', 'GET']) def set_orient(): global orient dir = request.form['direction'] # Dir is positive or negative 1. orient += int(dir) if orient > 3: orient = orient - 4 elif orient < 0: orient = orient + 4 global os_conf os_conf["counter_clockwise_rotation_count"] = orient with open('database/see.json', 'w') as f: print(f"Orient value is now {orient}")
## Network management UI # Provides modules for wi-fi setup from app import app from flask import render_template, request import os from modules.misc import list_apps from modules.kiwilog import kiwi from subprocess import PIPE, Popen from modules.update import check_update_api import json log = kiwi.instance('modules.networkui') with open('database/see.json') as f: see_config = json.load(f) default_app = see_config['default_app'] def get_nets(): string = os.popen('nmcli -t -m multiline dev wifi').read() schema = [] net_list = [] for row in string.split('\n'): data = row.split(':') if data[0] not in schema and data[0] != '': schema.append(data[0]) net = {} for row in string.split('\n'):
from modules import camera from app import app import flask_login from flask import render_template from modules.kiwilog import kiwi from modules import LED from flask import Response log = kiwi.instance('apps.simplestreamer') log.add_log('loaded simplestreamer dependencies') def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS #app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER # Load default app from database @app.route("/update") @flask_login.login_required def update_helper(): p = None # TODO: This needs to be fixed. IMPORTANT LED.blue() LED.green() if p == "Already up to date.": return init_config(up_to_date=True) else:
from modules.kiwilog import kiwi log = kiwi.instance('modules.LED') try: from periphery import GPIO cur_col = '' log.add_log("Sucessfully imported periphery.GPIO") b = GPIO(77, "out") # Actually blue r = GPIO(73, "out") # Actually red g = GPIO(138, "out") # Actually green ir = GPIO(141, "out") def red(): global cur_col if cur_col != 'red': log.add_log("LEDMode changed to RED") cur_col = 'red' r.write(True) g.write(False) b.write(False) def green(): global cur_col if cur_col != 'green': log.add_log("LEDMode changed to GREEN") cur_col = 'green' r.write(False) g.write(True) b.write(False)
import importlib from modules.kiwilog import kiwi from modules.globals import getGlobalConfig from program.Video_Streaming import main as video_streaming from program.Object_Detection import main as object_detection from program.Facial_Recognition import main as facial_recognition from program.Motion_Detection import main as motion_detection from threading import Lock import time switch_app_mutex = False #from program.Facial_Recognition import main as facial_recognition log = kiwi.instance('sys.modules.kernel') see_config = getGlobalConfig() default_app = see_config['default_app'] # TODO: This part needs to be abstracted/generalizable. if default_app == 'Video Streaming': video_streaming.initialize() elif default_app == 'Object Detection': object_detection.initialize() elif default_app == 'Motion Detection': motion_detection.initialize() elif default_app == 'Facial Recognition': facial_recognition.initialize() # #try:
from modules import LED from modules import buzzer from modules import login from modules import camera from modules.globals import getGlobalConfig from modules.install import install from modules.kiwilog import kiwi from modules.misc import list_apps from modules.modeSelector import * from modules import settings from modules import systemInformationAPI from modules import frontend from modules import gallery from modules.power import reboot, power_off log = kiwi.instance('sys.boot') log.add_log("Welcome to seeOS (COS).") app.secret_key = 'hello' UPLOAD_FOLDER = 'database/tmp' ALLOWED_EXTENSIONS = {'tree'} sys_update_available = False #Check if a system update is available update = modules.update.check_update_api() see_config = getGlobalConfig() default_app = see_config['default_app']