Exemplo n.º 1
0
    def __init__(self, app):
        super(PhotoBooth, self).__init__()

        self.app = app

        self.dark = False
        self.veille_countdown = False
        self.fullscreen = False

        self.action_done = False

        self.movie = QMovie(r'ressources\Spinner-1s-400px_white.gif')

        self.camera = Camera(SCALE)
        self.ROTATE_180 = ROTATE_180

        self.relais = Relais(('light', 'fanPrinter', 'fanCam', ''))

        self.cam_thread = None
        self.cd_thread = None
        self.lastPhoto = None

        self.veille_th = None

        self.MainWindow = QtWidgets.QMainWindow()
        self.status = 0
        self.nbPrint = 0
        self.comptPrint = 0
        self.init_ui()

        self.printer_fan_thread = None
        self.upper_fan_th = Thread(target=upper_fan_controller,
                                   args=[self.relais])
        self.upper_fan_th.start()
Exemplo n.º 2
0
def init_pumps():
    result = db._get_pumpen()
    #Initalisiert alle Pumpen zum ersten mal
    for i in range(0, len(result)):
        Relais(result[i][1])
    #Holt sich die Globale Variable inited_pumps und setzt diese auf True
    global inited_pumps
    inited_pumps = True
class Program:
    _running = True
    _relais = None

    def __init__(self):
        self._relais = Relais(14)

    def __del__(self):
        del self._relais

    def run(self):
        time.sleep(1)
        print("Running...")
        while self._running:
            self._relais.activate()
            time.sleep(2.5)
            self._relais.deactivate()
            time.sleep(2.5)

    def stop(self):
        self._running = False
