feat: Half working state

This commit is contained in:
Xeovalyte 2023-10-13 09:43:42 +02:00
parent bac28c30ad
commit 4ae2e63add
20 changed files with 1521 additions and 183 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Vue 3 App</title> <title>Frankenstein Dashboard</title>
</head> </head>
<body> <body>

File diff suppressed because it is too large Load Diff

View File

@ -10,12 +10,17 @@
"tauri": "tauri" "tauri": "tauri"
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1.5.0",
"@vueuse/core": "^10.5.0",
"vue": "^3.3.4", "vue": "^3.3.4",
"@tauri-apps/api": "^1.5.0" "vue-color-input": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {
"@tauri-apps/cli": "^1.5.0",
"@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue": "^4.2.3",
"vite": "^4.4.4", "autoprefixer": "^10.4.16",
"@tauri-apps/cli": "^1.5.0" "postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"vite": "^4.4.4"
} }
} }

View File

@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

View File

@ -2,6 +2,27 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "CoreFoundation-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0e9889e6db118d49d88d84728d0e964d973a5680befb5f85f55141beea5c20b"
dependencies = [
"libc",
"mach",
]
[[package]]
name = "IOKit-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99696c398cbaf669d2368076bdb3d627fb0ce51a26899d7c61228c5c0af3bf4a"
dependencies = [
"CoreFoundation-sys",
"libc",
"mach",
]
[[package]] [[package]]
name = "addr2line" name = "addr2line"
version = "0.21.0" version = "0.21.0"
@ -1417,6 +1438,26 @@ 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 = "libudev"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0"
dependencies = [
"libc",
"libudev-sys",
]
[[package]]
name = "libudev-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
dependencies = [
"libc",
"pkg-config",
]
[[package]] [[package]]
name = "line-wrap" name = "line-wrap"
version = "0.1.1" version = "0.1.1"
@ -1469,6 +1510,24 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
[[package]]
name = "mach"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9"
dependencies = [
"libc",
]
[[package]]
name = "mach2"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d0d1830bcd151a6fc4aea1369af235b36c1528fe976b8ff678683c9995eade8"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@ -1580,6 +1639,17 @@ 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.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
]
[[package]] [[package]]
name = "nodrop" name = "nodrop"
version = "0.1.14" version = "0.1.14"
@ -2366,6 +2436,24 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "serialport"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c32634e2bd4311420caa504404a55fad2131292c485c97014cbed89a5899885f"
dependencies = [
"CoreFoundation-sys",
"IOKit-sys",
"bitflags 1.3.2",
"cfg-if",
"libudev",
"mach2",
"nix",
"regex",
"scopeguard",
"winapi",
]
[[package]] [[package]]
name = "servo_arc" name = "servo_arc"
version = "0.1.1" version = "0.1.1"
@ -2997,6 +3085,7 @@ version = "0.0.0"
dependencies = [ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serialport",
"tauri", "tauri",
"tauri-build", "tauri-build",
] ]

View File

