Compare commits

..

34 Commits

Author SHA1 Message Date
17a3b82d5c Update toos-dashboard/src-tauri/src/animation.rs
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m18s
2023-10-28 08:43:55 +02:00
8c087f452e Update toos-dashboard/src-tauri/src/animation.rs
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m16s
2023-10-27 20:49:37 +02:00
23431457b7 Update toos-dashboard/src-tauri/src/animation.rs
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m16s
2023-10-27 20:39:31 +02:00
3f6ea3a2f1 Changed localhost to 127.0.0.1
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m29s
2023-10-27 15:11:20 +02:00
ef0c80d099 merge
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m21s
2023-10-27 15:03:38 +02:00
6af55a17bf Merge branch 'main' of https://gitea.xeovalyte.dev/xeovalyte/toos-halloween 2023-10-27 15:03:04 +02:00
1a760adcfd Update .gitea/workflows/workflow.yml
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m37s
2023-10-27 14:22:38 +02:00
ff7f0f2e96 Update .gitea/workflows/workflow.yml
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m17s
2023-10-27 14:04:28 +02:00
b13e97ba6a Update .gitea/workflows/workflow.yml
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 3m59s
2023-10-27 13:22:23 +02:00
3c2053dc85 Update .gitea/workflows/workflow.yml
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m6s
2023-10-27 13:16:43 +02:00
13b669ce22 Update .gitea/workflows/workflow.yml
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 4m18s
2023-10-27 13:02:08 +02:00
5ed82d0fca Update .gitea/workflows/workflow.yml
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 3m55s
2023-10-27 12:52:02 +02:00
d713becd68 Update .gitea/workflows/workflow.yml 2023-10-27 12:51:45 +02:00
9670bed8e8 Update .gitea/workflows/workflow.yml
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m3s
2023-10-27 12:45:30 +02:00
ce09220708 Update .gitea/workflows/workflow.yml
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 1m36s
2023-10-27 10:40:29 +02:00
422f4c68c6 feat: Added relative audio path 2023-10-27 10:34:47 +02:00
078683b5b2 feat: Added button
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 4m8s
2023-10-26 15:31:07 +02:00
dc78ea7426 feat: Added button 2023-10-26 15:30:53 +02:00
81edabee6e feat: Renamend secret to custom token
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 3m58s
2023-10-24 23:13:37 +02:00
c8bb08343e feat: Renamed Github to Gitea
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 3m59s
2023-10-24 23:05:37 +02:00
d0d01fafbc feat: More depenencies
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 4m2s
2023-10-24 22:54:32 +02:00
6ca8176993 feat: Added depedencies
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 2m2s
2023-10-24 22:51:30 +02:00
119d287865 feat: Changed working directory
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 1m58s
2023-10-24 22:46:46 +02:00
113834ab26 feat: Removed sudo
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 1m29s
2023-10-24 22:43:11 +02:00
b885ae8acb feat: Changed yarn to npm
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 32s
2023-10-24 22:42:30 +02:00
9f9c4ff508 feat: Changed ci
Some checks failed
publish / publish-tauri (ubuntu-20.04) (push) Failing after 29s
2023-10-24 22:41:14 +02:00
c234a1d1f9 feat:: Added vite
Some checks failed
publish / create-release (push) Successful in 14s
publish / build-tauri (ubuntu-latest) (push) Failing after 1m34s
publish / publish-release (push) Has been skipped
2023-10-24 22:34:25 +02:00
f0558b0ac9 feat: Changed bundle indentifier
Some checks failed
publish / create-release (push) Successful in 13s
publish / build-tauri (ubuntu-latest) (push) Failing after 1m37s
publish / publish-release (push) Has been skipped
publish / build-tauri (windows-latest) (push) Has been cancelled
2023-10-24 22:29:06 +02:00
4792be9ab3 feat: Removed sudo
Some checks failed
publish / create-release (push) Successful in 13s
publish / build-tauri (ubuntu-latest) (push) Failing after 1m28s
publish / publish-release (push) Has been skipped
publish / build-tauri (windows-latest) (push) Has been cancelled
2023-10-24 22:23:01 +02:00
8cb9217548 feat: Removed macos
Some checks failed
publish / create-release (push) Successful in 53s
publish / build-tauri (ubuntu-latest) (push) Failing after 39s
publish / build-tauri (windows-latest) (push) Has been cancelled
publish / publish-release (push) Has been cancelled
2023-10-24 22:20:28 +02:00
477e76d14c feat: Added ci 2023-10-24 22:19:09 +02:00
5256bbdd7b feat: Added Arduino code and audio files 2023-10-24 22:13:37 +02:00
5b6a6413f4 feat: Added sound + Light effect 2023-10-24 22:12:52 +02:00
d2872ef3fd feat: Play sound 2023-10-16 19:01:34 +02:00
20 changed files with 1096 additions and 104 deletions