Exemplo n.º 4
0
class PhotoBooth(Ui_PhotoBooth):
    def __init__(self, app):
        super(PhotoBooth, self).__init__()

        self.app = app

        self.dark = False
        self.veille_countdown = False
        self.fullscreen = False

        self.action_done = False

        self.movie = QMovie(r'ressources\Spinner-1s-400px_white.gif')

        self.camera = Camera(SCALE)
        self.ROTATE_180 = ROTATE_180

        self.relais = Relais(('light', 'fanPrinter', 'fanCam', ''))

        self.cam_thread = None
        self.cd_thread = None
        self.lastPhoto = None

        self.veille_th = None

        self.MainWindow = QtWidgets.QMainWindow()
        self.status = 0
        self.nbPrint = 0
        self.comptPrint = 0
        self.init_ui()

        self.printer_fan_thread = None
        self.upper_fan_th = Thread(target=upper_fan_controller,
                                   args=[self.relais])
        self.upper_fan_th.start()

    def init_ui(self):

        self.setupUi(self.MainWindow)

        if SCALE != 1:
            self.set_scale()

        self.loading.setMovie(self.movie)
        self.movie.start()

        self.buttonExit.clicked.connect(lambda: self.close_window())
        self.buttonRestart.clicked.connect(lambda: self.show_cam())
        self.buttonPrinter.clicked.connect(lambda: self.send2printer())
        self.buttonDecrease.clicked.connect(lambda: self.change_nb_print(-1))
        self.buttonIncrease.clicked.connect(lambda: self.change_nb_print(1))
        self.buttonCancel.clicked.connect(lambda: self.mode_veille())
        self.veilleButton.clicked.connect(lambda: self.show_cam())
        self.buttonPhoto.clicked.connect(lambda: self.start_countdown())

        self.widgetPrint.hide()
        self.widgetPhoto.hide()
        self.warning.hide()
        self.countdown.hide()
        self.flash.hide()

        self.get_compt_print()

        self.MainWindow.show()
        self.show_cam()

        if not DEVELOPERMODE:
            self.full_screen()
            # self.widgetDevelopper.hide()

    def set_scale(self):
        font = QtGui.QFont()
        font.setFamily("Amatic")
        font.setPointSize(20)
        font.setBold(True)
        # font.setWeight(75)
        font.setPointSize(int(round(75 / SCALE, 0)))
        self.MainWindow.setFont(font)
        self.MainWindow.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)

        # font.setPointSize(36)
        font.setPointSize(int(round(36 / SCALE, 0)))
        self.compteur.setFont(font)

        # font.setPointSize(100)
        font.setPointSize(int(round(100 / SCALE, 0)))
        self.nbPrintLabel.setFont(font)

        font = QtGui.QFont()
        font.setFamily("Amatic")
        font.setPointSize(60)
        font.setBold(True)
        # font.setWeight(75)
        font.setPointSize(int(round(75 / SCALE, 0)))
        self.buttonIncrease.setFont(font)

        font = QtGui.QFont()
        # font.setPointSize(72)
        font.setPointSize(int(round(72 / SCALE, 0)))
        self.buttonPrinter.setFont(font)
        self.buttonRestart.setFont(font)
        self.buttonCancel.setFont(font)
        self.buttonPhoto.setFont(font)
        font.setFamily("Amatic")
        self.veilleButton.setFont(font)

        font = QtGui.QFont()
        font.setFamily("Amatic")
        # font.setPointSize(60)
        font.setPointSize(int(round(60 / SCALE, 0)))
        font.setBold(True)
        # font.setWeight(75)
        font.setPointSize(int(round(75 / SCALE, 0)))
        self.buttonDecrease.setFont(font)

        font = QtGui.QFont()
        # font.setPointSize(500)
        font.setPointSize(int(round(500 / SCALE, 0)))
        self.countdown.setFont(font)

        font = QtGui.QFont()
        # font.setPointSize(160)
        font.setPointSize(int(round(160 / SCALE, 0)))
        self.lookUp.setFont(font)

    def set_image(self, image):
        self.camView.setPixmap(QPixmap.fromImage(image))

    def full_screen(self):
        if self.fullscreen:
            self.MainWindow.showNormal()
        else:
            self.MainWindow.showFullScreen()
        self.fullscreen = not self.fullscreen

    def close_window(self):
        with open("run.txt", "w") as file:
            file.write("0")
        self.stop_veille()
        self.relais.close()
        self.camera.close()
        self.stop_cam()
        self.MainWindow.close()

    def show_photo(self):
        pixmap = self.lastPhoto.QImage

        self.viewer.setPixmap(pixmap)

        self.widgetPrint.show()

        self.change_nb_print(0)

    def start_countdown(self):
        self.action_done = True
        self.countdown.setText(
            QtCore.QCoreApplication.translate("MainWindow", '10'))
        self.countdown.show()
        self.buttonPhoto.hide()
        self.cd_thread = Thread(target=self.countdown_thread)
        self.cd_thread.start()

    def countdown_thread(self):
        cd = 10
        while cd > 0:
            sleep(1)
            cd -= 1

            self.countdown.setText(
                QtCore.QCoreApplication.translate("MainWindow", str(cd)))

            if cd == 8:
                focus_thread = Thread(target=self.camera.focus)
                focus_thread.start()

            elif cd == 2:
                self.loading.hide()

                self.camView.hide()
                stop_thread = Thread(target=self.stop_cam)
                stop_thread.start()
                self.camView.clear()

                self.lookUp.show()
                self.camView.hide()

            elif cd == 1:
                focus_thread = Thread(target=self.camera.focus, args=[True])
                focus_thread.start()

        self.take_photo()

        self.camView.show()

    def show_cam(self):
        self.buttonPhoto.hide()
        self.action_done = True
        self.camView.hide()
        self.veilleButton.hide()
        self.widgetPrint.hide()
        self.widgetPhoto.show()
        self.lookUp.hide()

        self.cam_thread = CamThread(self)
        self.cam_thread.start()

        if self.dark:
            self.relais.on('light')

        self.stop_veille()
        self.veille_countdown = True
        self.veille_th = Thread(target=self.veille_thread)
        self.veille_th.start()

    def veille_thread(self):
        timer = 0
        while timer < 60 and self.veille_countdown and self.camera.PhotoBoothWindow.is_open(
        ):
            timer += 1
            if self.action_done:
                timer = 0
                self.action_done = False
            # print("Veille thread - ", str(timer))
            sleep(1)
        if timer == 60:
            self.mode_veille()

    def mode_veille(self):
        self.stop_cam()
        self.veilleButton.show()
        self.relais.off('light')

    def stop_veille(self):
        self.veille_countdown = False
        if self.veille_th:
            while self.veille_th.is_alive():
                pass

    def stop_cam(self):
        # print(cam_thread)
        try:
            self.cam_thread.stop()
            self.cam_thread.quit()
            del self.cam_thread
        except AttributeError:
            pass
        # print("Closing")
        # print(cam_thread)

    def take_photo(self):

        old_pic = Photo()

        self.camera.trigger_on()
        self.flash.show()
        sleep(0.4)
        self.flash.hide()
        self.camera.trigger_off()
        self.widgetPhoto.hide()
        self.loading.show()
        self.countdown.hide()

        self.lastPhoto = Photo()
        while self.lastPhoto.path == old_pic.path:
            self.lastPhoto = Photo()

        # self.buttonPhoto.show()

        if self.lastPhoto.is_darker(1600):
            self.relais.on('light')
            self.dark = True
        self.lastPhoto.watermark()

        self.show_photo()

    def change_nb_print(self, i):
        self.action_done = True
        if i == 0:
            self.nbPrint = 1
        else:
            self.nbPrint = min(max(1, self.nbPrint + i), 6)
        self.nbPrintLabel.setText(
            QtCore.QCoreApplication.translate("MainWindow", str(self.nbPrint)))

    def printer_fan_controler(self):
        self.relais.on('fanPrinter')
        sleep(60)
        self.relais.off('fanPrinter')

    def send2printer(self):
        self.action_done = True
        for _ in range(self.nbPrint):
            printer(self.lastPhoto)

        self.printer_fan_thread = Thread(target=self.printer_fan_controler)
        self.printer_fan_thread.start()

        self.set_compt_print(self.nbPrint)
        self.show_cam()

    def get_compt_print(self):
        with open("compteur.txt", "r") as file:
            self.comptPrint = int(file.read())
        self.show_compt_print()

    def set_compt_print(self, n):
        self.comptPrint -= n
        with open("compteur.txt", "w") as file:
            file.write(str(self.comptPrint))
        self.show_compt_print()

        with open("Printlog.csv", "a") as csvFile:
            line = [str(datetime.now()), self.lastPhoto.name, str(n)]
            csvFile.write(';'.join(line))

    def show_compt_print(self):
        text = str(self.comptPrint) + '\nphotos\nrestantes'
        self.compteur.setText(
            QtCore.QCoreApplication.translate("MainWindow", text))
 def __init__(self):
     self._relais = Relais(14)
