Ejemplo n.º 1
0
def main():
    logging.debug("=== MAIN START ===")

    # Increase stack size per thread this increases micropython recursion depth
    _thread.stack_size(8192 * 2)

    # Read and parse configuration from config.json
    utils.init()

    controller = MainController()

    # Check if configuration via access point has to be started
    if not config.cfg.ap_config_done or wake_reason() == PIN_WAKE:
        logging.debug("AP_DONE: {}, wake_reason: {}".format(
            config.cfg.ap_config_done, wake_reason()))
        logging.debug("SSID: {}, Password: {}".format(config.cfg.ssid,
                                                      config.cfg.password))
        if config.cfg.ssid != 'ssid' and config.cfg.password != 'password':
            logging.debug("SSID and password aren't default. Try to connect")
            pass
        else:
            logging.debug("=== Entering configuration mode ===")

            event = MainControllerEvent(
                MainControllerEventType.CONFIGURE_ACCESS_POINT)
            controller.add_event(event)

    logging.debug("Main loop")
    # If the device is powered on, then actual time from NTP server must be downloaded

    if reset_cause() == HARD_RESET or reset_cause(
    ) == PWRON_RESET or reset_cause() == SOFT_RESET:
        event = MainControllerEvent(MainControllerEventType.TEST_CONNECTION)
        controller.add_event(event)

    # Print actual time
    event = MainControllerEvent(MainControllerEventType.PRINT_TIME)
    controller.add_event(event)

    # Read temperature and humidity from the sensor and return the data as JSON
    event = MainControllerEvent(MainControllerEventType.GET_SENSOR_DATA)
    controller.add_event(event)

    # Connect to WIFI and publish JSON with data to AWS via MQTT
    event = MainControllerEvent(MainControllerEventType.PUBLISH_DATA)
    controller.add_event(event)

    # Good night!
    event = MainControllerEvent(MainControllerEventType.GO_TO_SLEEP,
                                callback=None,
                                ms=config.cfg.data_publishing_period_in_ms)
    controller.add_event(event)

    controller.perform()
Ejemplo n.º 2
0
 def __init__(self):
     uid = os.getuid()
     if uid != 0:
         print '请使用root用户操作'
         sys.exit(-1)
     self.welcome()
     self.quit_quit = False
     self.switch_queue = Queue.Queue(0)
     self.view_control_map = {
         'login': LoginController(),
         'bye': ByeController(),
         'main': MainController(),
     }
     self._init_db()
     logging.info('程序开始')
     Thread(target=self._watchdog_switch).start()
Ejemplo n.º 3
0
import sys

from PyQt5.Qt import QApplication

from controller.main_controller import MainController

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainController(
        user="******")  #"Pracownik dziekanatu")
    sys.exit(app.exec_())
Ejemplo n.º 4
0
import os.path
from sys import argv, exit

from qtpy.QtWidgets import QApplication

from controller import RegisterController
from controller.main_controller import MainController
from model import init_database, Account
from utils import get_app_folder
from view import RegisterDialog
from view.main_window import MainWindow

if __name__ == '__main__':
    app = QApplication(argv)
    init_database(os.path.join(get_app_folder(), "database.sqlite"))

    accounts = Account.select()

    if not accounts:
        register_controller = RegisterController()
        register_dialog = RegisterDialog(register_controller)
        register_dialog.exec()

    controller = MainController()
    window = MainWindow(controller)

    exit(app.exec_())
Ejemplo n.º 5
0
def main_ui():
    """ Main function. """
    # Create instances of the model and the controller
    view = MainView()
    model = None
    MainController(model=model, view=view)
Ejemplo n.º 6
0
'''import psycopg2

connection = psycopg2.connect(host="localhost", port="5432", database="db_lab1", user="******", password="******")
cursor = connection.cursor()
cursor.execute("SELECT * FROM game")
row = cursor.fetchone()

while row is not None:
	print(row)
	row = cursor.fetchone()

'''
import psycopg2
from config import config
from controller.main_controller import MainController

if __name__ == '__main__':
    connection = psycopg2.connect(**config)
    main_controller = MainController(connection)
    main_controller.start()
    main_controller.close()
Ejemplo n.º 7
0
def main():
    MainController().iniciar()
Ejemplo n.º 8
0
 def __init__(self):
     from controller.main_controller import MainController
     self.main_controller = MainController()
     self.tasks_queue = []
Ejemplo n.º 9
0
import sys

import qdarkstyle
from PyQt5.QtWidgets import QApplication

from controller.main_controller import MainController
from gui.main_window import MainWindow
from model.gol_model import GOLModel

app = QApplication(sys.argv)
# Set the dark style for PyQt5
app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyqt5'))

# Create the model, GUI and controller
gol_model = GOLModel()
main_window = MainWindow(gol_model)
main_controller = MainController(app, main_window, gol_model)

main_window.show()
sys.exit(app.exec_())