Compare commits

..

No commits in common. "477e76d14c87abb25a16821eb0b2be1cdd6d66ff" and "634d1c17e4666934e57e6882af7f16518276c55f" have entirely different histories.

20 changed files with 102 additions and 1084 deletions

View File

@ -1,91 +0,0 @@
name: 'publish'
on: push
jobs:
create-release:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create-release.outputs.result }}
steps:
- uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 16
- name: get version
run: echo "PACKAGE_VERSION=$(node -p "require('./toos-dashboard/package.json').version")" >> $GITHUB_ENV
- name: create release
id: create-release
uses: actions/github-script@v6
with:
script: |
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `app-v${process.env.PACKAGE_VERSION}`,
name: `Desktop App v${process.env.PACKAGE_VERSION}`,
body: 'Take a look at the assets to download and install this app.',
draft: true,
prerelease: false
})
return data.id
build-tauri:
needs: create-release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v3
with:
node-version: 16
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
run: yarn install # change this to npm or pnpm depending on which one you use
workdir: toos-dashboard/
- uses: tauri-apps/tauri-action@v0
workdir: toos-dashboard/
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ needs.create-release.outputs.release_id }}
publish-release:
permissions:
contents: write
runs-on: ubuntu-latest
needs: [create-release, build-tauri]
steps:
- name: publish release
id: publish-release
uses: actions/github-script@v6
workdir: toos-dashboard/
env:
release_id: ${{ needs.create-release.outputs.release_id }}
with:
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
draft: false,
prerelease: false
})

View File

