Esempio n. 1
0
def print_status() -> str:
    with ChiTuPrinter() as printer:
        # the printer sends periodic "ok" responses over serial. this means that
        # sometimes we get an unexpected response from the printer (an "ok" instead of
        # the print status we expected). due to this, we retry at most 3 times here
        # until we have a successful response. see issue #180
        selected_file = retry(
            printer.get_selected_file,
            UnexpectedPrinterResponse,
            num_retries=3,
        )
        print_status = retry(
            printer.get_print_status,
            UnexpectedPrinterResponse,
            num_retries=3,
        )

        if print_status.state == PrinterState.IDLE:
            progress = 0.0
            print_details = {}
        else:
            sliced_model_file = read_cached_sliced_model_file(
                config.get_files_directory() / selected_file)

            if print_status.current_byte == 0:
                current_layer = 1
            else:
                current_layer = (
                    sliced_model_file.end_byte_offset_by_layer.index(
                        print_status.current_byte) + 1)

            progress = (100.0 * none_throws(current_layer - 1) /
                        none_throws(sliced_model_file.layer_count))

            print_details = {
                "current_layer":
                current_layer,
                "layer_count":
                sliced_model_file.layer_count,
                "print_time_secs":
                sliced_model_file.print_time_secs,
                "time_left_secs":
                round(sliced_model_file.print_time_secs * (100.0 - progress) /
                      100.0),
            }

        return jsonify({
            "state": print_status.state.value,
            "selected_file": selected_file,
            "progress": progress,
            **print_details,
        })
Esempio n. 2
0
 def get_power_supply(self, name: str) -> PowerSupply:
     config = none_throws(self.config)
     try:
         return next(d for d in config.get_devices()
                     if isinstance(d, PowerSupply) and d.name == name)
     except StopIteration:
         raise Exception(f"Power Supply not found: {name}")
Esempio n. 3
0
def print_status() -> str:
    with ElegooMars() as elegoo_mars:
        selected_file = elegoo_mars.get_selected_file()
        print_status = elegoo_mars.get_print_status()

        if print_status.state == PrinterState.IDLE:
            progress = 0.0
            print_details = {}
        else:
            sliced_model_file = read_cached_sliced_model_file(
                config.get_files_directory() / selected_file
            )

            if print_status.current_byte == 0:
                current_layer = 1
            else:
                current_layer = (
                    sliced_model_file.end_byte_offset_by_layer.index(
                        print_status.current_byte
                    )
                    + 1
                )

            progress = (
                100.0
                * none_throws(current_layer - 1)
                / none_throws(sliced_model_file.layer_count)
            )

            print_details = {
                "current_layer": current_layer,
                "layer_count": sliced_model_file.layer_count,
                "print_time_secs": sliced_model_file.print_time_secs,
                "time_left_secs": round(
                    sliced_model_file.print_time_secs * (100.0 - progress) / 100.0
                ),
            }

        return jsonify(
            {
                "state": print_status.state.value,
                "selected_file": selected_file,
                "progress": progress,
                **print_details,
            }
        )
Esempio n. 4
0
def serve(path: str) -> Response:
    LOG.info(f"Serving `{path}`...")
    static_folder = none_throws(application.static_folder)
    if path != "" and os.path.exists(static_folder + "/" + path):
        LOG.info("Found static resource.")
        return send_from_directory(static_folder, path)
    else:
        LOG.info("Resource not found. Falling back to `index.html`")
        return send_from_directory(static_folder, "index.html")
Esempio n. 5
0
 def serial_controller(self) -> "SerialController":
     return none_throws(
         self._serial_controller,
         "Attempted to access SerialDevice without opening it first",
     )
Esempio n. 6
0
 def _render_device_info(
         self, device: DeviceInfoResponse) -> List[Tuple[str, str]]:
     if device.device_type == DeviceType.POWER_SUPPLY:
         return self._get_power_supply_info(
             none_throws(device.power_supply_info))
     raise Exception(f"Unknown device type {type(device)}")