Example #1
0
def set_procedure(procedure):
    statuses = {}
    db_save = True
    expire_delta = 120
    if procedure == "lights_on":
        statuses = {"865": True, "led": True, "led_rgb": True}
    elif procedure == "lights_off":
        statuses = {"865": False, "led": False, "led_rgb": False}
    elif procedure == "movie":
        expire_delta = 150
        statuses = {"865": False, "led": False, "led_rgb": True}
    elif procedure == "schimb_apa":
        statuses = {"865": False, "led": True, "led_rgb": True, "pompa": False, "incalzitor": False}
    elif procedure == "feed":
        expire_delta = 10
        statuses = {"pompa": False}
    elif procedure == "reset":
        db_save = False
        TempCommands.clear_all()
        statuses = get_statuses()

    if db_save:
        TempCommands.add_entry(statuses, expire_delta)

    IO.set_pins(statuses)

    return procedure
Example #2
0
    def done_click(self):
        for i in range(len(self.radios)):
            if self.radios[i].getChecked():
                op = Operation(Operation.get_new_id(), self.theorems[i].formula.get_no_of_args_for_unique_form(),
                               self.textbox_scheme.getText(), self.textbox_name.getText(), Operation.EXPRESSION)
                Operation.global_operations.append(op)
                Theorem.theorems.append(Theorem(self.theorems[i].formula.get_def_theorem(op),18,"iojo",[]))

        IO.save()
        self.hide()
Example #3
0
    def download_data(self, after):
        def after1(json):
            Operation.global_operations = [Operation.from_dict(op) for op in json["operations"]]
            Theorem.theorems = [Theorem.from_dict(th) for th in json["theorems"]]
            self.label_done.setText("done")
            after()
            # put_request({"operations": [o.to_json() for o in Operation.global_operations],
            #              "theorems": [ax.to_json() for ax in Theorem.axioms]})

        IO.get_request(after1)
Example #4
0
    def run(self, mandatory=False, seconds=config["time_betwen_actions"]):
        if len(self.next_pins) == 0:
            return

        logging.warning(str(self.next_pins))
        if mandatory:
            pin_id = self.next_pins.pop(0)
            IO.change_pin_status(pin_id, self.required_status)
            self.next_operation_time = datetime.now() + timedelta(seconds=seconds)

        elif self.next_operation_time < datetime.now():
            self.run(mandatory=True)

        self.dump()
Example #5
0
    def download_data(self, after):
        def after1(json):
            Operation.global_operations = [
                Operation.from_dict(op) for op in json["operations"]
            ]
            Theorem.theorems = [
                Theorem.from_dict(th) for th in json["theorems"]
            ]
            self.label_done.setText("done")
            after()
            # put_request({"operations": [o.to_json() for o in Operation.global_operations],
            #              "theorems": [ax.to_json() for ax in Theorem.axioms]})

        IO.get_request(after1)
Example #6
0
 def done_click(self):
     self.theorem.folder = self.get_folder_name()
     Theorem.theorems.append(self.theorem)
     IO.save()
     self.hide()
Example #7
0
 def __init__(self, bin_path: str):
     self.__parsed = False
     self.__parsed_splash = {}
     self.__bytes = b""
     self.__iomanager = IO(bin_path, bytes)
