├── .dockerignore ├── .env.example ├── .github └── workflows │ └── main.yaml ├── .gitignore ├── .prettierrc ├── .vscode └── extensions.json ├── Dockerfile ├── LICENSE ├── README.md ├── backend ├── __init__.py ├── api.py ├── asyncCameraClient.py ├── main.py ├── printer_ftp.py ├── printer_payload.py ├── printer_ws.py ├── printers.py ├── type_printer_status.py ├── types_printer.py └── types_ws.py ├── components.json ├── docker-compose.yaml ├── frontend ├── App.svelte ├── app.css ├── assets │ └── svelte.svg ├── lib │ ├── Dashboard.svelte │ ├── GitHubButton.svelte │ ├── ModeToggleButton.svelte │ ├── Navbar.svelte │ ├── Printer.svelte │ ├── components │ │ └── ui │ │ │ ├── alert-dialog │ │ │ ├── alert-dialog-action.svelte │ │ │ ├── alert-dialog-cancel.svelte │ │ │ ├── alert-dialog-content.svelte │ │ │ ├── alert-dialog-description.svelte │ │ │ ├── alert-dialog-footer.svelte │ │ │ ├── alert-dialog-header.svelte │ │ │ ├── alert-dialog-overlay.svelte │ │ │ ├── alert-dialog-title.svelte │ │ │ └── index.ts │ │ │ ├── ams │ │ │ ├── AmsStatus.svelte │ │ │ └── index.ts │ │ │ ├── aspect-ratio │ │ │ └── index.ts │ │ │ ├── badge │ │ │ ├── badge.svelte │ │ │ └── index.ts │ │ │ ├── button │ │ │ ├── button.svelte │ │ │ └── index.ts │ │ │ ├── card │ │ │ ├── card-content.svelte │ │ │ ├── card-description.svelte │ │ │ ├── card-footer.svelte │ │ │ ├── card-header.svelte │ │ │ ├── card-title.svelte │ │ │ ├── card.svelte │ │ │ └── index.ts │ │ │ ├── input │ │ │ ├── index.ts │ │ │ └── input.svelte │ │ │ ├── label │ │ │ ├── index.ts │ │ │ └── label.svelte │ │ │ ├── popover │ │ │ ├── index.ts │ │ │ └── popover-content.svelte │ │ │ ├── progress │ │ │ ├── index.ts │ │ │ └── progress.svelte │ │ │ ├── skeleton │ │ │ ├── index.ts │ │ │ └── skeleton.svelte │ │ │ ├── slider │ │ │ ├── index.ts │ │ │ └── slider.svelte │ │ │ ├── sonner │ │ │ ├── index.ts │ │ │ └── sonner.svelte │ │ │ ├── switch │ │ │ ├── index.ts │ │ │ └── switch.svelte │ │ │ └── tooltip │ │ │ ├── index.ts │ │ │ └── tooltip-content.svelte │ ├── printerModel.ts │ └── utils.ts ├── main.ts ├── typesApi.ts ├── typesPrinter.ts └── vite-env.d.ts ├── index.html ├── package-lock.json ├── package.json ├── poetry.lock ├── poetry.toml ├── postcss.config.js ├── public └── vite.svg ├── pyproject.toml ├── svelte.config.js ├── tailwind.config.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.node.json └── vite.config.ts /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .next 3 | node_modules 4 | .venv 5 | venv 6 | .ruff_cache 7 | .env 8 | .github 9 | dist 10 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | BAMBUI_PRINTER.MY-P1S.IP=192.168.123.42 2 | BAMBUI_PRINTER.MY-P1S.ACCESS_CODE=12345678 3 | BAMBUI_PRINTER.MY-P1S.SERIAL=01P00C12345678 4 | BAMBUI_PRINTER.MY-P1S.MODEL=P1S 5 | VITE_BACKEND_URL=localhost:8000 6 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Test and Build 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | tags: 8 | - "*" 9 | 10 | env: 11 | REGISTRY: ghcr.io 12 | IMAGE_NAME: ${{ github.repository }} 13 | 14 | jobs: 15 | format_ts: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | - uses: actions/setup-node@v4 20 | with: 21 | node-version: 22 22 | - name: Cache node modules 23 | id: cache-nodemodules 24 | uses: actions/cache@v3 25 | env: 26 | cache-name: cache-node-modules 27 | with: 28 | path: node_modules 29 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} 30 | restore-keys: | 31 | ${{ runner.os }}-build-${{ env.cache-name }}- 32 | ${{ runner.os }}-build- 33 | ${{ runner.os }}- 34 | 35 | - name: Install Dependencies 36 | if: steps.cache-nodemodules.outputs.cache-hit != 'true' 37 | run: npm ci 38 | 39 | - name: format 40 | run: npx prettier backend/ --check 41 | 42 | lint_format_typecheck_py: 43 | runs-on: ubuntu-latest 44 | steps: 45 | - uses: actions/checkout@v4 46 | 47 | - name: Install Python 48 | uses: actions/setup-python@v4 49 | with: 50 | python-version: "3.12" 51 | 52 | - uses: actions/cache@v3 53 | id: cache-venv 54 | with: 55 | path: ./.venv/ 56 | key: ${{ runner.os }}-venv-${{ hashFiles('**/pyproject.toml') }} 57 | restore-keys: | 58 | ${{ runner.os }}-venv- 59 | 60 | - run: pip install poetry 61 | - run: | 62 | poetry install --with dev --no-root 63 | if: steps.cache-venv.outputs.cache-hit != 'true' 64 | 65 | - name: Run Ruff 66 | run: | 67 | poetry run ruff check . 68 | poetry run ruff format . --check 69 | 70 | - name: typecheck 71 | run: | 72 | poetry run mypy . 73 | 74 | build_and_push: 75 | name: build_and_push 76 | runs-on: ubuntu-latest 77 | permissions: 78 | packages: write 79 | 80 | needs: 81 | - format_ts 82 | - lint_format_typecheck_py 83 | 84 | steps: 85 | - name: Check out repository code 86 | uses: actions/checkout@v4 87 | 88 | - name: Set up QEMU 89 | uses: docker/setup-qemu-action@v3 90 | 91 | - name: Set up Docker Buildx 92 | uses: docker/setup-buildx-action@v3 93 | 94 | - name: Docker meta 95 | id: meta 96 | uses: docker/metadata-action@v4 97 | env: 98 | DOCKER_METADATA_PR_HEAD_SHA: true 99 | with: 100 | images: | 101 | ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} 102 | tags: | 103 | type=raw,value=edge,enable=${{ github.ref == 'refs/heads/main' }} 104 | type=sha,format=short 105 | type=semver,pattern={{raw}} 106 | type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} 107 | 108 | - name: Login to Docker Hub 109 | uses: docker/login-action@v3 110 | with: 111 | registry: ${{ env.REGISTRY }} 112 | username: ${{ github.actor }} 113 | password: ${{ secrets.GITHUB_TOKEN }} 114 | 115 | - name: Build and push 116 | uses: docker/build-push-action@v4 117 | with: 118 | context: . 119 | push: true 120 | cache-from: type=gha 121 | cache-to: type=gha,mode=max 122 | tags: ${{ steps.meta.outputs.tags }} 123 | platforms: linux/amd64,linux/arm64/v8 124 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## ts 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | pnpm-debug.log* 9 | lerna-debug.log* 10 | 11 | node_modules 12 | dist 13 | dist-ssr 14 | *.local 15 | 16 | # Editor directories and files 17 | .vscode/* 18 | !.vscode/extensions.json 19 | .idea 20 | .DS_Store 21 | *.suo 22 | *.ntvs* 23 | *.njsproj 24 | *.sln 25 | *.sw? 26 | 27 | ## python 28 | .venv 29 | .env 30 | .ruff_cache 31 | .mypy_cache 32 | *.pyc 33 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | "semi": true, 4 | "singleQuote": false, 5 | "printWidth": 120, 6 | "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], 7 | "overrides": [ 8 | { 9 | "files": "*.svelte", 10 | "options": { 11 | "parser": "svelte" 12 | } 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["svelte.svelte-vscode"] 3 | } 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM --platform=$BUILDPLATFORM node:22-slim AS node-builder 2 | WORKDIR /code 3 | COPY package.json package-lock.json ./ 4 | RUN npm install 5 | 6 | COPY index.html svelte.config.js tsconfig.app.json tsconfig.json tsconfig.node.json vite.config.ts postcss.config.js tailwind.config.ts components.json ./ 7 | COPY public/ public/ 8 | COPY frontend/ frontend/ 9 | 10 | RUN npm run build 11 | 12 | 13 | 14 | FROM python:3.12-slim AS python-builder 15 | 16 | RUN pip install poetry 17 | 18 | WORKDIR /code 19 | COPY poetry.toml pyproject.toml poetry.lock /code/ 20 | 21 | RUN poetry install --no-root 22 | 23 | 24 | FROM python:3.12-slim 25 | 26 | ENV PYTHONDONTWRITEBYTECODE=1 27 | ENV PYTHONUNBUFFERED=1 28 | 29 | RUN apt-get update -y && apt-get install curl -y 30 | 31 | WORKDIR /code 32 | 33 | COPY --from=node-builder /code/dist/ /code/dist/ 34 | COPY --from=python-builder /code/.venv /code/.venv 35 | 36 | COPY backend /code/backend 37 | 38 | ENV VIRTUAL_ENV=/code/.venv 39 | ENV PATH="$VIRTUAL_ENV/bin:$PATH" 40 | 41 | EXPOSE 8080 42 | 43 | HEALTHCHECK --interval=10s --timeout=5s --start-period=3s --retries=3 \ 44 | CMD curl --fail http://localhost:8080/healthz || exit 1 45 | 46 | CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8080"] 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BambUI 2 | 3 | > This software is in a very early stage of development. Please note the liability clause of the AGPL license you agree to when using this program. 4 | 5 | A simple and slim UI for LAN mode of Bambu Lab Printers. 6 | I do not trust Bambu Cloud and wanted an easy way to access my Printer P1S via home VPN. 7 | I also do not like their Network Plugin for print monitoring, all current solutions including Home Assistant did not fit my needs, so I decided to build my own. 8 | Currently, only P1S printers are supported. The UI shows a lot of buttons, but all disabled ones are not implemented yet. 9 | 10 | Features: 11 | 12 | - Add as many printers as you like 13 | - Camera Stream 14 | - UI control 15 | - No Cloud required (works only in Lan Mode) 16 | - Mobile friendly 17 | - svelte, shadcn/ui, FastApi and docker (with vite and poetry) 18 | - Connections running via server, so printer CPU is not overutilized 19 | - Connect as many Clients as you want 20 | - ready to use docker image (see `docker-compose.yaml`) 21 | 22 | ## Installation 23 | 24 | The following printer models are supported: 25 | 26 | - P1 Series P1S and P1P 27 | - A1 Series A1 and A1M 28 | 29 | You will need 4 Env vars to add a printer: 30 | 31 | For the printer model following strings are used: `P1S`, `P1P`, `A1` or `A1M`. 32 | 33 | Replace `` with the apropiate values for your machine. 34 | You may add as many printers as you like. 35 | `` is an arbitrary name you give your machine. 36 | You may use it for identification. 37 | All env vars associated with one printer may have the same name. 38 | This name will be visible across the UI. 39 | You may choose this at any time. 40 | It has no functionality except identification and is no referral to the printer, so you may choose a name that you like. 41 | It will only be used within BambUI. 42 | You can add this env block for as many printers as you like. 43 | 44 | ```bash 45 | BAMBUI_PRINTER..IP= 46 | BAMBUI_PRINTER..ACCESS_CODE= 47 | BAMBUI_PRINTER..SERIAL= 48 | BAMBUI_PRINTER..MODEL= 49 | ``` 50 | 51 | ### Using docker commandline 52 | 53 | Start the service: 54 | 55 | ```bash 56 | docker run \ 57 | -p 8080:8080 \ 58 | --restart always \ 59 | -e BAMBUI_PRINTER.MY-P1S.IP=192.168.12.42 \ 60 | -e BAMBUI_PRINTER.MY-P1S.ACCESS_CODE=12345678 \ 61 | -e BAMBUI_PRINTER.MY-P1S.SERIAL=01P00C12345678 \ 62 | -e BAMBUI_PRINTER.MY-P1S.MODEL=P1S \ 63 | ghcr.io/fidoriel/bambui:edge 64 | ``` 65 | 66 | ### Using docker compose 67 | 68 | Write a compose file as bambui.yml: 69 | 70 | ```yaml 71 | services: 72 | bambui: 73 | image: ghcr.io/fidoriel/bambui:edge 74 | restart: always 75 | ports: 76 | - 8080:8080 77 | environment: 78 | - BAMBUI_PRINTER.MY-P1S.IP=192.168.12.42 79 | - BAMBUI_PRINTER.MY-P1S.ACCESS_CODE=12345678 80 | - BAMBUI_PRINTER.MY-P1S.SERIAL=01P00C12345678 81 | - BAMBUI_PRINTER.MY-P1S.MODEL=P1S 82 | ``` 83 | 84 | Start the service in the background (-d): 85 | 86 | ```bash 87 | docker compose -f bambui.yml up -d 88 | ``` 89 | 90 | ### Using a Portainer stack 91 | 92 | - Login to Portainer 93 | - Go to "Stacks" 94 | - Click "Add stack" 95 | - Enter the name "Bambui" 96 | - Paste the content of the bambui.yml file from "Using docker compose" into the "Web editor" 97 | - Click "Deploy the stack" 98 | 99 | ## Development 100 | 101 | Create an `.env` based on `.env.example` 102 | Set Up: 103 | 104 | ```bash 105 | poetry install 106 | uvicorn backend.main:app --port 8000 --env-file .env --reload 107 | npm i 108 | npm run dev 109 | ``` 110 | 111 | Lint 112 | 113 | ```bash 114 | mypy . 115 | ruff check . 116 | ruff format . 117 | npm run format 118 | npm run build 119 | ``` 120 | -------------------------------------------------------------------------------- /backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fidoriel/BambUI/8114a987b429f463c670c9360251cfba8ae9c649/backend/__init__.py -------------------------------------------------------------------------------- /backend/api.py: -------------------------------------------------------------------------------- 1 | from fastapi import APIRouter 2 | from .printers import printers 3 | from pydantic import BaseModel 4 | from .printers import SupportedPrinters, Printer 5 | import asyncio 6 | 7 | router = APIRouter() 8 | 9 | 10 | class PrinterResponse(BaseModel): 11 | name: str 12 | model: SupportedPrinters 13 | is_online: bool 14 | 15 | 16 | @router.get("/printers") 17 | async def get_printers() -> list[PrinterResponse]: 18 | async def get_printer_status(printer: Printer) -> PrinterResponse: 19 | return PrinterResponse( 20 | name=printer.name, model=printer.model, is_online=await printer.ping() 21 | ) 22 | 23 | return await asyncio.gather( 24 | *[get_printer_status(printer) for printer in printers.values()] 25 | ) 26 | -------------------------------------------------------------------------------- /backend/asyncCameraClient.py: -------------------------------------------------------------------------------- 1 | import ssl 2 | from logging import getLogger 3 | 4 | import asyncio 5 | from bambu_connect.CameraClient import CameraClient 6 | 7 | 8 | import logging 9 | 10 | logger = getLogger(__name__) 11 | 12 | logger = logging.getLogger(__name__) 13 | 14 | 15 | class AsyncCameraClient(CameraClient): 16 | async def capture_stream(self, img_callback): 17 | ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) 18 | ctx.check_hostname = False 19 | ctx.verify_mode = ssl.CERT_NONE 20 | 21 | jpeg_start = bytearray([0xFF, 0xD8, 0xFF, 0xE0]) 22 | jpeg_end = bytearray([0xFF, 0xD9]) 23 | read_chunk_size = 4096 24 | 25 | while self.streaming: 26 | try: 27 | reader, writer = await asyncio.open_connection( 28 | host=self.hostname, port=self.port, ssl=ctx 29 | ) 30 | 31 | logger.info("Connected to server") 32 | 33 | writer.write(self.auth_packet) 34 | await writer.drain() 35 | 36 | buf = bytearray() 37 | 38 | while self.streaming: 39 | try: 40 | data = await asyncio.wait_for( 41 | reader.read(read_chunk_size), timeout=5 42 | ) 43 | if not data: 44 | break 45 | 46 | buf += data 47 | img, buf = self.__find_jpeg__(buf, jpeg_start, jpeg_end) 48 | if img: 49 | await img_callback(bytes(img)) 50 | 51 | except Exception as e: 52 | logger.error("Error reading stream: %s", e) 53 | break 54 | 55 | writer.close() 56 | await writer.wait_closed() 57 | 58 | except Exception as e: 59 | logger.error(f"Connection error: {e}") 60 | await asyncio.sleep(1) 61 | break 62 | 63 | async def start_stream(self, img_callback): 64 | if self.streaming: 65 | logger.info("Stream for %s already running.", self.hostname) 66 | return 67 | 68 | self.streaming = True 69 | 70 | def on_done(task: asyncio.tasks.Task): 71 | try: 72 | task.result() 73 | except Exception as e: 74 | logger.error(f"Stream task encountered an error: {e}") 75 | finally: 76 | self.streaming = False 77 | 78 | try: 79 | self.stream_task = asyncio.create_task(self.capture_stream(img_callback)) 80 | self.stream_task.add_done_callback(on_done) 81 | except Exception as e: 82 | logger.error(f"An error occurred while starting the stream: {e}") 83 | self.streaming = False 84 | 85 | async def stop_stream(self): 86 | if not self.streaming: 87 | logger.warning("Stream for %s is not running.", self.hostname) 88 | return 89 | 90 | self.streaming = False 91 | if self.stream_task: 92 | await self.stream_task 93 | -------------------------------------------------------------------------------- /backend/main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI 2 | from fastapi.staticfiles import StaticFiles 3 | from .api import router as api_router 4 | import logging 5 | from fastapi.middleware.cors import CORSMiddleware 6 | from .printer_ws import router as ws_router 7 | from fastapi.responses import FileResponse 8 | 9 | logging.basicConfig(level=logging.INFO) 10 | logger = logging.getLogger(__name__) 11 | 12 | app = FastAPI() 13 | 14 | app.add_middleware( 15 | CORSMiddleware, 16 | allow_origins=["*"], 17 | allow_credentials=True, 18 | allow_methods=["*"], 19 | allow_headers=["*"], 20 | ) 21 | 22 | 23 | @app.get("/healthz") 24 | async def healthz() -> dict[str, str]: 25 | return {"status": "healthy"} 26 | 27 | 28 | app.include_router(api_router, prefix="/api") 29 | app.include_router(ws_router, prefix="/ws") 30 | 31 | app.mount("", StaticFiles(directory="dist/", html=True, check_dir=True), name="dist") 32 | 33 | 34 | @app.exception_handler(404) 35 | async def http_exception_handler(request, exc): 36 | return FileResponse("dist/index.html") 37 | -------------------------------------------------------------------------------- /backend/printer_ftp.py: -------------------------------------------------------------------------------- 1 | import aioftp 2 | import ssl 3 | from typing import Literal, ClassVar 4 | from pydantic import BaseModel 5 | from pathlib import PurePosixPath 6 | 7 | from contextlib import asynccontextmanager 8 | from typing import AsyncIterator 9 | 10 | 11 | class PrinterFileSystemEntry(BaseModel): 12 | entry_type: Literal["file", "dir"] 13 | path: PurePosixPath 14 | size: str 15 | modify: str 16 | 17 | supported_files: ClassVar[list[str]] = [".3mf"] 18 | 19 | @property 20 | def is_dir(self) -> bool: 21 | return self.entry_type == "dir" 22 | 23 | @property 24 | def is_file(self) -> bool: 25 | return self.entry_type == "file" 26 | 27 | @property 28 | def is_printable(self) -> bool: 29 | suffix = self.path.suffix.lower() 30 | return suffix in self.supported_files 31 | 32 | 33 | @asynccontextmanager 34 | async def ftps_connection( 35 | host: str, password: str, user: str = "bblp", port: int = 990 36 | ) -> AsyncIterator[aioftp.Client]: 37 | ctx = ssl.create_default_context() 38 | ctx.check_hostname = False 39 | ctx.verify_mode = ssl.CERT_NONE 40 | client = aioftp.Client(ssl=ctx) 41 | 42 | try: 43 | await client.connect(host, port=port) 44 | await client.login(user, password) 45 | yield client 46 | finally: 47 | await client.quit() 48 | -------------------------------------------------------------------------------- /backend/printer_payload.py: -------------------------------------------------------------------------------- 1 | from typing import Literal 2 | 3 | RAW_COMMAND_TYPE = ( 4 | dict[ 5 | str, 6 | dict[str, str | int | list[str] | list[int] | None] 7 | | int 8 | | str 9 | | list[str] 10 | | list[int] 11 | | None, 12 | ] 13 | | None 14 | ) 15 | 16 | FAN_NUM_PART = 1 17 | FAN_NUM_AUX = 2 18 | FAN_NUM_CHAMBER = 3 19 | 20 | 21 | def enable_light(status: bool) -> RAW_COMMAND_TYPE: 22 | mode = "on" if status else "off" 23 | return {"system": {"led_mode": mode}} 24 | 25 | 26 | def generate_gcode_payload( 27 | gcode_line: str, 28 | ) -> RAW_COMMAND_TYPE: 29 | return {"print": {"command": "gcode_line", "param": f"{gcode_line}"}} 30 | 31 | 32 | def generate_payload_speed_level( 33 | speed_level: Literal[1, 2, 3, 4], 34 | ) -> RAW_COMMAND_TYPE: 35 | return {"print": {"command": "print_speed", "param": f"{speed_level}"}} 36 | 37 | 38 | def bed_temp_command(temperature: int) -> RAW_COMMAND_TYPE: 39 | return generate_gcode_payload(f"M140 S{temperature}\n") 40 | 41 | 42 | def extruder_temp_command( 43 | temperature: int, 44 | ) -> RAW_COMMAND_TYPE: 45 | return generate_gcode_payload(f"M104 S{temperature}\n") 46 | 47 | 48 | def fan_speed_gcode(speed: int, fan_num: int) -> RAW_COMMAND_TYPE: 49 | return generate_gcode_payload(f"M106 P{fan_num} S{speed}\n") 50 | 51 | 52 | def fan_aux_command(speed: int) -> RAW_COMMAND_TYPE: 53 | return fan_speed_gcode(speed, FAN_NUM_AUX) 54 | 55 | 56 | def fan_chamber_command(speed: int) -> RAW_COMMAND_TYPE: 57 | return fan_speed_gcode(speed, FAN_NUM_CHAMBER) 58 | 59 | 60 | def fan_part_command(speed: int) -> RAW_COMMAND_TYPE: 61 | return fan_speed_gcode(speed, FAN_NUM_PART) 62 | 63 | 64 | def move_x_command(mm: int) -> RAW_COMMAND_TYPE: 65 | return generate_gcode_payload(f"G91\nG0 X{mm}\nG90\n") 66 | 67 | 68 | def move_y_command(mm: int) -> RAW_COMMAND_TYPE: 69 | return generate_gcode_payload(f"G91\nG0 Y{mm}\nG90\n") 70 | 71 | 72 | def move_z_command(mm: int) -> RAW_COMMAND_TYPE: 73 | return generate_gcode_payload(f"G91\nG0 Z{mm}\nG90\n") 74 | 75 | 76 | def move_e_command(mm: int) -> RAW_COMMAND_TYPE: 77 | return generate_gcode_payload(f"G91\nG0 E{mm}\nG90\n") 78 | 79 | 80 | def home_command() -> RAW_COMMAND_TYPE: 81 | return generate_gcode_payload("G28\n") 82 | 83 | 84 | def stop_command() -> RAW_COMMAND_TYPE: 85 | return {"print": {"command": "stop"}} 86 | 87 | 88 | def pause_command() -> RAW_COMMAND_TYPE: 89 | return {"print": {"command": "pause"}} 90 | 91 | 92 | def resume_command() -> RAW_COMMAND_TYPE: 93 | return {"print": {"command": "resume"}} 94 | 95 | 96 | def pushall_command() -> RAW_COMMAND_TYPE: 97 | return { 98 | "pushing": {"sequence_id": 0, "command": "pushall"}, 99 | "user_id": "1234567890", 100 | } 101 | 102 | 103 | def filament_load_spool() -> RAW_COMMAND_TYPE: 104 | return { 105 | "print": { 106 | "command": "ams_change_filament", 107 | "target": 255, 108 | "curr_temp": 215, 109 | "tar_temp": 215, 110 | } 111 | } 112 | 113 | 114 | def filament_unload_spool() -> RAW_COMMAND_TYPE: 115 | return { 116 | "print": { 117 | "command": "ams_change_filament", 118 | "target": 254, 119 | "curr_temp": 215, 120 | "tar_temp": 215, 121 | } 122 | } 123 | 124 | 125 | def resume_filament_action() -> RAW_COMMAND_TYPE: 126 | return { 127 | "print": { 128 | "command": "ams_control", 129 | "param": "resume", 130 | } 131 | } 132 | 133 | 134 | def calibration( 135 | bed_levelling: bool = True, 136 | motor_noise_cancellation: bool = True, 137 | vibration_compensation: bool = True, 138 | ) -> RAW_COMMAND_TYPE: 139 | bitmask = 0 140 | 141 | if bed_levelling: 142 | bitmask |= 1 << 1 143 | if vibration_compensation: 144 | bitmask |= 1 << 2 145 | if motor_noise_cancellation: 146 | bitmask |= 1 << 3 147 | 148 | return {"print": {"command": "calibration", "option": bitmask}} 149 | 150 | 151 | def start_print_file( 152 | filename: str, 153 | ) -> RAW_COMMAND_TYPE: 154 | return { 155 | "print": { 156 | "command": "project_file", 157 | "param": "Metadata/plate_1.gcode", 158 | "subtask_name": f"{filename}", 159 | "url": f"ftp://{filename}", 160 | "bed_type": "auto", 161 | "timelapse": False, 162 | "bed_leveling": True, 163 | "flow_cali": False, 164 | "vibration_cali": True, 165 | "layer_inspect": False, 166 | "use_ams": False, 167 | "profile_id": "0", 168 | "project_id": "0", 169 | "subtask_id": "0", 170 | "task_id": "0", 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /backend/printer_ws.py: -------------------------------------------------------------------------------- 1 | from fastapi import WebSocket, APIRouter 2 | from starlette.websockets import WebSocketState, WebSocketDisconnect 3 | from .printers import printers 4 | from logging import getLogger 5 | from typing import Any 6 | from .types_printer import PrinterRequest 7 | 8 | logger = getLogger(__name__) 9 | 10 | router = APIRouter() 11 | 12 | 13 | @router.websocket("/printer/{printer_id}") 14 | async def printer_websocket(websocket: WebSocket, printer_id: str): 15 | printer = printers.get(printer_id) 16 | if printer is None: 17 | await websocket.close(code=4004, reason="Invalid Printer Name") 18 | return 19 | 20 | await websocket.accept() 21 | 22 | async def socket_callback(data: dict[str, Any]) -> None: 23 | if websocket.client_state == WebSocketState.CONNECTED: 24 | await websocket.send_json(data) 25 | 26 | async with printer.client(socket_callback): 27 | try: 28 | while True: 29 | data = await websocket.receive_json() 30 | logger.info( 31 | "Received from user for %s %s %s", 32 | printer.name, 33 | printer.model, 34 | str(data)[:120], 35 | ) 36 | await printer.hanlde_request(PrinterRequest.from_printer_json(data)) 37 | 38 | except WebSocketDisconnect: 39 | pass 40 | except Exception as e: 41 | logger.exception("Error with printer %s", printer_id, exc_info=e) 42 | -------------------------------------------------------------------------------- /backend/printers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | from logging import getLogger 4 | from .asyncCameraClient import AsyncCameraClient 5 | from bambu_connect.utils.models import PrinterStatus 6 | from contextlib import asynccontextmanager 7 | from typing import AsyncGenerator, Callable, Coroutine 8 | from typing import Literal, Any 9 | from pydantic import BaseModel 10 | from uuid import uuid4 11 | from .types_ws import WsJpegImage 12 | from .printer_payload import pushall_command 13 | import ssl 14 | import asyncio 15 | from aiomqtt.client import MqttError, Client as MqttClient 16 | import json 17 | from .types_printer import PrinterRequest 18 | from .types_ws import WsError, WsMessage 19 | from .printer_ftp import PrinterFileSystemEntry, ftps_connection 20 | from ping3 import ping 21 | 22 | logger = getLogger(__name__) 23 | 24 | SupportedPrinters = Literal["P1S", "P1P", "A1", "A1M"] 25 | 26 | 27 | class Printer: 28 | subscribers: dict[str, Callable[[dict[str, Any]], Coroutine[Any, Any, None]]] 29 | camera_client: AsyncCameraClient | None 30 | mqtt_client: MqttClient | None 31 | printer_status: PrinterStatus | None 32 | printer_status_values: dict[str, Any] 33 | printer_subscriber_task: asyncio.tasks.Task | None 34 | 35 | name: str 36 | ip: str 37 | access_code: str 38 | serial: str 39 | model: SupportedPrinters 40 | username: str = "bblp" 41 | port: int = 8883 42 | ftp_port: int = 990 43 | 44 | full_push: bool = False 45 | latest_image: bytes | None = None 46 | 47 | def __init__( 48 | self, name: str, ip: str, access_code: str, serial: str, model: Literal["P1S"] 49 | ): 50 | self.name = name 51 | self.ip = ip 52 | self.serial = serial 53 | self.model = model 54 | self.access_code = access_code 55 | 56 | self.subscribers = {} 57 | self.camera_client = None 58 | self.mqtt_client = None 59 | self.printer_status = None 60 | self.printer_status_values = {} 61 | self.printer_subscriber_task = None 62 | 63 | @property 64 | def request_topic(self) -> str: 65 | return f"device/{self.serial}/request" 66 | 67 | @property 68 | def is_idle_print(self) -> str: 69 | return self.printer_status_values.get("print_type", "").lower() == "idle" 70 | 71 | async def image_callback(self, image: bytes) -> None: 72 | self.latest_image = image 73 | await self.callback_all_connected_ws(WsJpegImage.from_bytes(image)) 74 | 75 | async def start_printer_subscriber(self): 76 | if self.printer_subscriber_task is None or self.printer_subscriber_task.done(): 77 | self.printer_subscriber_task = asyncio.create_task( 78 | self.printer_subscriber() 79 | ) 80 | logger.info("Created new task for %s", self.name) 81 | 82 | def on_done(task: asyncio.tasks.Task): 83 | self.full_push = False 84 | try: 85 | task.result() 86 | except asyncio.CancelledError: 87 | logger.info("Printer subscriber cancelled for %s", self.name) 88 | except Exception as e: 89 | logger.exception( 90 | "Printer subscriber failed for %s: %s", self.name, e 91 | ) 92 | self.printer_subscriber_task = None 93 | if self.subscribers: 94 | self.printer_subscriber_task = asyncio.create_task( 95 | self.start_printer_subscriber() 96 | ) 97 | 98 | self.printer_subscriber_task.add_done_callback(on_done) 99 | 100 | async def start( 101 | self, callback: Callable[[dict[str, Any]], Coroutine[Any, Any, None]] 102 | ) -> None: 103 | if not self.subscribers: 104 | logger.error("Started Printer Connection without subscribers") 105 | return 106 | 107 | if self.camera_client is None: 108 | self.camera_client = AsyncCameraClient( 109 | hostname=self.ip, access_code=self.access_code 110 | ) 111 | if self.camera_client is not None: 112 | await self.camera_client.start_stream(self.image_callback) 113 | 114 | if self.mqtt_client is None: 115 | ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS) 116 | ssl_context.verify_mode = ssl.CERT_NONE 117 | ssl_context.check_hostname = False 118 | self.mqtt_client = MqttClient( 119 | hostname=self.ip, 120 | username=self.username, 121 | password=self.access_code, 122 | port=self.port, 123 | tls_insecure=True, 124 | tls_context=ssl_context, 125 | ) 126 | await self.start_printer_subscriber() 127 | 128 | async def stop(self, force: bool = False) -> None: 129 | if self.subscribers and not force: 130 | logger.info( 131 | "Not stopping %s %s because printer has connected users", 132 | self.name, 133 | self.model, 134 | ) 135 | return 136 | 137 | if force: 138 | logger.info( 139 | "Force stopping %s %s despite %d connected users", 140 | self.name, 141 | self.model, 142 | len(self.subscribers), 143 | ) 144 | 145 | if self.camera_client is not None: 146 | await self.camera_client.stop_stream() 147 | self.camera_client = None 148 | 149 | logger.info("Tasks for %s stopped", self.name) 150 | 151 | async def callback_all_connected_ws( 152 | self, payload: dict[str, Any] | BaseModel 153 | ) -> None: 154 | payload_dict = ( 155 | payload.model_dump() if isinstance(payload, BaseModel) else payload 156 | ) 157 | 158 | for callback in self.subscribers.values(): 159 | await callback(payload_dict) 160 | 161 | async def send_ws_error(self, message: str) -> None: 162 | await self.callback_all_connected_ws(WsError(message=message)) 163 | 164 | async def send_ws_message(self, message: str) -> None: 165 | await self.callback_all_connected_ws(WsMessage(message=message)) 166 | 167 | async def publish_request(self, payload: str | dict[str, Any]) -> None: 168 | if isinstance(payload, dict): 169 | payload = json.dumps(payload) 170 | 171 | if self.mqtt_client is not None: 172 | try: 173 | logger.info("Publishing %s to %s %s", payload, self.name, self.model) 174 | await self.mqtt_client.publish(self.request_topic, payload) 175 | except MqttError: 176 | await self.send_ws_error("Printer MQTT Connection Error") 177 | logger.error("Cannot send request because MQTT connection faulty") 178 | else: 179 | logger.error("Cannot send request because client not connected") 180 | 181 | async def request_full_push(self) -> None: 182 | if not self.full_push: 183 | await self.publish_request(json.dumps(pushall_command())) 184 | logger.info("Requested full push from %s %s", self.name, self.model) 185 | 186 | async def handle_system_callback(self, payload: dict[str, str]) -> None: 187 | pass 188 | 189 | async def printer_subscriber(self) -> None: 190 | while True: 191 | if not await self.ping(): 192 | await asyncio.sleep(10) 193 | await self.send_ws_error("Printer Offline") 194 | continue 195 | if self.mqtt_client is None: 196 | await asyncio.sleep(0.1) 197 | continue 198 | try: 199 | async with self.mqtt_client as client: 200 | await self.request_full_push() 201 | await client.subscribe(f"device/{self.serial}/report") 202 | async for message in client.messages: 203 | try: 204 | if not isinstance(message.payload, bytes): 205 | logger.error( 206 | "Printer %s %s sent unexpected %s", 207 | self.name, 208 | self.model, 209 | message.payload, 210 | ) 211 | continue 212 | payload = json.loads(message.payload) 213 | logger.info( 214 | "Received from %s %s %s", self.name, self.model, payload 215 | ) 216 | 217 | if self.printer_status_values is None: 218 | self.printer_status_values = {} 219 | 220 | if print_payload := payload.get("print"): 221 | self.printer_status_values.update(print_payload) 222 | if print_payload.get("msg") == 0: 223 | self.full_push = True 224 | 225 | elif system_payload := payload.get("system"): 226 | await self.handle_system_callback(system_payload) 227 | 228 | client_payload = { 229 | "type": "printer_status", 230 | "data": self.printer_status_values, 231 | } 232 | if self.full_push: 233 | await self.callback_all_connected_ws(client_payload) 234 | await self.request_full_push() 235 | 236 | except KeyError: 237 | logger.error( 238 | "Error while subscribing %s %s", self.name, self.model 239 | ) 240 | continue 241 | except MqttError: 242 | await asyncio.sleep(3) 243 | 244 | @asynccontextmanager 245 | async def client( 246 | self, callback: Callable[[dict[str, Any]], Coroutine[Any, Any, None]] 247 | ) -> AsyncGenerator[None, None]: 248 | uuid = str(uuid4()) 249 | self.subscribers[uuid] = callback 250 | await self.start(callback) 251 | try: 252 | yield None 253 | finally: 254 | del self.subscribers[uuid] 255 | await self.stop() 256 | 257 | async def force_refresh(self) -> None: 258 | logger.info("force restarting %s", self.name) 259 | await self.stop(force=True) 260 | for callback in self.subscribers.values(): 261 | await self.start(callback) 262 | 263 | async def hanlde_request(self, request: PrinterRequest) -> None: 264 | if request.data.check_idle and not self.is_idle_print: 265 | logger.info("Printer is not Idle") 266 | await self.send_ws_error("Printer not Idle") 267 | return 268 | await request.pre_server_command(self) 269 | if command := request.to_command(): 270 | await self.publish_request(command) 271 | await request.post_server_command(self) 272 | 273 | async def list_ftps_files(self) -> list[PrinterFileSystemEntry]: 274 | files = [] 275 | async with ftps_connection( 276 | host=self.ip, 277 | port=self.ftp_port, 278 | user=self.username, 279 | password=self.access_code, 280 | ) as client: 281 | raw_files = await client.list(recursive=False) 282 | for path, meta in raw_files: 283 | files.append( 284 | PrinterFileSystemEntry( 285 | path=path, 286 | entry_type=meta["type"], 287 | size=meta["size"], 288 | modify=meta["modify"], 289 | ) 290 | ) 291 | return files 292 | 293 | async def upload_ftps_file(self, file: bytes, file_path: str) -> None: 294 | async with ftps_connection( 295 | host=self.ip, 296 | port=self.ftp_port, 297 | user=self.username, 298 | password=self.access_code, 299 | ) as client: 300 | stream = await client.upload_stream(destination=file_path) 301 | await stream.write(file) 302 | stream.close() 303 | return None 304 | 305 | async def delete_ftps_file(self, file: bytes, file_path: str) -> None: 306 | async with ftps_connection( 307 | host=self.ip, 308 | port=self.ftp_port, 309 | user=self.username, 310 | password=self.access_code, 311 | ) as client: 312 | client.remove(path=file_path) 313 | return None 314 | 315 | async def ping(self) -> bool: 316 | ping_response = await asyncio.to_thread(ping, dest_addr=self.ip, timeout=1) 317 | return bool(ping_response) 318 | 319 | 320 | def parse_printers_from_env() -> dict[str, Printer]: 321 | printers_read: dict[str, dict[str, Any]] = {} 322 | for key, value in os.environ.items(): 323 | match = re.match(r"BAMBUI_PRINTER\.([^.]+)\.(IP|ACCESS_CODE|SERIAL|MODEL)", key) 324 | if match: 325 | name, attribute = match.groups() 326 | if name not in printers_read: 327 | printers_read[name] = {} 328 | printers_read[name][attribute.lower()] = value 329 | 330 | _printers = { 331 | name: Printer(name=name, **details) for name, details in printers_read.items() 332 | } 333 | logger.info("Printers: %s", ",".join(_printers.keys())) 334 | return _printers 335 | 336 | 337 | printers = parse_printers_from_env() 338 | -------------------------------------------------------------------------------- /backend/type_printer_status.py: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | from pydantic import BaseModel 3 | 4 | 5 | class Upload(BaseModel): 6 | status: str | None = None 7 | progress: int | None = None 8 | message: str | None = None 9 | 10 | 11 | class Online(BaseModel): 12 | ahb: bool | None = None 13 | rfid: bool | None = None 14 | version: int | None = None 15 | 16 | 17 | class VTTray(BaseModel): 18 | id: str | None = None 19 | tag_uid: str | None = None 20 | tray_id_name: str | None = None 21 | tray_info_idx: str | None = None 22 | tray_type: str | None = None 23 | tray_sub_brands: str | None = None 24 | tray_color: str | None = None 25 | tray_weight: str | None = None 26 | tray_diameter: str | None = None 27 | tray_temp: str | None = None 28 | tray_time: str | None = None 29 | bed_temp_type: str | None = None 30 | bed_temp: str | None = None 31 | nozzle_temp_max: str | None = None 32 | nozzle_temp_min: str | None = None 33 | xcam_info: str | None = None 34 | tray_uuid: str | None = None 35 | remain: int | None = None 36 | k: float | None = None 37 | n: int | None = None 38 | cali_idx: int | None = None 39 | 40 | 41 | class AMSEntry(BaseModel): 42 | humidity: str | None = None 43 | id: str | None = None 44 | temp: str | None = None 45 | tray: list[VTTray] | None = None 46 | 47 | 48 | class AMS(BaseModel): 49 | ams: list[AMSEntry] | None = None 50 | ams_exist_bits: str | None = None 51 | tray_exist_bits: str | None = None 52 | tray_is_bbl_bits: str | None = None 53 | tray_tar: str | None = None 54 | tray_now: str | None = None 55 | tray_pre: str | None = None 56 | tray_read_done_bits: str | None = None 57 | tray_reading_bits: str | None = None 58 | version: int | None = None 59 | insert_flag: bool | None = None 60 | power_on_flag: bool | None = None 61 | 62 | 63 | class IPCam(BaseModel): 64 | ipcam_dev: str | None = None 65 | ipcam_record: str | None = None 66 | timelapse: str | None = None 67 | resolution: str | None = None 68 | tutk_server: str | None = None 69 | mode_bits: int | None = None 70 | 71 | 72 | class LightsReport(BaseModel): 73 | node: str | None = None 74 | mode: str | None = None 75 | 76 | 77 | class UpgradeState(BaseModel): 78 | sequence_id: int | None = None 79 | progress: str | None = None 80 | status: str | None = None 81 | consistency_request: bool | None = None 82 | dis_state: int | None = None 83 | err_code: int | None = None 84 | force_upgrade: bool | None = None 85 | message: str | None = None 86 | module: str | None = None 87 | new_version_state: int | None = None 88 | new_ver_list: list[Any] | None = None 89 | cur_state_code: int | None = None 90 | idx2: int | None = None 91 | 92 | 93 | class PrinterStatus(BaseModel): 94 | upload: Upload | None = None 95 | nozzle_temper: float | None = None 96 | nozzle_target_temper: float | None = None 97 | bed_temper: float | None = None 98 | bed_target_temper: float | None = None 99 | chamber_temper: float | None = None 100 | mc_print_stage: str | None = None 101 | heatbreak_fan_speed: str | None = None 102 | cooling_fan_speed: str | None = None 103 | big_fan1_speed: str | None = None 104 | big_fan2_speed: str | None = None 105 | mc_percent: int | None = None 106 | mc_remaining_time: int | None = None 107 | ams_status: int | None = None 108 | ams_rfid_status: int | None = None 109 | hw_switch_state: int | None = None 110 | spd_mag: int | None = None 111 | spd_lvl: int | None = None 112 | print_error: int | None = None 113 | lifecycle: str | None = None 114 | wifi_signal: str | None = None 115 | gcode_state: str | None = None 116 | gcode_file_prepare_percent: str | None = None 117 | queue_number: int | None = None 118 | queue_total: int | None = None 119 | queue_est: int | None = None 120 | queue_sts: int | None = None 121 | project_id: str | None = None 122 | profile_id: str | None = None 123 | task_id: str | None = None 124 | subtask_id: str | None = None 125 | subtask_name: str | None = None 126 | gcode_file: str | None = None 127 | stg: list[Any] | None = None 128 | stg_cur: int | None = None 129 | print_type: str | None = None 130 | home_flag: int | None = None 131 | mc_print_line_number: str | None = None 132 | mc_print_sub_stage: int | None = None 133 | sdcard: bool | None = None 134 | force_upgrade: bool | None = None 135 | mess_production_state: str | None = None 136 | layer_num: int | None = None 137 | total_layer_num: int | None = None 138 | s_obj: list[Any] | None = None 139 | fan_gear: int | None = None 140 | hms: list[Any] | None = None 141 | online: Online | None = None 142 | ams: AMS | None = None 143 | ipcam: IPCam | None = None 144 | vt_tray: VTTray | None = None 145 | lights_report: list[LightsReport] | None = None 146 | upgrade_state: UpgradeState | None = None 147 | command: str | None = None 148 | msg: int | None = None 149 | sequence_id: str | None = None 150 | -------------------------------------------------------------------------------- /backend/types_printer.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel, field_validator 2 | from typing import Literal, Self, Any, TYPE_CHECKING 3 | import json 4 | from abc import abstractmethod 5 | from . import printer_payload as pl 6 | from .printer_payload import RAW_COMMAND_TYPE 7 | from pydantic import Field 8 | from typing import ClassVar 9 | from base64 import b64decode 10 | 11 | if TYPE_CHECKING: 12 | from .printers import Printer 13 | 14 | 15 | class PrinterBaseCommand(BaseModel): 16 | check_idle: ClassVar[bool] = False 17 | type: Literal[ 18 | "print_speed", 19 | "bed_temp", 20 | "extruder_temp", 21 | "fan_speed", 22 | "fan_part", 23 | "fan_aux", 24 | "fan_chamber", 25 | "move_x", 26 | "move_y", 27 | "move_z", 28 | "move_e", 29 | "move_home", 30 | "stop_print", 31 | "pause_print", 32 | "resume_print", 33 | "force_refresh", 34 | "load_filament", 35 | "unload_filament", 36 | "calibrate", 37 | "upload_file", 38 | "chamber_light", 39 | ] 40 | 41 | async def pre_server_command(self, printer: "Printer") -> None: 42 | pass 43 | 44 | @abstractmethod 45 | def to_command(self) -> RAW_COMMAND_TYPE: ... 46 | 47 | async def post_server_command(self, printer: "Printer") -> None: 48 | pass 49 | 50 | 51 | class ChamberLight(PrinterBaseCommand): 52 | type: Literal["chamber_light"] = "chamber_light" 53 | enable: bool 54 | 55 | def to_command(self) -> RAW_COMMAND_TYPE: 56 | return pl.enable_light(self.enable) 57 | 58 | 59 | class Temperature(PrinterBaseCommand): 60 | temperature: int 61 | 62 | 63 | class ExtruderTemp(Temperature): 64 | type: Literal["extruder_temp"] = "extruder_temp" 65 | 66 | def to_command(self) -> RAW_COMMAND_TYPE: 67 | return pl.extruder_temp_command(self.temperature) 68 | 69 | 70 | class BedTemp(Temperature): 71 | type: Literal["bed_temp"] = "bed_temp" 72 | 73 | def to_command(self) -> RAW_COMMAND_TYPE: 74 | return pl.bed_temp_command(self.temperature) 75 | 76 | 77 | class PrintSpeed(PrinterBaseCommand): 78 | type: Literal["print_speed"] = "print_speed" 79 | speed: Literal[1, 2, 3, 4] 80 | 81 | def to_command(self) -> RAW_COMMAND_TYPE: 82 | return pl.generate_payload_speed_level(self.speed) 83 | 84 | 85 | class FanSpeed(PrinterBaseCommand): 86 | speed: int 87 | 88 | 89 | class AuxFanSpeed(FanSpeed): 90 | type: Literal["fan_aux"] = "fan_aux" 91 | 92 | def to_command(self) -> RAW_COMMAND_TYPE: 93 | return pl.fan_aux_command(self.speed) 94 | 95 | 96 | class ChamberFanSpeed(FanSpeed): 97 | type: Literal["fan_chamber"] = "fan_chamber" 98 | 99 | def to_command(self) -> RAW_COMMAND_TYPE: 100 | return pl.fan_chamber_command(self.speed) 101 | 102 | 103 | class PartFanSpeed(FanSpeed): 104 | type: Literal["fan_part"] = "fan_part" 105 | 106 | def to_command(self) -> RAW_COMMAND_TYPE: 107 | return pl.fan_part_command(self.speed) 108 | 109 | 110 | class Move(PrinterBaseCommand): 111 | distance: int 112 | 113 | check_idle: ClassVar[bool] = True 114 | 115 | 116 | class MoveX(Move): 117 | type: Literal["move_x"] = "move_x" 118 | 119 | def to_command(self) -> RAW_COMMAND_TYPE: 120 | return pl.move_x_command(self.distance) 121 | 122 | 123 | class MoveY(Move): 124 | type: Literal["move_y"] = "move_y" 125 | 126 | def to_command(self) -> RAW_COMMAND_TYPE: 127 | return pl.move_y_command(self.distance) 128 | 129 | 130 | class MoveZ(Move): 131 | type: Literal["move_z"] = "move_z" 132 | 133 | def to_command(self) -> RAW_COMMAND_TYPE: 134 | return pl.move_z_command(self.distance) 135 | 136 | 137 | class MoveE(Move): 138 | type: Literal["move_e"] = "move_e" 139 | 140 | def to_command(self) -> RAW_COMMAND_TYPE: 141 | return pl.move_e_command(self.distance) 142 | 143 | 144 | class MoveHome(PrinterBaseCommand): 145 | type: Literal["move_home"] = "move_home" 146 | 147 | check_idle: ClassVar[bool] = True 148 | 149 | def to_command(self) -> RAW_COMMAND_TYPE: 150 | return pl.home_command() 151 | 152 | 153 | class StopPrint(PrinterBaseCommand): 154 | type: Literal["stop_print"] = "stop_print" 155 | 156 | def to_command(self) -> RAW_COMMAND_TYPE: 157 | return pl.stop_command() 158 | 159 | 160 | class PausePrint(PrinterBaseCommand): 161 | type: Literal["pause_print"] = "pause_print" 162 | 163 | def to_command(self) -> RAW_COMMAND_TYPE: 164 | return pl.pause_command() 165 | 166 | 167 | class ResumePrint(PrinterBaseCommand): 168 | type: Literal["resume_print"] = "resume_print" 169 | 170 | def to_command(self) -> RAW_COMMAND_TYPE: 171 | return pl.resume_command() 172 | 173 | 174 | class FilamentLoad(PrinterBaseCommand): 175 | type: Literal["load_filament"] = "load_filament" 176 | 177 | check_idle: ClassVar[bool] = True 178 | 179 | def to_command(self) -> RAW_COMMAND_TYPE: 180 | return pl.filament_load_spool() 181 | 182 | 183 | class FilamentUnload(PrinterBaseCommand): 184 | type: Literal["unload_filament"] = "unload_filament" 185 | 186 | check_idle: ClassVar[bool] = True 187 | 188 | def to_command(self) -> RAW_COMMAND_TYPE: 189 | return pl.filament_unload_spool() 190 | 191 | 192 | class ForceRefresh(PrinterBaseCommand): 193 | type: Literal["force_refresh"] = "force_refresh" 194 | 195 | async def pre_server_command(self, printer: "Printer") -> None: 196 | await printer.force_refresh() 197 | 198 | def to_command(self) -> RAW_COMMAND_TYPE: 199 | return None 200 | 201 | 202 | class Calibration(PrinterBaseCommand): 203 | type: Literal["calibrate"] = "calibrate" 204 | bed_levelling: bool = True 205 | motor_noise_cancellation: bool = True 206 | vibration_compensation: bool = True 207 | 208 | check_idle: ClassVar[bool] = True 209 | 210 | def to_command(self) -> RAW_COMMAND_TYPE: 211 | return pl.calibration( 212 | self.bed_levelling, 213 | self.motor_noise_cancellation, 214 | self.vibration_compensation, 215 | ) 216 | 217 | 218 | class PrintFile(PrinterBaseCommand): 219 | type: Literal["upload_file"] = "upload_file" 220 | file: bytes 221 | file_name: str 222 | 223 | check_idle: ClassVar[bool] = True 224 | 225 | @field_validator("file") 226 | def validate_file(cls, v: bytes) -> bytes: 227 | try: 228 | return b64decode(v) 229 | except (TypeError, ValueError): 230 | return v 231 | 232 | async def pre_server_command(self, printer: "Printer") -> None: 233 | await printer.upload_ftps_file(file=self.file, file_path=self.file_name) 234 | await printer.send_ws_message(f"File '{self.file_name}' uploaded") 235 | 236 | def to_command(self) -> RAW_COMMAND_TYPE: 237 | return pl.start_print_file(self.file_name) 238 | 239 | async def post_server_command(self, printer: "Printer") -> None: 240 | await printer.send_ws_message(f"Print '{self.file_name}' started") 241 | 242 | 243 | class PrinterRequest(BaseModel): 244 | data: ( 245 | PrintFile 246 | | Calibration 247 | | ForceRefresh 248 | | PrintSpeed 249 | | BedTemp 250 | | ExtruderTemp 251 | | PartFanSpeed 252 | | ChamberFanSpeed 253 | | AuxFanSpeed 254 | | MoveZ 255 | | MoveZ 256 | | MoveX 257 | | MoveE 258 | | MoveHome 259 | | StopPrint 260 | | PausePrint 261 | | ForceRefresh 262 | | FilamentLoad 263 | | FilamentUnload 264 | | PrintFile 265 | | ChamberLight 266 | | MoveY 267 | | ResumePrint 268 | ) = Field(discriminator="type") 269 | 270 | @classmethod 271 | def from_printer_json(cls, data: dict[Any, Any] | str) -> Self: 272 | json_data = data 273 | if isinstance(data, str): 274 | json_data = json.loads(data) 275 | 276 | return cls.model_validate_json(json.dumps({"data": json_data})) 277 | 278 | def to_command(self) -> RAW_COMMAND_TYPE: 279 | return self.data.to_command() 280 | 281 | async def pre_server_command(self, printer: "Printer") -> None: 282 | await self.data.pre_server_command(printer) 283 | 284 | async def post_server_command(self, printer: "Printer") -> None: 285 | await self.data.post_server_command(printer) 286 | -------------------------------------------------------------------------------- /backend/types_ws.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel 2 | from typing import Literal 3 | import base64 4 | 5 | 6 | class WsBaseCommand(BaseModel): 7 | type: Literal["error", "jpeg_image", "printer_status", "message"] 8 | 9 | 10 | class WsError(WsBaseCommand): 11 | type: Literal["error"] = "error" 12 | message: str 13 | 14 | 15 | class WsMessage(WsBaseCommand): 16 | type: Literal["message"] = "message" 17 | message: str 18 | 19 | 20 | class WsJpegImage(WsBaseCommand): 21 | type: Literal["jpeg_image"] = "jpeg_image" 22 | image: str # base64 23 | 24 | @classmethod 25 | def from_bytes(cls, image: bytes) -> "WsJpegImage": 26 | return WsJpegImage(image=base64.b64encode(image).decode("utf-8")) 27 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://next.shadcn-svelte.com/schema.json", 3 | "style": "default", 4 | "tailwind": { 5 | "config": "tailwind.config.ts", 6 | "css": "frontend/app.css", 7 | "baseColor": "zinc" 8 | }, 9 | "aliases": { 10 | "components": "$lib/components", 11 | "utils": "$lib/utils", 12 | "ui": "$lib/components/ui", 13 | "hooks": "$lib/hooks" 14 | }, 15 | "typescript": true, 16 | "registry": "https://next.shadcn-svelte.com/registry" 17 | } 18 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | bambui: 3 | image: ghcr.io/fidoriel/bambui:edge 4 | build: . 5 | env_file: 6 | - .env 7 | ports: 8 | - 8080:8080 9 | environment: 10 | - BAMBUI_PRINTER.MY-P1S.IP=192.168.123.42 11 | - BAMBUI_PRINTER.MY-P1S.ACCESS_CODE=12345678 12 | - BAMBUI_PRINTER.MY-P1S.SERIAL=01P00C12345678 13 | - BAMBUI_PRINTER.MY-P1S.MODEL=P1S 14 | -------------------------------------------------------------------------------- /frontend/App.svelte: -------------------------------------------------------------------------------- 1 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /frontend/app.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @layer base { 6 | :root { 7 | --background: 0 0% 100%; 8 | --foreground: 240 10% 3.9%; 9 | --muted: 240 4.8% 95.9%; 10 | --muted-foreground: 240 3.8% 46.1%; 11 | --popover: 0 0% 100%; 12 | --popover-foreground: 240 10% 3.9%; 13 | --card: 0 0% 100%; 14 | --card-foreground: 240 10% 3.9%; 15 | --border: 240 5.9% 90%; 16 | --input: 240 5.9% 90%; 17 | --primary: 240 5.9% 10%; 18 | --primary-foreground: 0 0% 98%; 19 | --secondary: 240 4.8% 95.9%; 20 | --secondary-foreground: 240 5.9% 10%; 21 | --accent: 240 4.8% 95.9%; 22 | --accent-foreground: 240 5.9% 10%; 23 | --destructive: 0 72.2% 50.6%; 24 | --destructive-foreground: 0 0% 98%; 25 | --ring: 240 10% 3.9%; 26 | --radius: 0.5rem; 27 | --sidebar-background: 0 0% 98%; 28 | --sidebar-foreground: 240 5.3% 26.1%; 29 | --sidebar-primary: 240 5.9% 10%; 30 | --sidebar-primary-foreground: 0 0% 98%; 31 | --sidebar-accent: 240 4.8% 95.9%; 32 | --sidebar-accent-foreground: 240 5.9% 10%; 33 | --sidebar-border: 220 13% 91%; 34 | --sidebar-ring: 217.2 91.2% 59.8%; 35 | } 36 | 37 | .dark { 38 | --background: 240 10% 3.9%; 39 | --foreground: 0 0% 98%; 40 | --muted: 240 3.7% 15.9%; 41 | --muted-foreground: 240 5% 64.9%; 42 | --popover: 240 10% 3.9%; 43 | --popover-foreground: 0 0% 98%; 44 | --card: 240 10% 3.9%; 45 | --card-foreground: 0 0% 98%; 46 | --border: 240 3.7% 15.9%; 47 | --input: 240 3.7% 15.9%; 48 | --primary: 0 0% 98%; 49 | --primary-foreground: 240 5.9% 10%; 50 | --secondary: 240 3.7% 15.9%; 51 | --secondary-foreground: 0 0% 98%; 52 | --accent: 240 3.7% 15.9%; 53 | --accent-foreground: 0 0% 98%; 54 | --destructive: 0 62.8% 30.6%; 55 | --destructive-foreground: 0 0% 98%; 56 | --ring: 240 4.9% 83.9%; 57 | --sidebar-background: 240 5.9% 10%; 58 | --sidebar-foreground: 240 4.8% 95.9%; 59 | --sidebar-primary: 224.3 76.3% 48%; 60 | --sidebar-primary-foreground: 0 0% 100%; 61 | --sidebar-accent: 240 3.7% 15.9%; 62 | --sidebar-accent-foreground: 240 4.8% 95.9%; 63 | --sidebar-border: 240 3.7% 15.9%; 64 | --sidebar-ring: 217.2 91.2% 59.8%; 65 | } 66 | } 67 | 68 | @layer base { 69 | * { 70 | @apply border-border; 71 | } 72 | body { 73 | @apply bg-background text-foreground; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /frontend/assets/svelte.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/lib/Dashboard.svelte: -------------------------------------------------------------------------------- 1 | 27 | 28 |
29 |