View File

@@ -0,0 +1,37 @@
name: 'publish'
on: push
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [ubuntu-20.04]
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-20.04'
run: |
apt-get update
apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libasound2-dev libudev-dev
- name: install frontend dependencies
run: npm install # change this to npm or pnpm depending on which one you use
working-directory: ./toos-dashboard
- run: npm run tauri build
working-directory: ./toos-dashboard
- uses: actions/upload-artifact@v3
with:
name: toos-dashboard.AppImage
path: toos-dashboard/src-tauri/target/release/bundle/appimage/*.AppImage

View File

@@ -1,6 +1,167 @@
#include <Adafruit_NeoPixel.h>
const int redPin = 4;
const int greenPin = 5;
const int bluePin = 13;
const int whitePin = 14;
const int btnPin = 18;
#define PIN_WS2812B 27
#define NUM_PIXELS 68
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
String inputCommand = "";
String inputColor = "";
int buttonState = 0;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50;
void setup() {
ws2812b.begin();
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(btnPin, INPUT);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
analogWrite(whitePin, 0);
}
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
}
}
int reading = digitalRead(btnPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
Serial.write("1");
}
}
}
lastButtonState = reading;
}
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.

Binary file not shown.

View File

@@ -62,6 +62,28 @@ dependencies = [
"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]]
name = "android-tzdata"
version = "0.1.1"
@@ -83,6 +105,12 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "atk"
version = "0.15.1"
@@ -140,6 +168,26 @@ version = "0.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "bitflags"
version = "1.3.2"
@@ -262,6 +310,7 @@ version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"jobserver",
"libc",
]
@@ -271,6 +320,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfb"
version = "0.7.3"
@@ -317,9 +375,26 @@ dependencies = [
"iana-time-zone",
"num-traits",
"serde",
"windows-targets",
"windows-targets 0.48.5",
]
[[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]]
name = "cocoa"
version = "0.24.1"
@@ -412,6 +487,51 @@ dependencies = [
"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]]
name = "cpufeatures"
version = "0.2.9"
@@ -531,6 +651,12 @@ dependencies = [
"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]]
name = "deranged"
version = "0.3.8"
@@ -1161,6 +1287,12 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hound"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
[[package]]
name = "html5ever"
version = "0.25.2"
@@ -1360,6 +1492,20 @@ dependencies = [
"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]]
name = "jni"
version = "0.20.0"
@@ -1380,6 +1526,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.64"
@@ -1432,12 +1587,39 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "libc"
version = "0.2.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "libudev"
version = "0.3.0"
@@ -1595,6 +1777,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.7.1"
@@ -1613,11 +1801,25 @@ checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4"
dependencies = [
"bitflags 1.3.2",
"jni-sys",
"ndk-sys",
"ndk-sys 0.3.0",
"num_enum",
"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]]
name = "ndk-context"
version = "0.1.1"
@@ -1633,12 +1835,32 @@ dependencies = [
"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]]
name = "new_debug_unreachable"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "nix"
version = "0.26.4"
@@ -1656,6 +1878,16 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "nu-ansi-term"
version = "0.46.0"
@@ -1666,6 +1898,17 @@ dependencies = [
"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]]
name = "num-integer"
version = "0.1.45"
@@ -1737,6 +1980,17 @@ dependencies = [
"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]]
name = "objc_exception"
version = "0.1.2"
@@ -1764,6 +2018,38 @@ dependencies = [
"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]]
name = "once_cell"
version = "1.18.0"
@@ -1831,7 +2117,7 @@ dependencies = [
"libc",
"redox_syscall 0.3.5",
"smallvec",
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
@@ -1840,6 +2126,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.3.0"
@@ -2238,12 +2530,89 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.4.0"
@@ -2448,7 +2817,7 @@ dependencies = [
"cfg-if",
"libudev",
"mach2",
"nix",
"nix 0.26.4",
"regex",
"scopeguard",
"winapi",
@@ -2484,6 +2853,12 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "shlex"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
[[package]]
name = "simd-adler32"
version = "0.3.7"
@@ -2586,6 +2961,56 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "syn"
version = "1.0.109"
@@ -2659,13 +3084,13 @@ dependencies = [
"gtk",
"image",
"instant",
"jni",
"jni 0.20.0",
"lazy_static",
"libc",
"log",
"ndk",
"ndk 0.6.0",
"ndk-context",
"ndk-sys",
"ndk-sys 0.3.0",
"objc",
"once_cell",
"parking_lot",
@@ -2735,6 +3160,7 @@ dependencies = [
"rand 0.8.5",
"raw-window-handle",
"regex",
"rfd",
"semver",
"serde",
"serde_json",
@@ -3083,6 +3509,9 @@ dependencies = [
name = "toos-dashboard"
version = "0.0.0"
dependencies = [
"once_cell",
"rodio",
"rust-embed",
"serde",
"serde_json",
"serialport",
@@ -3312,6 +3741,18 @@ dependencies = [
"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]]
name = "wasm-bindgen-macro"
version = "0.2.87"
@@ -3341,6 +3782,16 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "webkit2gtk"
version = "0.18.2"
@@ -3457,6 +3908,19 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "windows"
version = "0.39.0"
@@ -3471,13 +3935,22 @@ dependencies = [
"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]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
@@ -3527,7 +4000,22 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[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]]
@@ -3563,6 +4051,12 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a"
[[package]]
name = "windows_aarch64_msvc"
version = "0.39.0"
@@ -3581,6 +4075,12 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1"
[[package]]
name = "windows_i686_gnu"
version = "0.39.0"
@@ -3599,6 +4099,12 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c"
[[package]]
name = "windows_i686_msvc"
version = "0.39.0"
@@ -3617,6 +4123,12 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "windows_x86_64_gnu"
version = "0.39.0"
@@ -3647,6 +4159,12 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "windows_x86_64_msvc"
version = "0.39.0"

View File

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

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,128 @@
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 std::path::{Path, PathBuf};
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 } ));
static PLAYING: Mutex<bool> = Mutex::new(false);
pub static AUDIO_PATH: Mutex<Lazy<PathBuf>> = Mutex::new(Lazy::new(|| Path::new("assets/audio.mp3").to_path_buf()));
#[tauri::command]
pub fn start() {
let mut playing = PLAYING.lock().unwrap();
if *playing {
return;
} else {
*playing = true;
}
thread::spawn(move || {
println!("Starting animation...");
play_sound();
thread::sleep(Duration::from_millis(800));
let _ = serial::write_serial(format!("SET_LIGHT:0;").as_str());
stage_one();
stage_two();
let mut playing = PLAYING.lock().unwrap();
*playing = false;
});
}
fn play_sound() {
thread::spawn(|| {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let path = AUDIO_PATH.lock().unwrap();
let file = BufReader::new(File::open(&**path).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());
thread::sleep(Duration::from_millis(1000));
let _ = serial::write_serial(format!("SET_LIGHT:255;").as_str());
}

View File

@@ -1,83 +1,23 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::sync:: Mutex;
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()),
};
}
mod serial;
mod animation;
fn main() {
tauri::Builder::default()
.manage(PortMap::default())
.invoke_handler(tauri::generate_handler![get_serial_ports, write_serial, open_port])
.invoke_handler(tauri::generate_handler![serial::get_serial_ports, serial::write_serial, serial::open_port, serial::close_port, animation::start])
.setup(|app| {
let resource_path = app.path_resolver()
.resolve_resource("assets/audio.mp3")
.expect("failed to resolve resource");
let mut audio_path = animation::AUDIO_PATH.lock().unwrap();
**audio_path = resource_path;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,103 @@
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

@@ -2,7 +2,7 @@
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"devPath": "http://127.0.0.1:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
@@ -16,18 +16,24 @@
"shell": {
"all": false,
"open": true
},
"dialog": {
"all": true
}
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"identifier": "dev.xeovalyte.toosdashboard",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": [
"assets/audio.mp3"
]
},
"security": {

View File

@@ -2,10 +2,14 @@
<div class="w-full flex h-screen bg-neutral-950">
<Sidebar @updateCurrentPage="setCurrentPage" />
<div class="w-full">
<Status />
<Main v-if="currentPage === 0" />
<Conf v-if="currentPage === 1" />
<Test v-if="currentPage === 2" />
</div>
<audio id="audioContainer">
<source src="./assets/audio.mp3" type="audio/mp3">
</audio>
</div>
</template>
@@ -14,12 +18,27 @@ import Sidebar from "./components/Sidebar.vue";
import Test from "./components/Test.vue";
import Main from "./components/Main.vue";
import Conf from "./components/Conf.vue";
import Status from "./components/Status.vue";
import { ref } from "vue";
import { ref, onMounted } 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 setCurrentPage = (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>

Binary file not shown.

View File

@@ -1,3 +1,23 @@
<template>
<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>
<script setup>
import { invoke } from "@tauri-apps/api/tauri"
const test = async () => {
await invoke('start');
}
</script>

View File

@@ -0,0 +1,31 @@
<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>
<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 my-5">LED Strip Monster</h2>
<h2 class="text-white font-bold text-lg text-center mb-5">LED Strip Monster</h2>
<div class="flex flex-col items-center">
<color-input disable-alpha v-model="color" />
<div class="space-x-3">
@@ -15,16 +15,35 @@
</div>
</div>
</div>
<div class="bg-neutral-800 rounded-2xl p-5">
<h2 class="text-white font-bold text-lg text-center my-5">LED Strip Hallway</h2>
<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 Hallway</h2>
<div class="flex flex-col items-center">
<input v-model="brightness" type="range" min="0" max="100" class="w-40">
<label class="text-white mt-2">BRIGHTNESS: {{ brightness }}% </label>
<button @click="submitBrightness" class="px-5 py-2 bg-sky-400 w-full rounded my-5">
<button @click="submitBrightness" class="px-5 py-2 bg-sky-400 w-full rounded mt-4">
Submit
</button>
</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>
</template>
@@ -34,6 +53,7 @@ import { useSerial } from "../composables/useSerial"
const color = ref({ r: 0, g: 128, b: 255, a: 1});
const brightness = ref(100);
const pixel = ref({ color: { r: 64, g: 255, b: 255, a: 1 }, pixel: 0 });
const submitColor = () => {
useSerial("SET_STRIP_COLOR:" + `${color.value.r},${color.value.g},${color.value.b}`);
@@ -42,6 +62,14 @@ const submitColor = () => {
const submitBrightness = () => {
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>
<style>

View File

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

View File

@@ -1,9 +1,14 @@
import { invoke } from "@tauri-apps/api/tauri"
import { message } from '@tauri-apps/api/dialog';
import { useLocalStorage } from '@vueuse/core'
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 })
export function useSerial(input) {
console.log(serialConfig.value)
invoke('write_serial', { input: input + ";", portName: serialConfig.value.port, baud: serialConfig.value.baud });
export async function useSerial(input) {
try {
await 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' });
}
}