Example #8
0
class LogoUtils:
    def __init__(self, bin_path: str):
        self.__parsed = False
        self.__parsed_splash = {}
        self.__bytes = b""
        self.__iomanager = IO(bin_path, bytes)

    def __get_splash_description(self, splash_bytes: bytes) -> str:
        """get_splash_description(splash) : return the description of the given splash byte array.

        Trunctacte array from 0x98 to 0xd8. (0xA0 to 0xd8 for non-formatted splash_bytes)

        0x98 is where the name of the file start, 0xd8 where it ends.
        64 bytes after 0x98.
        """
        if "SPLASH!!".encode() in splash_bytes:
            return copy(
                splash_bytes[0xE0:0x110]).decode("UTF-8").rstrip('\x00')
        return copy(splash_bytes[0xd8:0x108]).decode("UTF-8").rstrip('\x00')

    def __get_splash_name(self, splash_bytes: bytes) -> str:
        """get_splash_name(splash) : return the name of the given splash byte array.

        Trunctacte array from 0x98 to 0xd8. (0xA0 to 0xd8 for non-formatted splash_bytes)

        0x98 is where the name of the file start, 0xd8 where it ends.
        64 bytes after 0x98.
        """
        if "SPLASH!!".encode() in splash_bytes:
            return copy(splash_bytes[0xA0:0xE0]).decode("UTF-8").rstrip('\x00')
        return copy(splash_bytes[0x98:0xd8]).decode("UTF-8").rstrip('\x00')

    def __get_splash_content(self, splash_bytes: bytes) -> bytes:
        """get_splash_content(splash) : return the content of the given splash byte array.

        Trunctacte array from 0x200 to END. (0x1f8 for non-formatted splash_bytes)

        0x200 is where the content of the file start.
        """
        if "SPLASH!!".encode() in splash_bytes:
            return copy(splash_bytes[0x200:])
        return copy(splash_bytes[0x1f8:])

    def __get_splash_width(self, splash_bytes: bytes) -> int:
        """get_splash_width(splash) : return the width contained inside the byte array.

        Get the value contained in 0x?? (0x?? for non-formatted splash_bytes)
        """
        if "SPLASH!!".encode() in splash_bytes:
            return int.from_bytes(splash_bytes[0x24:0x28],
                                  'little',
                                  signed=True)
        return int.from_bytes(splash_bytes[0x1C:0x20], 'little', signed=True)

    def __get_splash_height(self, splash_bytes: bytes) -> int:
        """get_splash_height(splash) : return the height contained inside the byte array.

        Get the value contained in 0x?? (0x?? for non-formatted splash_bytes)
        """
        if "SPLASH!!".encode() in splash_bytes:
            return int.from_bytes(splash_bytes[0x20:0x24],
                                  'little',
                                  signed=True)
        return int.from_bytes(splash_bytes[0x18:0x1C], 'little', signed=True)

    def __parse_splash(self) -> dict:
        for index, splash in enumerate(self.__bytes.split(
                "SPLASH!!".encode())[1:],
                                       start=1):
            self.__parsed_splash.update({
                index: {
                    "name": self.__get_splash_name(splash),
                    "description": self.__get_splash_description(splash),
                    "dimentions": {
                        "width": self.__get_splash_width(splash),
                        "height": self.__get_splash_height(splash),
                    },
                    "content": self.__get_splash_content(splash)
                }
            })
        self.__parsed = True

    def __read_splash(self):
        self.__iomanager.read()
        self.__bytes = self.__iomanager.get_copy()

    def get_splashes(self):
        if not self.__parsed:
            self.__read_splash()
            self.__parse_splash()
        return self.__parsed_splash
Example #9
0
 def done_click(self):
     self.theorem.folder=self.get_folder_name()
     Theorem.theorems.append(self.theorem)
     IO.save()
     self.hide()
Example #10
0
def reload_pins():
    statuses = get_statuses()
    IO.set_pins(statuses)

    return str(statuses)
Example #11
0
def doser(pin_id, quantity):
    seconds = IO.temp_open(pin_id, quantity)
    return "just dosed '{}' for {} seconds".format(pin_id, seconds)
Example #12
0
def close_pin(pin_id):
    obj = TempCommands.add_entry({pin_id: False})
    IO.close(pin_id)
    return "<h1 style='color:blue'>Hello There, {}</h1>".format(pin_id)
Example #13
0
def open_pin(pin_id):
    obj = TempCommands.add_entry({pin_id: True})
    IO.open(pin_id)
    return "<h1 style='color:blue'>Hello There, {}</h1>".format(pin_id)