Available Printers

30 | 31 |
32 | {#if printers.length > 0} 33 | {#each printers as printer} 34 | 35 | 40 | 41 |
42 |

{printer.name}

43 |
44 |

{printer.model}

45 | 46 | 47 |
48 |
49 | {/each} 50 | {:else} 51 | 52 |
53 | 54 | 55 |
56 |
57 | 58 |
59 | 60 | 61 |
62 |
63 | {/if} 64 |
65 |
66 | -------------------------------------------------------------------------------- /frontend/lib/GitHubButton.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 20 | -------------------------------------------------------------------------------- /frontend/lib/ModeToggleButton.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 18 | -------------------------------------------------------------------------------- /frontend/lib/Navbar.svelte: -------------------------------------------------------------------------------- 1 | 27 | 28 |
29 |
30 | 33 | 34 |
35 | 36 | 37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /frontend/lib/Printer.svelte: -------------------------------------------------------------------------------- 1 | 179 | 180 |
181 |
182 | 183 |
184 | 185 | {#if connectionError} 186 |
{connectionError}
187 | {:else if imageUrl} 188 | Printer camera feed 189 | {:else} 190 |
Connecting to printer camera...
191 | {/if} 192 |
193 |
194 | 195 | 196 | 197 | 198 |
199 | 200 |
201 | 202 | 203 | {printerStatus?.gcode_file || "No file loaded"} 204 | 205 |
206 | 207 | 208 |
209 | 210 | 211 | {printerStatus?.print_type || "Idle"} 212 | 213 |
214 | 215 | 216 |
217 | 218 | 219 | {printerStatus?.layer_num || 0}/{printerStatus?.total_layer_num || 0} 220 | 221 |
222 | 223 | 224 |
225 | 226 | 227 | {printerStatus?.mc_remaining_time || "--"} 228 | 229 |
230 |
231 | 232 | 240 |
241 | 242 | 243 | 244 |
245 |
246 |

Status {printerStatus?.print_type} {printerStatus?.mc_percent}%

247 | 248 | 249 | 250 | 251 | 258 | 259 |

Pause

260 |
261 |
262 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 272 | 273 | 274 |

Stop

275 |
276 |
277 |
279 | 280 | 281 | Are you absolutely sure to Stop the Print? 282 | 283 | This action cannot be undone. The print cannot be resumed. 284 | 285 | 286 | 287 | Cancel 288 | { 290 | sendWsCommand(new StopPrint()); 291 | }} 292 | > 293 | Stop Print 294 | 295 | 296 | 297 |
298 | 299 | 300 | 301 | 302 | 311 | 312 |

Resume

313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |

{printerId}

323 |
324 | 328 | 329 | 335 |
336 |
337 | 338 | 339 | 340 |
341 | 342 |
343 | 344 |
345 |
346 | 353 | 360 |
361 |
362 | 363 | 364 |
365 | 372 | 379 | 388 | 395 | 402 |
403 | 404 | 405 |
406 |
407 | 414 | 421 |
422 |
423 |
424 | 425 | 426 |
427 | 428 |
429 | 436 | 443 | 450 | 457 |
458 | 459 | 460 |
461 | 468 | 475 | 482 | 489 |
490 | 491 | 492 |
493 | 500 | 507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 | 515 | Speed 516 |
517 | Normal 518 |
519 | { 522 | sendWsCommand(new PrintSpeed(value[0] as 1 | 2 | 3 | 4)); 523 | }} 524 | value={[1]} 525 | min={1} 526 | max={3} 527 | step={1} 528 | class="w-full" 529 | /> 530 |
531 |
532 |
533 |
534 | 535 | 536 | 537 | 538 |
539 |
540 |
541 | Nozzle 542 |
543 |
544 | {Math.round(printerStatus?.nozzle_temper ?? 0)}/{printerStatus?.nozzle_target_temper}°C 545 |
546 |
547 |
548 |
549 | Bed 550 |
551 |
552 | {Math.round(printerStatus?.bed_temper ?? 0)}/{printerStatus?.bed_target_temper}°C 553 |
554 |
555 |
556 |
557 | Chamber 558 |
559 |
{Math.round(printerStatus?.chamber_temper ?? 0)}°C
560 |
561 |
562 | { 566 | sendWsCommand(new ChamberLight(enabled)); 567 | }} 568 | /> 569 | 572 |
573 |
574 | 575 |
576 |
577 |
578 |
579 | 580 | Part Cooling 581 |
582 | {Math.round((Number(printerStatus?.cooling_fan_speed ?? 0) / 15) * 100)}% 583 |
584 | { 586 | sendWsCommand(new PartFanSpeed(value[0])); 587 | }} 588 | value={[printerStatus?.cooling_fan_speed]} 589 | max={15} 590 | step={1} 591 | class="w-full" 592 | /> 593 |
594 |
595 |
596 |
597 | 598 | Chamber 599 |
600 | {Math.round((Number(printerStatus?.big_fan2_speed ?? 0) / 15) * 100)}% 601 |
602 | { 604 | sendWsCommand(new ChamberFanSpeed(value[0])); 605 | }} 606 | value={[printerStatus?.big_fan2_speed || 0]} 607 | max={15} 608 | step={1} 609 | class="w-full" 610 | /> 611 |
612 |
613 |
614 |
615 | 616 | Auxillary 617 |
618 | {Math.round((Number(printerStatus?.big_fan1_speed ?? 0) / 15) * 100)}% 619 |
620 | { 622 | sendWsCommand(new AuxFanSpeed(value[0])); 623 | }} 624 | value={[printerStatus?.big_fan1_speed || 0]} 625 | max={15} 626 | step={1} 627 | class="w-full" 628 | /> 629 |
630 |
631 |
632 |
633 | {#if printerStatus?.ams?.ams_exist_bits === "1"} 634 | 635 | 636 | ({ 638 | id: tray.id || "", 639 | tray_id: tray.tray_id_name || "", 640 | material: tray.tray_type || "", 641 | k_factor: tray.k?.toFixed(3) || "0.00", 642 | color: tray.tray_color || "#808080", 643 | active: printerStatus?.ams?.tray_now === tray.id, 644 | nozzle_temp_max: tray.nozzle_temp_max || "0", 645 | nozzle_temp_min: tray.nozzle_temp_min || "0", 646 | tray_temp: tray.tray_temp || "0", 647 | tray_sub_brands: tray.tray_sub_brands || "None", 648 | tag_uid: tray.tag_uid || "None", 649 | })) || []} 650 | extSpool={{ 651 | id: printerStatus.vt_tray?.id || "", 652 | tray_id: printerStatus.vt_tray?.tray_id_name || "", 653 | material: printerStatus.vt_tray?.tray_type || "", 654 | k_factor: printerStatus.vt_tray?.k?.toFixed(3) || "0.00", 655 | color: printerStatus.vt_tray?.tray_color || "#808080", 656 | active: printerStatus?.ams?.tray_now === printerStatus.vt_tray?.id, 657 | }} 658 | humidity={printerStatus?.ams?.ams?.[0]?.humidity} 659 | /> 660 | 661 | 662 | {/if} 663 |
664 |
665 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-action.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-cancel.svelte: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-content.svelte: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 26 | 27 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-description.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-footer.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
19 | {@render children?.()} 20 |
21 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-header.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | {@render children?.()} 16 |
17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-overlay.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/alert-dialog-title.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/alert-dialog/index.ts: -------------------------------------------------------------------------------- 1 | import { AlertDialog as AlertDialogPrimitive } from "bits-ui"; 2 | import Title from "./alert-dialog-title.svelte"; 3 | import Action from "./alert-dialog-action.svelte"; 4 | import Cancel from "./alert-dialog-cancel.svelte"; 5 | import Footer from "./alert-dialog-footer.svelte"; 6 | import Header from "./alert-dialog-header.svelte"; 7 | import Overlay from "./alert-dialog-overlay.svelte"; 8 | import Content from "./alert-dialog-content.svelte"; 9 | import Description from "./alert-dialog-description.svelte"; 10 | 11 | const Root = AlertDialogPrimitive.Root; 12 | const Trigger = AlertDialogPrimitive.Trigger; 13 | const Portal = AlertDialogPrimitive.Portal; 14 | 15 | export { 16 | Root, 17 | Title, 18 | Action, 19 | Cancel, 20 | Portal, 21 | Footer, 22 | Header, 23 | Trigger, 24 | Overlay, 25 | Content, 26 | Description, 27 | // 28 | Root as AlertDialog, 29 | Title as AlertDialogTitle, 30 | Action as AlertDialogAction, 31 | Cancel as AlertDialogCancel, 32 | Portal as AlertDialogPortal, 33 | Footer as AlertDialogFooter, 34 | Header as AlertDialogHeader, 35 | Trigger as AlertDialogTrigger, 36 | Overlay as AlertDialogOverlay, 37 | Content as AlertDialogContent, 38 | Description as AlertDialogDescription, 39 | }; 40 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/ams/AmsStatus.svelte: -------------------------------------------------------------------------------- 1 | 63 | 64 |
65 | 66 |
67 | 68 |
69 | 70 |
71 | Ext Spool 72 |
73 | 74 | 75 |
76 |
77 | 78 |
79 | 80 |
88 | {#if extSpool.material} 89 |
90 | {extSpool.material} 91 | K{extSpool.k_factor} 92 |
93 |
94 | 95 |
96 | {:else} 97 |
98 | ? 99 |
100 | {/if} 101 |
102 | {#if extSpool.active} 103 | 104 | 107 | 108 | 109 | {/if} 110 |
111 |
112 |
113 | 114 | 115 |
116 |
117 | AMS 118 |
119 | 120 |
121 | {#each slots as slot, index} 122 |
123 |
{formatSlotName(slot.id)}
124 |
132 | {#if slot.material} 133 |
134 | {slot.material} 135 | K{slot.k_factor} 136 |
137 | 138 | 139 | 140 | 141 | 145 | 146 |
147 |
148 | Filament: 149 | {slot.material} 150 |
151 |
152 | Type: 153 | {slot.tray_sub_brands} 154 |
155 |
156 | Color: 157 | 161 |
162 |
163 | Nozzle Temperature: 164 |
165 | max: {slot.nozzle_temp_max}°C 166 | min: {slot.nozzle_temp_min}°C 167 |
168 |
169 |
170 | Serial Number: 171 | {slot.tag_uid} 172 |
173 | 174 |
Flow Dynamics
175 |
176 |
177 | Factor K: 178 | {slot.k_factor} 179 |
180 |
181 |
182 |
183 |
184 | {:else} 185 |
186 | ? 187 |
188 | {/if} 189 |
190 | {#if slot.active} 191 | 192 | 195 | 196 | 197 | {/if} 198 |
199 | {/each} 200 |
201 |
202 | {6 - humidity} 203 |
204 |
207 | 208 |
209 | 210 | 211 | {#if humidity > 0} 212 |
216 | {/if} 217 | 218 | 219 | 220 |
221 |
222 |
223 |
224 |
225 |
226 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/ams/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./AmsStatus.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as AmsStatus, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/aspect-ratio/index.ts: -------------------------------------------------------------------------------- 1 | import { AspectRatio as AspectRatioPrimitive } from "bits-ui"; 2 | 3 | const Root = AspectRatioPrimitive.Root; 4 | 5 | export { Root, Root as AspectRatio }; 6 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/badge/badge.svelte: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/badge/index.ts: -------------------------------------------------------------------------------- 1 | import { type VariantProps, tv } from "tailwind-variants"; 2 | export { default as Badge } from "./badge.svelte"; 3 | 4 | export const badgeVariants = tv({ 5 | base: "focus:ring-ring inline-flex select-none items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2", 6 | variants: { 7 | variant: { 8 | default: "bg-primary text-primary-foreground hover:bg-primary/80 border-transparent", 9 | secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent", 10 | destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent", 11 | outline: "text-foreground", 12 | }, 13 | }, 14 | defaultVariants: { 15 | variant: "default", 16 | }, 17 | }); 18 | 19 | export type Variant = VariantProps["variant"]; 20 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/button/button.svelte: -------------------------------------------------------------------------------- 1 | 39 | 40 | 54 | 55 | {#if href} 56 | 57 | {@render children?.()} 58 | 59 | {:else} 60 | 63 | {/if} 64 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/button/index.ts: -------------------------------------------------------------------------------- 1 | import Root, { type ButtonProps, type ButtonSize, type ButtonVariant, buttonVariants } from "./button.svelte"; 2 | 3 | export { 4 | Root, 5 | type ButtonProps as Props, 6 | // 7 | Root as Button, 8 | buttonVariants, 9 | type ButtonProps, 10 | type ButtonSize, 11 | type ButtonVariant, 12 | }; 13 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card-content.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | {@render children?.()} 16 |
17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card-description.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |

15 | {@render children?.()} 16 |

17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card-footer.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | {@render children?.()} 16 |
17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card-header.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | {@render children?.()} 16 |
17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card-title.svelte: -------------------------------------------------------------------------------- 1 | 16 | 17 |
24 | {@render children?.()} 25 |
26 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/card.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 |
15 | {@render children?.()} 16 |
17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/card/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./card.svelte"; 2 | import Content from "./card-content.svelte"; 3 | import Description from "./card-description.svelte"; 4 | import Footer from "./card-footer.svelte"; 5 | import Header from "./card-header.svelte"; 6 | import Title from "./card-title.svelte"; 7 | 8 | export { 9 | Root, 10 | Content, 11 | Description, 12 | Footer, 13 | Header, 14 | Title, 15 | // 16 | Root as Card, 17 | Content as CardContent, 18 | Description as CardDescription, 19 | Footer as CardFooter, 20 | Header as CardHeader, 21 | Title as CardTitle, 22 | }; 23 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/input/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./input.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Input, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/input/input.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 23 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/label/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./label.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Label, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/label/label.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/popover/index.ts: -------------------------------------------------------------------------------- 1 | import { Popover as PopoverPrimitive } from "bits-ui"; 2 | import Content from "./popover-content.svelte"; 3 | const Root = PopoverPrimitive.Root; 4 | const Trigger = PopoverPrimitive.Trigger; 5 | const Close = PopoverPrimitive.Close; 6 | 7 | export { 8 | Root, 9 | Content, 10 | Trigger, 11 | Close, 12 | Root as Popover, 13 | Content as PopoverContent, 14 | Trigger as PopoverTrigger, 15 | Close as PopoverClose, 16 | }; 17 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/popover/popover-content.svelte: -------------------------------------------------------------------------------- 1 | 11 | 12 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/progress/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./progress.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Progress, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/progress/progress.svelte: -------------------------------------------------------------------------------- 1 | 13 | 14 | 21 |
25 |
26 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/skeleton/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./skeleton.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Skeleton, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/skeleton/skeleton.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/slider/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./slider.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Slider, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/slider/slider.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 19 | {#snippet children({ thumbs })} 20 | 21 | 22 | 23 | {#each thumbs as thumb} 24 | 28 | {/each} 29 | {/snippet} 30 | 31 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/sonner/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Toaster } from "./sonner.svelte"; 2 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/sonner/sonner.svelte: -------------------------------------------------------------------------------- 1 | 7 | 8 | 21 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/switch/index.ts: -------------------------------------------------------------------------------- 1 | import Root from "./switch.svelte"; 2 | 3 | export { 4 | Root, 5 | // 6 | Root as Switch, 7 | }; 8 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/switch/switch.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 22 | 27 | 28 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/tooltip/index.ts: -------------------------------------------------------------------------------- 1 | import { Tooltip as TooltipPrimitive } from "bits-ui"; 2 | import Content from "./tooltip-content.svelte"; 3 | 4 | const Root = TooltipPrimitive.Root; 5 | const Trigger = TooltipPrimitive.Trigger; 6 | const Provider = TooltipPrimitive.Provider; 7 | 8 | export { 9 | Root, 10 | Trigger, 11 | Content, 12 | Provider, 13 | // 14 | Root as Tooltip, 15 | Content as TooltipContent, 16 | Trigger as TooltipTrigger, 17 | Provider as TooltipProvider, 18 | }; 19 | -------------------------------------------------------------------------------- /frontend/lib/components/ui/tooltip/tooltip-content.svelte: -------------------------------------------------------------------------------- 1 | 12 | 13 | 22 | -------------------------------------------------------------------------------- /frontend/lib/printerModel.ts: -------------------------------------------------------------------------------- 1 | export interface Upload { 2 | status?: string; 3 | progress?: number; 4 | message?: string; 5 | } 6 | 7 | export interface Online { 8 | ahb?: boolean; 9 | rfid?: boolean; 10 | version?: number; 11 | } 12 | 13 | export interface VTTray { 14 | id?: string; 15 | tag_uid?: string; 16 | tray_id_name?: string; 17 | tray_info_idx?: string; 18 | tray_type?: string; 19 | tray_sub_brands?: string; 20 | tray_color?: string; 21 | tray_weight?: string; 22 | tray_diameter?: string; 23 | tray_temp?: string; 24 | tray_time?: string; 25 | bed_temp_type?: string; 26 | bed_temp?: string; 27 | nozzle_temp_max?: string; 28 | nozzle_temp_min?: string; 29 | xcam_info?: string; 30 | tray_uuid?: string; 31 | remain?: number; 32 | k?: number; 33 | n?: number; 34 | cali_idx?: number; 35 | } 36 | 37 | export interface AMSEntry { 38 | humidity?: string; 39 | id?: string; 40 | temp?: string; 41 | tray?: Array; 42 | } 43 | 44 | export interface AMS { 45 | ams?: Array; 46 | ams_exist_bits?: string; 47 | tray_exist_bits?: string; 48 | tray_is_bbl_bits?: string; 49 | tray_tar?: string; 50 | tray_now?: string; 51 | tray_pre?: string; 52 | tray_read_done_bits?: string; 53 | tray_reading_bits?: string; 54 | version?: number; 55 | insert_flag?: boolean; 56 | power_on_flag?: boolean; 57 | } 58 | 59 | export interface IPCam { 60 | ipcam_dev?: string; 61 | ipcam_record?: string; 62 | timelapse?: string; 63 | resolution?: string; 64 | tutk_server?: string; 65 | mode_bits?: number; 66 | } 67 | 68 | export interface LightsReport { 69 | node?: string; 70 | mode?: string; 71 | } 72 | 73 | export interface UpgradeState { 74 | sequence_id?: number; 75 | progress?: string; 76 | status?: string; 77 | consistency_request?: boolean; 78 | dis_state?: number; 79 | err_code?: number; 80 | force_upgrade?: boolean; 81 | message?: string; 82 | module?: string; 83 | new_version_state?: number; 84 | new_ver_list?: Array; 85 | cur_state_code?: number; 86 | idx2?: number; 87 | } 88 | 89 | export interface PrinterStatus { 90 | upload?: Upload; 91 | nozzle_temper?: number; 92 | nozzle_target_temper?: number; 93 | bed_temper?: number; 94 | bed_target_temper?: number; 95 | chamber_temper?: number; 96 | mc_print_stage?: string; 97 | heatbreak_fan_speed?: string; 98 | cooling_fan_speed?: string; 99 | big_fan1_speed?: string; 100 | big_fan2_speed?: string; 101 | mc_percent?: number; 102 | mc_remaining_time?: number; 103 | ams_status?: number; 104 | ams_rfid_status?: number; 105 | hw_switch_state?: number; 106 | spd_mag?: number; 107 | spd_lvl?: number; 108 | print_error?: number; 109 | lifecycle?: string; 110 | wifi_signal?: string; 111 | gcode_state?: string; 112 | gcode_file_prepare_percent?: string; 113 | queue_number?: number; 114 | queue_total?: number; 115 | queue_est?: number; 116 | queue_sts?: number; 117 | project_id?: string; 118 | profile_id?: string; 119 | task_id?: string; 120 | subtask_id?: string; 121 | subtask_name?: string; 122 | gcode_file?: string; 123 | stg?: Array; 124 | stg_cur?: number; 125 | print_type?: string; 126 | home_flag?: number; 127 | mc_print_line_number?: string; 128 | mc_print_sub_stage?: number; 129 | sdcard?: boolean; 130 | force_upgrade?: boolean; 131 | mess_production_state?: string; 132 | layer_num?: number; 133 | total_layer_num?: number; 134 | s_obj?: Array; 135 | fan_gear?: number; 136 | hms?: Array; 137 | online?: Online; 138 | ams?: AMS; 139 | ipcam?: IPCam; 140 | vt_tray?: VTTray; 141 | lights_report?: Array; 142 | upgrade_state?: UpgradeState; 143 | command?: string; 144 | msg?: number; 145 | sequence_id?: string; 146 | } 147 | -------------------------------------------------------------------------------- /frontend/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { type ClassValue, clsx } from "clsx"; 2 | import { twMerge } from "tailwind-merge"; 3 | 4 | export function getBackendUrl(): string { 5 | let url = import.meta.env.VITE_BACKEND_URL; 6 | 7 | if (url) { 8 | url = "http://" + url; 9 | } else { 10 | url = ""; 11 | } 12 | 13 | return url; 14 | } 15 | 16 | export function cn(...inputs: ClassValue[]) { 17 | return twMerge(clsx(inputs)); 18 | } 19 | 20 | type FlyAndScaleParams = { 21 | y?: number; 22 | x?: number; 23 | start?: number; 24 | duration?: number; 25 | }; 26 | 27 | export function flyAndScale( 28 | node: Element, 29 | params: FlyAndScaleParams = { y: -8, x: 0, start: 0.95, duration: 150 }, 30 | ): TransitionConfig { 31 | const style = getComputedStyle(node); 32 | const transform = style.transform === "none" ? "" : style.transform; 33 | 34 | const scaleConversion = (valueA: number, scaleA: [number, number], scaleB: [number, number]) => { 35 | const [minA, maxA] = scaleA; 36 | const [minB, maxB] = scaleB; 37 | 38 | const percentage = (valueA - minA) / (maxA - minA); 39 | const valueB = percentage * (maxB - minB) + minB; 40 | 41 | return valueB; 42 | }; 43 | 44 | return { 45 | duration: params.duration ?? 200, 46 | delay: 0, 47 | css: (t) => { 48 | const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0]); 49 | const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0]); 50 | const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1]); 51 | 52 | return styleToString({ 53 | transform: `${transform} translate3d(${x}px, ${y}px, 0) scale(${scale})`, 54 | opacity: t, 55 | }); 56 | }, 57 | easing: cubicOut, 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /frontend/main.ts: -------------------------------------------------------------------------------- 1 | import { mount } from "svelte"; 2 | import "./app.css"; 3 | import App from "./App.svelte"; 4 | import { v4 as uuid4 } from "uuid"; 5 | 6 | const app = mount(App, { 7 | target: document.getElementById("app")!, 8 | }); 9 | 10 | if (!window.isSecureContext) { 11 | window.crypto.randomUUID = () => { 12 | return uuid4(); 13 | }; 14 | } 15 | 16 | export default app; 17 | -------------------------------------------------------------------------------- /frontend/typesApi.ts: -------------------------------------------------------------------------------- 1 | export interface PrinterResponse { 2 | name: string; 3 | model: string; 4 | is_online: boolean; 5 | } 6 | -------------------------------------------------------------------------------- /frontend/typesPrinter.ts: -------------------------------------------------------------------------------- 1 | export type CommandType = 2 | | "chamber_light" 3 | | "extruder_temp" 4 | | "bed_temp" 5 | | "print_speed" 6 | | "fan_aux" 7 | | "fan_chamber" 8 | | "fan_part" 9 | | "move_x" 10 | | "move_y" 11 | | "move_z" 12 | | "move_e" 13 | | "move_home" 14 | | "stop_print" 15 | | "pause_print" 16 | | "resume_print" 17 | | "load_filament" 18 | | "unload_filament" 19 | | "force_refresh" 20 | | "calibrate" 21 | | "upload_file"; 22 | 23 | export abstract class PrinterCommand { 24 | constructor(readonly type: CommandType) {} 25 | } 26 | 27 | export class ChamberLight extends PrinterCommand { 28 | constructor(readonly enable: boolean) { 29 | super("chamber_light"); 30 | } 31 | } 32 | 33 | abstract class Temperature extends PrinterCommand { 34 | constructor( 35 | type: CommandType, 36 | readonly temperature: number, 37 | ) { 38 | super(type); 39 | } 40 | } 41 | 42 | export class ExtruderTemp extends Temperature { 43 | constructor(temperature: number) { 44 | super("extruder_temp", temperature); 45 | } 46 | } 47 | 48 | export class BedTemp extends Temperature { 49 | constructor(temperature: number) { 50 | super("bed_temp", temperature); 51 | } 52 | } 53 | 54 | export class PrintSpeed extends PrinterCommand { 55 | constructor(readonly speed: 1 | 2 | 3 | 4) { 56 | super("print_speed"); 57 | } 58 | } 59 | 60 | abstract class FanSpeed extends PrinterCommand { 61 | constructor( 62 | type: CommandType, 63 | readonly speed: number, 64 | ) { 65 | super(type); 66 | } 67 | } 68 | 69 | export class AuxFanSpeed extends FanSpeed { 70 | constructor(speed: number) { 71 | super("fan_aux", speed); 72 | } 73 | } 74 | 75 | export class ChamberFanSpeed extends FanSpeed { 76 | constructor(speed: number) { 77 | super("fan_chamber", speed); 78 | } 79 | } 80 | 81 | export class PartFanSpeed extends FanSpeed { 82 | constructor(speed: number) { 83 | super("fan_part", speed); 84 | } 85 | } 86 | 87 | abstract class Move extends PrinterCommand { 88 | constructor( 89 | type: CommandType, 90 | readonly distance: number, 91 | ) { 92 | super(type); 93 | } 94 | } 95 | 96 | export class MoveX extends Move { 97 | constructor(distance: number) { 98 | super("move_x", distance); 99 | } 100 | } 101 | 102 | export class MoveY extends Move { 103 | constructor(distance: number) { 104 | super("move_y", distance); 105 | } 106 | } 107 | 108 | export class MoveZ extends Move { 109 | constructor(distance: number) { 110 | super("move_z", distance); 111 | } 112 | } 113 | 114 | export class MoveE extends Move { 115 | constructor(distance: number) { 116 | super("move_e", distance); 117 | } 118 | } 119 | 120 | export class MoveHome extends PrinterCommand { 121 | constructor() { 122 | super("move_home"); 123 | } 124 | } 125 | 126 | export class StopPrint extends PrinterCommand { 127 | constructor() { 128 | super("stop_print"); 129 | } 130 | } 131 | 132 | export class PausePrint extends PrinterCommand { 133 | constructor() { 134 | super("pause_print"); 135 | } 136 | } 137 | 138 | export class ResumePrint extends PrinterCommand { 139 | constructor() { 140 | super("resume_print"); 141 | } 142 | } 143 | 144 | export class FilamentLoad extends PrinterCommand { 145 | constructor() { 146 | super("load_filament"); 147 | } 148 | } 149 | 150 | export class FilamentUnload extends PrinterCommand { 151 | constructor() { 152 | super("unload_filament"); 153 | } 154 | } 155 | 156 | export class ForceRefresh extends PrinterCommand { 157 | constructor() { 158 | super("force_refresh"); 159 | } 160 | } 161 | 162 | export class Calibration extends PrinterCommand { 163 | constructor( 164 | readonly bed_levelling: boolean, 165 | readonly motor_noise_cancellation: boolean, 166 | readonly vibration_compensation: boolean, 167 | ) { 168 | super("calibrate"); 169 | } 170 | } 171 | 172 | export class PrintFile extends PrinterCommand { 173 | constructor( 174 | readonly file: string, 175 | readonly file_name: string, 176 | ) { 177 | super("upload_file"); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /frontend/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | BambUI for Lan Mode 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bambui", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "preview": "vite preview", 10 | "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json", 11 | "format": "npx prettier . --write" 12 | }, 13 | "devDependencies": { 14 | "@sveltejs/vite-plugin-svelte": "^5.0.3", 15 | "@tsconfig/svelte": "^5.0.4", 16 | "autoprefixer": "^10.4.20", 17 | "bits-ui": "^1.0.0-next.74", 18 | "clsx": "^2.1.1", 19 | "mode-watcher": "^0.5.0", 20 | "prettier": "^3.4.2", 21 | "prettier-plugin-svelte": "^3.3.2", 22 | "prettier-plugin-tailwindcss": "^0.6.5", 23 | "svelte": "^5.15.0", 24 | "svelte-check": "^4.1.1", 25 | "svelte-sonner": "^0.3.28", 26 | "tailwind-merge": "^2.6.0", 27 | "tailwind-variants": "^0.3.0", 28 | "tailwindcss": "^3.4.9", 29 | "tailwindcss-animate": "^1.0.7", 30 | "tailwindcss-bg-patterns": "^0.3.0", 31 | "typescript": "~5.6.2", 32 | "vite": "^6.0.5" 33 | }, 34 | "dependencies": { 35 | "@dvcol/svelte-simple-router": "^1.9.0", 36 | "lucide-svelte": "^0.469.0", 37 | "uuid": "^11.0.3" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /poetry.toml: -------------------------------------------------------------------------------- 1 | [virtualenvs] 2 | in-project = true -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "bambui" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["fidoriel <49869342+fidoriel@users.noreply.github.com>"] 6 | license = "AGPL" 7 | readme = "README.md" 8 | packages = [ 9 | { include = "backend" }, 10 | ] 11 | 12 | [tool.poetry.dependencies] 13 | python = "^3.12" 14 | bambu-connect = "^0.3.1" 15 | python-dotenv = "^1.0.1" 16 | fastapi = "^0.115.6" 17 | uvicorn = { version = "^0.34.0", extras = ["standard"] } 18 | bambulabs-api = "^2.5.2" 19 | aiomqtt = "^2.3.0" 20 | aioftp = "^0.24.1" 21 | ping3 = "^4.0.8" 22 | 23 | [tool.poetry.group.dev.dependencies] 24 | ruff = "^0.8.4" 25 | mypy = "^1.14.0" 26 | 27 | [build-system] 28 | requires = ["poetry-core"] 29 | build-backend = "poetry.core.masonry.api" 30 | 31 | [[tool.mypy.overrides]] 32 | module = ["bambu_connect.*", "aioftp.*", "ping3"] 33 | ignore_missing_imports = true 34 | -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; 2 | 3 | export default { 4 | // Consult https://svelte.dev/docs#compile-time-svelte-preprocess 5 | // for more information about preprocessors 6 | preprocess: vitePreprocess(), 7 | }; 8 | -------------------------------------------------------------------------------- /tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import { fontFamily } from "tailwindcss/defaultTheme"; 2 | import type { Config } from "tailwindcss"; 3 | import tailwindcssAnimate from "tailwindcss-animate"; 4 | import tailwindBgPatterns from "tailwindcss-bg-patterns"; 5 | 6 | const config: Config = { 7 | darkMode: ["class"], 8 | content: ["./frontend/**/*.{html,js,svelte,ts}"], 9 | safelist: ["dark"], 10 | theme: { 11 | container: { 12 | center: true, 13 | padding: "2rem", 14 | screens: { 15 | "2xl": "1400px", 16 | }, 17 | }, 18 | extend: { 19 | colors: { 20 | border: "hsl(var(--border) / )", 21 | input: "hsl(var(--input) / )", 22 | ring: "hsl(var(--ring) / )", 23 | background: "hsl(var(--background) / )", 24 | foreground: "hsl(var(--foreground) / )", 25 | primary: { 26 | DEFAULT: "hsl(var(--primary) / )", 27 | foreground: "hsl(var(--primary-foreground) / )", 28 | }, 29 | secondary: { 30 | DEFAULT: "hsl(var(--secondary) / )", 31 | foreground: "hsl(var(--secondary-foreground) / )", 32 | }, 33 | destructive: { 34 | DEFAULT: "hsl(var(--destructive) / )", 35 | foreground: "hsl(var(--destructive-foreground) / )", 36 | }, 37 | muted: { 38 | DEFAULT: "hsl(var(--muted) / )", 39 | foreground: "hsl(var(--muted-foreground) / )", 40 | }, 41 | accent: { 42 | DEFAULT: "hsl(var(--accent) / )", 43 | foreground: "hsl(var(--accent-foreground) / )", 44 | }, 45 | popover: { 46 | DEFAULT: "hsl(var(--popover) / )", 47 | foreground: "hsl(var(--popover-foreground) / )", 48 | }, 49 | card: { 50 | DEFAULT: "hsl(var(--card) / )", 51 | foreground: "hsl(var(--card-foreground) / )", 52 | }, 53 | sidebar: { 54 | DEFAULT: "hsl(var(--sidebar-background))", 55 | foreground: "hsl(var(--sidebar-foreground))", 56 | primary: "hsl(var(--sidebar-primary))", 57 | "primary-foreground": "hsl(var(--sidebar-primary-foreground))", 58 | accent: "hsl(var(--sidebar-accent))", 59 | "accent-foreground": "hsl(var(--sidebar-accent-foreground))", 60 | border: "hsl(var(--sidebar-border))", 61 | ring: "hsl(var(--sidebar-ring))", 62 | }, 63 | }, 64 | borderRadius: { 65 | xl: "calc(var(--radius) + 4px)", 66 | lg: "var(--radius)", 67 | md: "calc(var(--radius) - 2px)", 68 | sm: "calc(var(--radius) - 4px)", 69 | }, 70 | fontFamily: { 71 | sans: [...fontFamily.sans], 72 | }, 73 | keyframes: { 74 | "accordion-down": { 75 | from: { height: "0" }, 76 | to: { height: "var(--bits-accordion-content-height)" }, 77 | }, 78 | "accordion-up": { 79 | from: { height: "var(--bits-accordion-content-height)" }, 80 | to: { height: "0" }, 81 | }, 82 | "caret-blink": { 83 | "0%,70%,100%": { opacity: "1" }, 84 | "20%,50%": { opacity: "0" }, 85 | }, 86 | }, 87 | animation: { 88 | "accordion-down": "accordion-down 0.2s ease-out", 89 | "accordion-up": "accordion-up 0.2s ease-out", 90 | "caret-blink": "caret-blink 1.25s ease-out infinite", 91 | }, 92 | }, 93 | }, 94 | plugins: [tailwindcssAnimate, tailwindBgPatterns], 95 | }; 96 | 97 | export default config; 98 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/svelte/tsconfig.json", 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "useDefineForClassFields": true, 6 | "module": "ESNext", 7 | "resolveJsonModule": true, 8 | /** 9 | * Typecheck JS in `.svelte` and `.js` files by default. 10 | * Disable checkJs if you'd like to use dynamic types in JS. 11 | * Note that setting allowJs false does not prevent the use 12 | * of JS in `.svelte` files. 13 | */ 14 | "allowJs": true, 15 | "checkJs": true, 16 | "isolatedModules": true, 17 | "moduleDetection": "force" 18 | }, 19 | "include": ["frontend/**/*.ts", "frontend/**/*.js", "frontend/**/*.svelte"] 20 | } 21 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }], 4 | "compilerOptions": { 5 | "paths": { 6 | "$lib": ["./frontend/lib"], 7 | "$lib/*": ["./frontend/lib/*"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 4 | "target": "ES2022", 5 | "lib": ["ES2023"], 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | 9 | /* Bundler mode */ 10 | "moduleResolution": "bundler", 11 | "allowImportingTsExtensions": true, 12 | "isolatedModules": true, 13 | "moduleDetection": "force", 14 | "noEmit": true, 15 | 16 | /* Linting */ 17 | "strict": true, 18 | "noUnusedLocals": true, 19 | "noUnusedParameters": true, 20 | "noFallthroughCasesInSwitch": true, 21 | "noUncheckedSideEffectImports": true 22 | }, 23 | "include": ["vite.config.ts"] 24 | } 25 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import { svelte } from "@sveltejs/vite-plugin-svelte"; 3 | import path from "path"; 4 | 5 | // https://vite.dev/config/ 6 | export default defineConfig({ 7 | plugins: [svelte()], 8 | resolve: { 9 | alias: { 10 | $lib: path.resolve("./frontend/lib"), 11 | }, 12 | }, 13 | }); 14 | --------------------------------------------------------------------------------