@ -1,135 +1,6 @@
#include <Adafruit_NeoPixel.h>
const int redPin = 4;
const int greenPin = 5;
const int bluePin = 13;
const int whitePin = 14;
#define PIN_WS2812B 27
#define NUM_PIXELS 68
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
String inputCommand = "";
String inputColor = "";
void setup() { void setup() {
ws2812b.begin();
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(whitePin, OUTPUT);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
analogWrite(whitePin, 0);
} }
void loop() { void loop() {
// Check if there is serial data available
if (Serial.available() > 0) {
char receivedChar = Serial.read();
// Check if the received character is not a newline character
if (receivedChar != ';') {
inputCommand += receivedChar;
} else {
// A newline character indicates the end of the command
if (inputCommand.startsWith("SET_STRIP_COLOR:")) {
inputColor = inputCommand.substring(16); // Extract the color value after ":"
setStripColor(inputColor);
} else if (inputCommand.startsWith("SET_LIGHT:")) {
int brightnessValue = inputCommand.substring(10).toInt();
setLight(brightnessValue);
} else if (inputCommand.startsWith("SET_LED:")) {
// Command format: SET_LED:index,R,G,B (e.g., SET_LED:5,255,0,0 for setting LED #5 to red)
setIndividualLED(inputCommand);
} else if (inputCommand.startsWith("SET_LED_COLOR:")) {
// Command format: SET_LED:index,R,G,B (e.g., SET_LED:5,255,0,0 for setting LED #5 to red)
setLedColor(inputCommand);
} else if (inputCommand.startsWith("SET_LED_OFF")) {
// Command format: SET_LED:index,R,G,B (e.g., SET_LED:5,255,0,0 for setting LED #5 to red)
ws2812b.clear();
ws2812b.show();
}
inputCommand = ""; // Clear the inputCommand string
inputColor = ""; // Clear the inputColor string
}
}
}
void setLight(int brightnessValue) {
// Set the separate light brightness between 0 and 255
analogWrite(whitePin, constrain(brightnessValue, 0, 255));
}
void setStripColor(String colorString) {
// Parse the colorString in the format "R,G,B" where R, G, and B are integer
int commaIndex = colorString.indexOf(',');
if (commaIndex >= 0) {
String redStr = colorString.substring(0, commaIndex);
colorString = colorString.substring(commaIndex + 1);
commaIndex = colorString.indexOf(',');
if (commaIndex >= 0) {
String greenStr = colorString.substring(0, commaIndex);
String blueStr = colorString.substring(commaIndex + 1);
// Convert the string values to integers
int redValue = redStr.toInt();
int greenValue = greenStr.toInt();
int blueValue = blueStr.toInt();
// Set the RGB LED color based on the parsed values
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
}
}
void setIndividualLED(String command) {
// Command format: SET_LED:index,R,G,B
int firstComma = command.indexOf(',');
int secondComma = command.indexOf(',', firstComma + 1);
int thirdComma = command.indexOf(',', secondComma + 1);
if (firstComma != -1 && secondComma != -1 && thirdComma != -1) {
int index = command.substring(8, firstComma).toInt(); // Extract the LED index
int red = command.substring(firstComma + 1, secondComma).toInt(); // Extract the red value
int green = command.substring(secondComma + 1, thirdComma).toInt(); // Extract the green value
int blue = command.substring(thirdComma + 1).toInt(); // Extract the blue value
// Check if the index is within bounds
if (index >= 0 && index < NUM_PIXELS) {
ws2812b.setPixelColor(index, ws2812b.Color(red, green, blue));
ws2812b.show();
}
}
}
void setLedColor(String colorString) {
// Parse the colorString in the format "R,G,B" where R, G, and B are integer
int commaIndex = colorString.indexOf(',');
if (commaIndex >= 0) {
String redStr = colorString.substring(0, commaIndex);
colorString = colorString.substring(commaIndex + 1);
commaIndex = colorString.indexOf(',');
if (commaIndex >= 0) {
String greenStr = colorString.substring(0, commaIndex);
String blueStr = colorString.substring(commaIndex + 1);
// Convert the string values to integers
int redValue = redStr.toInt();
int greenValue = greenStr.toInt();
int blueValue = blueStr.toInt();
// Set the RGB LED color based on the parsed values
ws2812b.fill(ws2812b.Color(redValue, greenValue, blueValue));
ws2812b.show();
}
}
} }

Binary file not shown.

Binary file not shown.

View File

@ -62,28 +62,6 @@ dependencies = [
"alloc-no-stdlib", "alloc-no-stdlib",
] ]
[[package]]
name = "alsa"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2562ad8dcf0f789f65c6fdaad8a8a9708ed6b488e649da28c01656ad66b8b47"
dependencies = [
"alsa-sys",
"bitflags 1.3.2",
"libc",
"nix 0.24.3",
]
[[package]]
name = "alsa-sys"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8fee663d06c4e303404ef5f40488a53e062f89ba8bfed81f42325aafad1527"
dependencies = [
"libc",
"pkg-config",
]
[[package]] [[package]]
name = "android-tzdata" name = "android-tzdata"
version = "0.1.1" version = "0.1.1"
@ -105,12 +83,6 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]] [[package]]
name = "atk" name = "atk"
version = "0.15.1" version = "0.15.1"
@ -168,26 +140,6 @@ version = "0.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2"
[[package]]
name = "bindgen"
version = "0.68.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
dependencies = [
"bitflags 2.4.0",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 2.0.37",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -310,7 +262,6 @@ version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [ dependencies = [
"jobserver",
"libc", "libc",
] ]
@ -320,15 +271,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]] [[package]]
name = "cfb" name = "cfb"
version = "0.7.3" version = "0.7.3"
@ -375,26 +317,9 @@ dependencies = [
"iana-time-zone", "iana-time-zone",
"num-traits", "num-traits",
"serde", "serde",
"windows-targets 0.48.5", "windows-targets",
] ]
[[package]]
name = "clang-sys"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "claxon"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688"
[[package]] [[package]]
name = "cocoa" name = "cocoa"
version = "0.24.1" version = "0.24.1"
@ -487,51 +412,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "coreaudio-rs"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "321077172d79c662f64f5071a03120748d5bb652f5231570141be24cfcd2bace"
dependencies = [
"bitflags 1.3.2",
"core-foundation-sys",
"coreaudio-sys",
]
[[package]]
name = "coreaudio-sys"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8478e5bdad14dce236b9898ea002eabfa87cbe14f0aa538dbe3b6a4bec4332d"
dependencies = [
"bindgen",
]
[[package]]
name = "cpal"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d959d90e938c5493000514b446987c07aed46c668faaa7d34d6c7a67b1a578c"
dependencies = [
"alsa",
"core-foundation-sys",
"coreaudio-rs",
"dasp_sample",
"jni 0.19.0",
"js-sys",
"libc",
"mach2",
"ndk 0.7.0",
"ndk-context",
"oboe",
"once_cell",
"parking_lot",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows 0.46.0",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.9" version = "0.2.9"
@ -651,12 +531,6 @@ dependencies = [
"syn 2.0.37", "syn 2.0.37",
] ]
[[package]]
name = "dasp_sample"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.8" version = "0.3.8"
@ -1287,12 +1161,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hound"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
[[package]] [[package]]
name = "html5ever" name = "html5ever"
version = "0.25.2" version = "0.25.2"
@ -1492,20 +1360,6 @@ dependencies = [
"system-deps 5.0.0", "system-deps 5.0.0",
] ]
[[package]]
name = "jni"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec"
dependencies = [
"cesu8",
"combine",
"jni-sys",
"log",
"thiserror",
"walkdir",
]
[[package]] [[package]]
name = "jni" name = "jni"
version = "0.20.0" version = "0.20.0"
@ -1526,15 +1380,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.64" version = "0.3.64"
@ -1587,39 +1432,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lewton"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030"
dependencies = [
"byteorder",
"ogg",
"tinyvec",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.148" version = "0.2.148"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]] [[package]]
name = "libudev" name = "libudev"
version = "0.3.0" version = "0.3.0"
@ -1777,12 +1595,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.1" version = "0.7.1"
@ -1801,25 +1613,11 @@ checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"jni-sys", "jni-sys",
"ndk-sys 0.3.0", "ndk-sys",
"num_enum", "num_enum",
"thiserror", "thiserror",
] ]
[[package]]
name = "ndk"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0"
dependencies = [
"bitflags 1.3.2",
"jni-sys",
"ndk-sys 0.4.1+23.1.7779620",
"num_enum",
"raw-window-handle",
"thiserror",
]
[[package]] [[package]]
name = "ndk-context" name = "ndk-context"
version = "0.1.1" version = "0.1.1"
@ -1835,32 +1633,12 @@ dependencies = [
"jni-sys", "jni-sys",
] ]
[[package]]
name = "ndk-sys"
version = "0.4.1+23.1.7779620"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cf2aae958bd232cac5069850591667ad422d263686d75b52a065f9badeee5a3"
dependencies = [
"jni-sys",
]
[[package]] [[package]]
name = "new_debug_unreachable" name = "new_debug_unreachable"
version = "1.0.4" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "nix"
version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
]
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.26.4" version = "0.26.4"
@ -1878,16 +1656,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.46.0"
@ -1898,17 +1666,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num-derive"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.45" version = "0.1.45"
@ -1980,17 +1737,6 @@ dependencies = [
"objc_exception", "objc_exception",
] ]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]] [[package]]
name = "objc_exception" name = "objc_exception"
version = "0.1.2" version = "0.1.2"
@ -2018,38 +1764,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "oboe"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8868cc237ee02e2d9618539a23a8d228b9bb3fc2e7a5b11eed3831de77c395d0"
dependencies = [
"jni 0.20.0",
"ndk 0.7.0",
"ndk-context",
"num-derive",
"num-traits",
"oboe-sys",
]
[[package]]
name = "oboe-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f44155e7fb718d3cfddcf70690b2b51ac4412f347cd9e4fbe511abe9cd7b5f2"
dependencies = [
"cc",
]
[[package]]
name = "ogg"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e"
dependencies = [
"byteorder",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.18.0" version = "1.18.0"
@ -2117,7 +1831,7 @@ dependencies = [
"libc", "libc",
"redox_syscall 0.3.5", "redox_syscall 0.3.5",
"smallvec", "smallvec",
"windows-targets 0.48.5", "windows-targets",
] ]
[[package]] [[package]]
@ -2126,12 +1840,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.0" version = "2.3.0"
@ -2530,89 +2238,12 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "rfd"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea"
dependencies = [
"block",
"dispatch",
"glib-sys",
"gobject-sys",
"gtk-sys",
"js-sys",
"lazy_static",
"log",
"objc",
"objc-foundation",
"objc_id",
"raw-window-handle",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows 0.37.0",
]
[[package]]
name = "rodio"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdf1d4dea18dff2e9eb6dca123724f8b60ef44ad74a9ad283cdfe025df7e73fa"
dependencies = [
"claxon",
"cpal",
"hound",
"lewton",
"symphonia",
]
[[package]]
name = "rust-embed"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1e7d90385b59f0a6bf3d3b757f3ca4ece2048265d70db20a2016043d4509a40"
dependencies = [
"rust-embed-impl",
"rust-embed-utils",
"walkdir",
]
[[package]]
name = "rust-embed-impl"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3d8c6fd84090ae348e63a84336b112b5c3918b3bf0493a581f7bd8ee623c29"
dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn 2.0.37",
"walkdir",
]
[[package]]
name = "rust-embed-utils"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "873feff8cb7bf86fdf0a71bb21c95159f4e4a37dd7a4bd1855a940909b583ada"
dependencies = [
"sha2",
"walkdir",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.4.0" version = "0.4.0"
@ -2817,7 +2448,7 @@ dependencies = [
"cfg-if", "cfg-if",
"libudev", "libudev",
"mach2", "mach2",
"nix 0.26.4", "nix",
"regex", "regex",
"scopeguard", "scopeguard",
"winapi", "winapi",
@ -2853,12 +2484,6 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "shlex"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
[[package]] [[package]]
name = "simd-adler32" name = "simd-adler32"
version = "0.3.7" version = "0.3.7"
@ -2961,56 +2586,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "symphonia"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62e48dba70095f265fdb269b99619b95d04c89e619538138383e63310b14d941"
dependencies = [
"lazy_static",
"symphonia-bundle-mp3",
"symphonia-core",
"symphonia-metadata",
]
[[package]]
name = "symphonia-bundle-mp3"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f31d7fece546f1e6973011a9eceae948133bbd18fd3d52f6073b1e38ae6368a"
dependencies = [
"bitflags 1.3.2",
"lazy_static",
"log",
"symphonia-core",
"symphonia-metadata",
]
[[package]]
name = "symphonia-core"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c73eb88fee79705268cc7b742c7bc93a7b76e092ab751d0833866970754142"
dependencies = [
"arrayvec",
"bitflags 1.3.2",
"bytemuck",
"lazy_static",
"log",
]
[[package]]
name = "symphonia-metadata"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89c3e1937e31d0e068bbe829f66b2f2bfaa28d056365279e0ef897172c3320c0"
dependencies = [
"encoding_rs",
"lazy_static",
"log",
"symphonia-core",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@ -3084,13 +2659,13 @@ dependencies = [
"gtk", "gtk",
"image", "image",
"instant", "instant",
"jni 0.20.0", "jni",
"lazy_static", "lazy_static",
"libc", "libc",
"log", "log",
"ndk 0.6.0", "ndk",
"ndk-context", "ndk-context",
"ndk-sys 0.3.0", "ndk-sys",
"objc", "objc",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
@ -3160,7 +2735,6 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"raw-window-handle", "raw-window-handle",
"regex", "regex",
"rfd",
"semver", "semver",
"serde", "serde",
"serde_json", "serde_json",
@ -3509,9 +3083,6 @@ dependencies = [
name = "toos-dashboard" name = "toos-dashboard"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"once_cell",
"rodio",
"rust-embed",
"serde", "serde",
"serde_json", "serde_json",
"serialport", "serialport",
@ -3741,18 +3312,6 @@ dependencies = [
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.87" version = "0.2.87"
@ -3782,16 +3341,6 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "web-sys"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]] [[package]]
name = "webkit2gtk" name = "webkit2gtk"
version = "0.18.2" version = "0.18.2"
@ -3908,19 +3457,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647"
dependencies = [
"windows_aarch64_msvc 0.37.0",
"windows_i686_gnu 0.37.0",
"windows_i686_msvc 0.37.0",
"windows_x86_64_gnu 0.37.0",
"windows_x86_64_msvc 0.37.0",
]
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.39.0" version = "0.39.0"
@ -3935,22 +3471,13 @@ dependencies = [
"windows_x86_64_msvc 0.39.0", "windows_x86_64_msvc 0.39.0",
] ]
[[package]]
name = "windows"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
dependencies = [
"windows-targets 0.42.2",
]
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.48.0" version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [ dependencies = [
"windows-targets 0.48.5", "windows-targets",
] ]
[[package]] [[package]]
@ -4000,22 +3527,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [ dependencies = [
"windows-targets 0.48.5", "windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
] ]
[[package]] [[package]]
@ -4051,12 +3563,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.39.0" version = "0.39.0"
@ -4075,12 +3581,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.39.0" version = "0.39.0"
@ -4099,12 +3599,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.39.0" version = "0.39.0"
@ -4123,12 +3617,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.39.0" version = "0.39.0"
@ -4159,12 +3647,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.39.0" version = "0.39.0"

View File

@ -13,13 +13,10 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] } tauri-build = { version = "1.5", features = [] }
[dependencies] [dependencies]
tauri = { version = "1.5", features = [ "dialog-all", "shell-open"] } tauri = { version = "1.5", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
serialport = "4.2.2" serialport = "4.2.2"
rodio = "0.17.1"
rust-embed="8.0.0"
once_cell = "1.18.0"
[features] [features]
# this feature is used for production builds or when `devPath` points to the filesystem # this feature is used for production builds or when `devPath` points to the filesystem

View File

@ -1,110 +0,0 @@
use std::time::Duration;
use std::thread;
use std::fs::File;
use std::io::BufReader;
use rodio::{Decoder, OutputStream, Sink};
use std::sync::Mutex;
use once_cell::sync::Lazy;
use crate::serial;
struct Timings {
charging_start_delay: u64,
charging_delay: u64,
charging_end_delay: u64,
}
static TIMINGS: Mutex<Lazy<Timings>> = Mutex::new(Lazy::new(|| Timings { charging_start_delay: 1600, charging_delay: 450, charging_end_delay: 400 } ));
#[tauri::command]
pub fn start() {
thread::spawn(move || {
println!("Starting animation...");
play_sound();
thread::sleep(Duration::from_millis(500));
let _ = serial::write_serial(format!("SET_LIGHT:0;").as_str());
stage_one();
stage_two();
});
}
fn play_sound() {
thread::spawn(|| {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let file = BufReader::new(File::open("assets/audio.mp3").unwrap());
let source = Decoder::new(file).unwrap();
sink.append(source);
sink.sleep_until_end();
});
}
fn stage_one() {
let timings = TIMINGS.lock().unwrap();
thread::sleep(Duration::from_millis(timings.charging_start_delay));
for i in 0..17 {
let _ = serial::write_serial(format!("SET_LED:{},0,128,255;", i).as_str());
let _ = serial::write_serial(format!("SET_LED:{},0,128,255;", 33 - i).as_str());
let _ = serial::write_serial(format!("SET_LED:{},0,128,255;", i + 34).as_str());
let _ = serial::write_serial(format!("SET_LED:{},0,128,255;", 67 - i).as_str());
thread::sleep(Duration::from_millis(timings.charging_delay));
}
}
fn stage_two() {
let timings = TIMINGS.lock().unwrap();
thread::sleep(Duration::from_millis(timings.charging_end_delay));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
thread::sleep(Duration::from_millis(200));
let _ = serial::write_serial(format!("SET_LED_COLOR:0,128,255;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,128,255;").as_str());
thread::sleep(Duration::from_millis(100));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
thread::sleep(Duration::from_millis(200));
let _ = serial::write_serial(format!("SET_LED_COLOR:0,128,255;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,128,255;").as_str());
thread::sleep(Duration::from_millis(200));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
thread::sleep(Duration::from_millis(100));
let _ = serial::write_serial(format!("SET_LED_COLOR:0,128,255;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,128,255;").as_str());
thread::sleep(Duration::from_millis(100));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
thread::sleep(Duration::from_millis(300));
let _ = serial::write_serial(format!("SET_LED_COLOR:0,128,255;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,128,255;").as_str());
thread::sleep(Duration::from_millis(100));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
thread::sleep(Duration::from_millis(100));
let _ = serial::write_serial(format!("SET_LED_COLOR:0,128,255;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,128,255;").as_str());
thread::sleep(Duration::from_millis(200));
let _ = serial::write_serial(format!("SET_LED_OFF;").as_str());
let _ = serial::write_serial(format!("SET_STRIP_COLOR:0,0,0;").as_str());
}

View File

@ -1,12 +1,83 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod serial; use std::sync:: Mutex;
mod animation; use std::io::ErrorKind;
use std::time::Duration;
use std::collections::HashMap;
use tauri::State;
#[derive(Default)]
struct PortMap(Mutex<HashMap<String, Box<dyn serialport::SerialPort>>>);
#[tauri::command]
async fn write_serial(input: &str, port_name: &str, port_map: State<'_, PortMap>) -> Result<(), String> {
match port_map.0.lock().unwrap().get(port_name) {
Some(port) => {
let mut clone = port.try_clone().expect("Failed to clone");
println!("Writing to serial");
match clone.write(input.as_bytes()) {
Ok(_) => {
Ok(())
},
Err(err) => Err(err.to_string()),
}
}
None => {
Ok(())
}
}
}
#[tauri::command]
fn get_serial_ports() -> Vec<String> {
let ports = serialport::available_ports().expect("No ports found");
let mut vec: Vec<String> = Vec::new();
for p in ports {
vec.push(p.port_name);
}
vec
}
#[tauri::command]
async fn open_port(_app_handle: tauri::AppHandle, port_map: State<'_, PortMap>) -> Result<(), String> {
match serialport::new("/dev/ttyUSB0", 9600).timeout(Duration::from_millis(10)).open() {
Ok(port) => {
port_map.0.lock().unwrap().insert("/dev/ttyUSB0".to_string(), port.try_clone().expect("Error cloning"));
println!("Port is open");
let mut clone = port.try_clone().expect("Failed to clone");
let mut buffer: Vec<u8> = vec![0; 1024];
loop {
match clone.read(buffer.as_mut_slice()) {
Ok(bytes_read) => {
if bytes_read > 0 {
let data = &buffer[..bytes_read];
let data = String::from_utf8_lossy(data).to_string();
if !data.trim().is_empty() {
println!("{}", data.trim());
}
}
},
Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
Err(e) => return Err(e.to_string()),
};
}
},
Err(err) => return Err(err.to_string()),
};
}
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
.invoke_handler(tauri::generate_handler![serial::get_serial_ports, serial::write_serial, serial::open_port, serial::close_port, animation::start]) .manage(PortMap::default())
.invoke_handler(tauri::generate_handler![get_serial_ports, write_serial, open_port])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

@ -1,103 +0,0 @@
use std::io::ErrorKind;
use std::time::Duration;
use std::collections::HashMap;
use std::sync::Mutex;
use tauri::Manager;
use once_cell::sync::Lazy;
use crate::animation;
#[derive(Default)]
pub struct PortMap(Mutex<HashMap<String, Box<dyn serialport::SerialPort>>>);
static PORT_MAP: Mutex<Lazy<HashMap<String, Box<dyn serialport::SerialPort>>>> = Mutex::new(Lazy::new(|| HashMap::new()));
static PORT_NAME: Mutex<Lazy<String>> = Mutex::new(Lazy::new(|| String::from("/dev/ttyUSB0")));
#[derive(Clone, serde::Serialize)]
pub struct PayloadPortState {
open: bool,
}
#[tauri::command]
pub fn write_serial(input: &str) -> Result<(), String> {
let port_name = PORT_NAME.lock().unwrap().to_string();
match PORT_MAP.lock().unwrap().get(&port_name) {
Some(port) => {
let mut clone = port.try_clone().expect("Failed to clone");
match clone.write(input.as_bytes()) {
Ok(_) => {
Ok(())
},
Err(err) => Err(err.to_string()),
}
}
None => {
Err(String::from("Port is closed"))
}
}
}
#[tauri::command]
pub fn get_serial_ports() -> Vec<String> {
let ports = serialport::available_ports().expect("No ports found");
let mut vec: Vec<String> = Vec::new();
for p in ports {
vec.push(p.port_name);
}
vec
}
#[tauri::command]
pub fn close_port(app_handle: tauri::AppHandle) {
let port_name = PORT_NAME.lock().unwrap().to_string();
match PORT_MAP.lock().unwrap().remove(&port_name) {
Some(_) => {
println!("Port {:?} closed", port_name);
app_handle.emit_all("port-state", PayloadPortState { open: false }).unwrap();
},
None => println!("Port {:?} was already closed", port_name),
}
}
#[tauri::command]
pub async fn open_port(app_handle: tauri::AppHandle, baud: u32) -> Result<(), String> {
let port_name = PORT_NAME.lock().unwrap().to_string();
match serialport::new(&port_name, baud).timeout(Duration::from_millis(10)).open() {
Ok(port) => {
// port_map.0.lock().unwrap().insert(port_name.to_string(), port.try_clone().expect("Error cloning"));
PORT_MAP.lock().unwrap().insert(port_name.clone(), port.try_clone().expect("Error cloning port"));
let mut clone = port.try_clone().expect("Failed to clone");
let mut buffer: Vec<u8> = vec![0; 1024];
println!("Port {:?} is open", port_name);
app_handle.emit_all("port-state", PayloadPortState { open: true }).unwrap();
loop {
match clone.read(buffer.as_mut_slice()) {
Ok(bytes_read) => {
if bytes_read > 0 {
let data = &buffer[..bytes_read];
let data = String::from_utf8_lossy(data).to_string();
if !data.trim().is_empty() {
println!("{}", data.trim());
if data.trim() == "1" {
animation::start();
app_handle.emit_all("button-on", PayloadPortState { open: true }).unwrap();
}
}
}
},
Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
Err(e) => return Err(e.to_string()),
};
}
},
Err(err) => return Err(err.to_string()),
}
}

View File

@ -16,9 +16,6 @@
"shell": { "shell": {
"all": false, "all": false,
"open": true "open": true
},
"dialog": {
"all": true
} }
}, },
"bundle": { "bundle": {

View File

@ -2,14 +2,10 @@
<div class="w-full flex h-screen bg-neutral-950"> <div class="w-full flex h-screen bg-neutral-950">
<Sidebar @updateCurrentPage="setCurrentPage" /> <Sidebar @updateCurrentPage="setCurrentPage" />
<div class="w-full"> <div class="w-full">
<Status />
<Main v-if="currentPage === 0" /> <Main v-if="currentPage === 0" />
<Conf v-if="currentPage === 1" /> <Conf v-if="currentPage === 1" />
<Test v-if="currentPage === 2" /> <Test v-if="currentPage === 2" />
</div> </div>
<audio id="audioContainer">
<source src="./assets/audio.mp3" type="audio/mp3">
</audio>
</div> </div>
</template> </template>
@ -18,27 +14,12 @@ import Sidebar from "./components/Sidebar.vue";
import Test from "./components/Test.vue"; import Test from "./components/Test.vue";
import Main from "./components/Main.vue"; import Main from "./components/Main.vue";
import Conf from "./components/Conf.vue"; import Conf from "./components/Conf.vue";
import Status from "./components/Status.vue";
import { ref, onMounted } from "vue"; import { ref } from "vue";
import { listen } from '@tauri-apps/api/event';
import { invoke } from "@tauri-apps/api/tauri"
import { useLocalStorage } from '@vueuse/core'
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600, open: false })
const currentPage = ref(2); const currentPage = ref(2);
const setCurrentPage = (x) => { const setCurrentPage = (x) => {
currentPage.value = x; currentPage.value = x;
} }
onMounted(async () => {
await invoke('close_port', { portName: serialConfig.value.port, baud: serialConfig.value.baud });
serialConfig.value.open = false;
await listen('port-state', (event) => {
serialConfig.value.open = event.payload.open
});
})
</script> </script>