Exemplo n.º 6
0
    return cpu_temp


def upper_fan_controller(relais):

    while relais.running and win32gui.FindWindow(None, 'PhotoBooth') > 0:
        cpu_temp = get_cpu_temp()

        if cpu_temp > MAX_TEMP:
            # print("CPU Temp = " + str(cpu_temp) + ">" + str(MAX_TEMP) + " - Fan ON")
            relais.on('fanCam')

        if cpu_temp < MIN_TEMP:
            # print("CPU Temp = " + str(cpu_temp) + "<" + str(MIN_TEMP) + " - Fan OFF")
            relais.off('fanCam')

        sleep(1)

    if relais.running:
        relais.close()


if __name__ == '__main__':
    new_relais = Relais(('light', 'fanPrinter', 'fanCam', ''))
    # upper_fan_controller(new_relais)

    upper_fan_thread = Thread(target=upper_fan_controller, args=[new_relais])
    upper_fan_thread.start()

    # get_cpu_temp()
Exemplo n.º 7
0
from relais import Relais
import time

relais = Relais(('light', 'fanCam', 'fanPrinter', ''))

relais.on('light')
time.sleep(0.005)
relais.on('light')
relais.off('fanPrinter')
time.sleep(5)

for i in range(10):
    relais.on('light')
    time.sleep(0.005)
    relais.on('light')
    relais.off('fanCam')
    time.sleep(0.995)
    relais.off('light')
    time.sleep(0.005)
    relais.off('light')
    relais.on('fanCam')
    time.sleep(0.995)
time.sleep(3)
relais.off('fanCam')
relais.off('fanPrinter')
import signal
import time

import paho.mqtt.client as mqtt

try:
    from relais import Relais
except ImportError:
    from .relais import Relais

MQTT_HOST: str = "10.0.0.22"
MQTT_PORT: int = 1883
API_KEY: str = "tOiOdxFTpZwezrrpCT"
VALVE_ID: str = "valve01"

relais = Relais(14)


def get_topic(device_id):
    return "/" + API_KEY + "/" + device_id + "/cmd"

    # The callback for when the client receives a CONNACK response from the server.


def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc))
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    print("Subscribing to topic " + get_topic(VALVE_ID))
    client.subscribe(get_topic(VALVE_ID))