@ -16,6 +16,7 @@ tauri-build = { version = "1.5", features = [] }
tauri = { version = "1.5", features = ["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"
[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,15 +1,93 @@
// 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")]
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command 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] #[tauri::command]
fn greet(name: &str) -> String { async fn read_serial(port_name: &str, port_map: State<'_, PortMap>) -> Result<(), String> {
format!("Hello, {}! You've been greeted from Rust!", name) match port_map.0.lock().unwrap().get(port_name) {
Some(port) => {
let mut clone = port.try_clone().expect("Failed to clone");
let mut buffer: Vec<u8> = vec![0; 1024];
println!("Reading serial");
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());
}
}
Ok(())
},
Err(ref e) if e.kind() == ErrorKind::TimedOut => Err(String::from("Timed out")),
Err(e) => Err(e.to_string()),
}
}
None => {
Ok(())
}
}
}
#[tauri::command]
async fn write_serial(input: &str, port_name: &str, port_map: State<'_, PortMap>) -> Result<(), String> {
println!("Trying to write");
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 => {
println!("Writing to serial not found");
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);
println!("Port open");
},
Err(err) => return Err(err.to_string()),
};
Ok(())
} }
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet]) .manage(PortMap::default())
.invoke_handler(tauri::generate_handler![get_serial_ports, read_serial, 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

@ -37,7 +37,7 @@
{ {
"fullscreen": false, "fullscreen": false,
"resizable": true, "resizable": true,
"title": "toos-dashboard", "title": "Frankenstein Dashboard",
"width": 800, "width": 800,
"height": 600 "height": 600
} }

View File

@ -1,52 +1,25 @@
<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
import Greet from "./components/Greet.vue";
</script>
<template> <template>
<div class="container"> <div class="w-full flex h-screen bg-neutral-950">
<h1>Welcome to Tauri!</h1> <Sidebar @updateCurrentPage="setCurrentPage" />
<div class="w-full">
<div class="row"> <Main v-if="currentPage === 0" />
<a href="https://vitejs.dev" target="_blank"> <Conf v-if="currentPage === 1" />
<img src="/vite.svg" class="logo vite" alt="Vite logo" /> <Test v-if="currentPage === 2" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" class="logo tauri" alt="Tauri logo" />
</a>
<a href="https://vuejs.org/" target="_blank">
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
</div> </div>
<p>Click on the Tauri, Vite, and Vue logos to learn more.</p>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VS Code</a>
+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
+
<a href="https://github.com/tauri-apps/tauri-vscode" target="_blank"
>Tauri</a
>
+
<a href="https://github.com/rust-lang/rust-analyzer" target="_blank"
>rust-analyzer</a
>
</p>
<Greet />
</div> </div>
</template> </template>
<style scoped> <script setup>
.logo.vite:hover { import Sidebar from "./components/Sidebar.vue";
filter: drop-shadow(0 0 2em #747bff); import Test from "./components/Test.vue";
} import Main from "./components/Main.vue";
import Conf from "./components/Conf.vue";
.logo.vue:hover { import { ref } from "vue";
filter: drop-shadow(0 0 2em #249b73);
const currentPage = ref(2);
const setCurrentPage = (x) => {
currentPage.value = x;
} }
</style> </script>

View File

@ -0,0 +1,10 @@
<template>
<h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Test</h1>
<div class="flex w-full justify-center">
<Serial />
</div>
</template>
<script setup>
import Serial from "./conf/Serial.vue"
</script>

View File

@ -1,21 +0,0 @@
<script setup>
import { ref } from "vue";
import { invoke } from "@tauri-apps/api/tauri";
const greetMsg = ref("");
const name = ref("");
async function greet() {
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
greetMsg.value = await invoke("greet", { name: name.value });
}
</script>
<template>
<form class="row" @submit.prevent="greet">
<input id="greet-input" v-model="name" placeholder="Enter a name..." />
<button type="submit">Greet</button>
</form>
<p>{{ greetMsg }}</p>
</template>

View File

@ -0,0 +1,3 @@
<template>
<h1 class="text-white text-2xl w-full font-bold text-center my-24">Frankenstein Dashboard</h1>
</template>

View File

@ -0,0 +1,17 @@
<template>
<div class="bg-neutral-800 text-white font-bold w-min px-2 flex flex-col gap-10 justify-center">
<button @click="$emit('updateCurrentPage', 0)" class="text-center bg-neutral-900 w-16 h-16 rounded-xl">
MAIN
</button>
<button @click="$emit('updateCurrentPage', 1)" class="text-center bg-neutral-900 w-16 h-16 rounded-xl">
CONF
</button>
<button @click="$emit('updateCurrentPage', 2)" class="text-center bg-neutral-900 w-16 h-16 rounded-xl">
TEST
</button>
</div>
</template>
<script setup>
const emit = defineEmits(['updateCurrentPage'])
</script>

View File

@ -0,0 +1,53 @@
<template>
<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>
<div class="flex flex-col items-center">
<color-input disable-alpha v-model="color" />
<div class="space-x-3">
<button @click="submitColor" class="px-5 py-2 bg-sky-400 rounded my-5">
Submit Color
</button>
<button class="px-3 py-2 bg-red-700 rounded my-5">
reset
</button>
</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="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">
Submit
</button>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from "vue"
import { useSerial } from "../composables/useSerial"
const color = ref({ r: 0, g: 128, b: 255, a: 1});
const brightness = ref(100);
const submitColor = () => {
useSerial("SET_STRIP_COLOR:" + `${color.value.r},${color.value.g},${color.value.b}`);
}
const submitBrightness = () => {
useSerial("SET_LIGHT:" + brightness.value * 2.55);
}
</script>
<style>
.color-input.user .box {
/* make clickable box a 100x100 circle */
width: 100px;
border-radius: 10px;
}
</style>

View File

@ -0,0 +1,42 @@
<template>
<div class="bg-neutral-800 rounded-2xl p-5">
<h2 class="text-white font-bold text-lg text-center mb-5">Serial</h2>
<div class="flex flex-col gap-y-2 items-center">
<div class="grid grid-cols-[70px_1fr] auto-cols-auto gap-y-2">
<label class="text-white mr-2">PORT </label>
<input type="text" v-model="serialConfig.port">
<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">
{{ port }}
</span>
<button @click="readSerial">READ</button>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { invoke } from "@tauri-apps/api/tauri"
import { useLocalStorage } from '@vueuse/core'
const ports = ref([])
const serialConfig = useLocalStorage('serialConfig', { port: '', baud: 9600 })
const getSerialPorts = async () => {
return await invoke('get_serial_ports');
}
onMounted(async () => {
ports.value = await getSerialPorts()
invoke('open_port');
})
const readSerial = async () => {
return await invoke('read_serial', { portName: "/dev/ttyUSB0" });
}
</script>

View File

@ -0,0 +1,9 @@
import { invoke } from "@tauri-apps/api/tauri"
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 });
}

View File

@ -0,0 +1,7 @@
import { Store } from "tauri-plugin-store-api";
const store = new Store(".settings.dat");
export function useStore() {
return store
}

View File

@ -1,5 +1,6 @@
import { createApp } from "vue"; import { createApp } from "vue";
import "./styles.css"; import "./styles.css";
import App from "./App.vue"; import App from "./App.vue";
import ColorInput from 'vue-color-input'
createApp(App).mount("#app"); createApp(App).use(ColorInput).mount("#app");

View File

@ -1,109 +1,9 @@
:root { @tailwind base;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif; @tailwind components;
font-size: 16px; @tailwind utilities;
line-height: 24px;
font-weight: 400;
color: #0f0f0f; @layer components {
background-color: #f6f6f6; input {
@apply bg-neutral-700 rounded px-2 text-white
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
.container {
margin: 0;
padding-top: 10vh;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: 0.75s;
}
.logo.tauri:hover {
filter: drop-shadow(0 0 2em #24c8db);
}
.row {
display: flex;
justify-content: center;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
h1 {
text-align: center;
}
input,
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
color: #0f0f0f;
background-color: #ffffff;
transition: border-color 0.25s;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}
button {
cursor: pointer;
}
button:hover {
border-color: #396cd8;
}
button:active {
border-color: #396cd8;
background-color: #e8e8e8;
}
input,
button {
outline: none;
}
#greet-input {
margin-right: 5px;
}
@media (prefers-color-scheme: dark) {
:root {
color: #f6f6f6;
background-color: #2f2f2f;
}
a:hover {
color: #24c8db;
}
input,
button {
color: #ffffff;
background-color: #0f0f0f98;
}
button:active {
background-color: #0f0f0f69;
} }
} }

View File

@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx,vue}",
],
theme: {
extend: {},
},
plugins: [],
}