Binary file not shown.

View File

@ -1,23 +1,3 @@
<template> <template>
<h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Dashboard</h1> <h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Dashboard</h1>
<div class="flex w-full justify-center gap-10">
<div class="bg-neutral-800 rounded-2xl p-5 h-min">
<h2 class="text-white font-bold text-lg text-center mb-5">Animation</h2>
<div class="flex flex-col items-center">
<div class="space-x-3">
<button @click="test" class="px-5 py-2 bg-sky-400 rounded my-5">
Start Animation
</button>
</div>
</div>
</div>
</div>
</template> </template>
<script setup>
import { invoke } from "@tauri-apps/api/tauri"
const test = async () => {
await invoke('start');
}
</script>

View File

@ -1,31 +0,0 @@
<template>
<div class="text-white flex justify-center w-full bg-neutral-800 py-3">
<span class="font-bold">PORT {{serialConfig.port}} is
<span v-if="serialConfig.open" class="text-green-500 hover:cursor-pointer" @click="closePort">OPEN</span>
<span v-else class="text-red-600 hover:cursor-pointer" @click="openPort">CLOSED</span>
</span>
</div>
</template>
<script setup>
import { useLocalStorage } from '@vueuse/core'
import { invoke } from "@tauri-apps/api/tauri"
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600, open: false })
const openPort = () => {
try {
invoke('open_port', { portName: serialConfig.value.port, baud: serialConfig.value.baud });
} catch (err) {
console.error(err);
}
}
const closePort = async () => {
try {
await invoke('close_port', { portName: serialConfig.value.port, baud: serialConfig.value.baud });
} catch (err) {
console.error(err);
}
}
</script>

View File

@ -2,7 +2,7 @@
<h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Test</h1> <h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Test</h1>
<div class="flex w-full justify-center gap-10"> <div class="flex w-full justify-center gap-10">
<div class="bg-neutral-800 rounded-2xl p-5 h-min"> <div class="bg-neutral-800 rounded-2xl p-5 h-min">
<h2 class="text-white font-bold text-lg text-center mb-5">LED Strip Monster</h2> <h2 class="text-white font-bold text-lg text-center my-5">LED Strip Monster</h2>
<div class="flex flex-col items-center"> <div class="flex flex-col items-center">
<color-input disable-alpha v-model="color" /> <color-input disable-alpha v-model="color" />
<div class="space-x-3"> <div class="space-x-3">
@ -15,35 +15,16 @@
</div> </div>
</div> </div>
</div> </div>
<div class="bg-neutral-800 rounded-2xl p-5 h-min"> <div class="bg-neutral-800 rounded-2xl p-5">
<h2 class="text-white font-bold text-lg text-center mb-5">LED Strip Hallway</h2> <h2 class="text-white font-bold text-lg text-center my-5">LED Strip Hallway</h2>
<div class="flex flex-col items-center"> <div class="flex flex-col items-center">
<input v-model="brightness" type="range" min="0" max="100" class="w-40"> <input v-model="brightness" type="range" min="0" max="100" class="w-40">
<label class="text-white mt-2">BRIGHTNESS: {{ brightness }}% </label> <label class="text-white mt-2">BRIGHTNESS: {{ brightness }}% </label>
<button @click="submitBrightness" class="px-5 py-2 bg-sky-400 w-full rounded mt-4"> <button @click="submitBrightness" class="px-5 py-2 bg-sky-400 w-full rounded my-5">
Submit Submit
</button> </button>
</div> </div>
</div> </div>
<div class="bg-neutral-800 rounded-2xl p-5">
<h2 class="text-white font-bold text-lg text-center mb-5">LED Strip Electrons</h2>
<div class="flex flex-col items-center">
<color-input disable-alpha v-model="pixel.color" />
<div class="flex items-center mt-4">
<label class="text-white mr-2">Pixel: </label>
<input v-model="pixel.pixel" type="number" min="0" max="182" class="w-40">
</div>
<button @click="submitPixel" class="px-5 py-2 bg-sky-400 w-full rounded my-5">
Submit Color
</button>
<button class="px-5 py-2 bg-sky-400 w-full rounded mb-5">
Test
</button>
<button @click="resetStrip" class="px-5 py-2 bg-red-700 w-full rounded">
Turn Off
</button>
</div>
</div>
</div> </div>
</template> </template>
@ -53,7 +34,6 @@ import { useSerial } from "../composables/useSerial"
const color = ref({ r: 0, g: 128, b: 255, a: 1}); const color = ref({ r: 0, g: 128, b: 255, a: 1});
const brightness = ref(100); const brightness = ref(100);
const pixel = ref({ color: { r: 64, g: 255, b: 255, a: 1 }, pixel: 0 });
const submitColor = () => { const submitColor = () => {
useSerial("SET_STRIP_COLOR:" + `${color.value.r},${color.value.g},${color.value.b}`); useSerial("SET_STRIP_COLOR:" + `${color.value.r},${color.value.g},${color.value.b}`);
@ -62,14 +42,6 @@ const submitColor = () => {
const submitBrightness = () => { const submitBrightness = () => {
useSerial("SET_LIGHT:" + brightness.value * 2.55); useSerial("SET_LIGHT:" + brightness.value * 2.55);
} }
const submitPixel = () => {
useSerial("SET_LED:" + `${pixel.value.pixel},${pixel.value.color.r},${pixel.value.color.g},${pixel.value.color.b}`);
}
const resetStrip = () => {
useSerial("SET_LED_OFF");
}
</script> </script>
<style> <style>

View File

@ -8,10 +8,11 @@
<label class="text-white mr-2">BAUD</label> <label class="text-white mr-2">BAUD</label>
<input type="number" v-model="serialConfig.baud"> <input type="number" v-model="serialConfig.baud">
</div> </div>
<span class="text-white mt-3 font-bold">Available ports:</span> <span class="text-white mt-3">Available ports</span>
<span v-for="port in ports" class="text-white hover:cursor-pointer bg-neutral-900 rounded w-full px-3 py-1 hover:bg-opacity-50" @click="serialConfig.port = port"> <span v-for="port in ports" class="text-white hover:cursor-pointer" @click="serialConfig.port = port">
{{ port }} {{ port }}
</span> </span>
<button @click="readSerial">READ</button>
</div> </div>
</div> </div>
</template> </template>
@ -23,7 +24,7 @@ import { useLocalStorage } from '@vueuse/core'
const ports = ref([]) const ports = ref([])
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600, open: false }) const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 })
const getSerialPorts = async () => { const getSerialPorts = async () => {
return await invoke('get_serial_ports'); return await invoke('get_serial_ports');
@ -31,5 +32,11 @@ const getSerialPorts = async () => {
onMounted(async () => { onMounted(async () => {
ports.value = await getSerialPorts() ports.value = await getSerialPorts()
invoke('open_port');
}) })
const readSerial = async () => {
return await invoke('read_serial', { portName: "/dev/ttyUSB0" });
}
</script> </script>

View File

@ -1,14 +1,9 @@
import { invoke } from "@tauri-apps/api/tauri" import { invoke } from "@tauri-apps/api/tauri"
import { message } from '@tauri-apps/api/dialog';
import { useLocalStorage } from '@vueuse/core' import { useLocalStorage } from '@vueuse/core'
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 }) const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 })
export async function useSerial(input) { export function useSerial(input) {
try { console.log(serialConfig.value)
await invoke('write_serial', { input: input + ";", portName: serialConfig.value.port, baud: serialConfig.value.baud }); invoke('write_serial', { input: input + ";", portName: serialConfig.value.port, baud: serialConfig.value.baud });
} catch (err) {
console.error(err);
await message(err, { title: 'Error while writing serial', type: 'error' });
}
} }