Skip to content

Commit

Permalink
Merge pull request #3 from lorforlinux/main
Browse files Browse the repository at this point in the history
Add Arduino Nano support and setup GitHub actions
  • Loading branch information
lorforlinux authored Jan 9, 2025
2 parents 4cae13f + 14404c1 commit ef61cc9
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 18 deletions.
177 changes: 177 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Build and Release Tauri App

on:
push:
branches:
- main

jobs:
check-version-and-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Get Version from package.json
id: get_version
run: |
version="v$(jq -r '.version' package.json)"
echo "::set-output name=version::$version"
- name: Check if Tag Exists
id: check_tag
run: |
version="${{ steps.get_version.outputs.version }}"
if git rev-parse "$version" >/dev/null 2>&1; then
echo "Tag $version already exists."
echo "::set-output name=tag_exists::true"
else
echo "Tag $version does not exist."
echo "::set-output name=tag_exists::false"
fi
- name: Create Tag
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
version="${{ steps.get_version.outputs.version }}"
git config user.name "github-actions"
git config user.email "[email protected]"
git tag -a "$version" -m "Release version $version"
git push origin "$version"
build:
needs: check-version-and-tag
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-22.04]
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Debug the runner OS
run: echo "Running on ${{ runner.os }}"

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: |
npm install
npm install tailwindcss-animate
- name: Run npm audit
run: npm audit --audit-level=high

- name: Install GTK and Build Tools (Ubuntu only)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libudev-dev build-essential pkg-config
- name: Install Tauri CLI (locally)
run: npm install @tauri-apps/cli

- name: Clean npm cache
run: npm cache clean --force

- name: Build Tauri App
run: npx tauri build

# Upload platform-specific artifacts
- name: Upload Artifact for macOS
if: runner.os == 'macOS'
uses: actions/upload-artifact@v3
with:
name: tauri-app-macos
path: src-tauri/target/release/bundle/dmg/*.dmg

- name: Upload Artifact for Windows
if: runner.os == 'Windows'
uses: actions/upload-artifact@v3
with:
name: tauri-app-windows
path: src-tauri/target/release/bundle/msi/*.msi

- name: Upload Artifact for Linux (deb)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: tauri-app-linux-deb
path: src-tauri/target/release/bundle/deb/*.deb

- name: Upload Artifact for Linux (rpm)
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: tauri-app-linux-rpm
path: src-tauri/target/release/bundle/rpm

release:
needs: [build, check-version-and-tag]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Fetch All Tags
run: git fetch --tags

- name: Verify Created Tag
id: verified_version
run: |
version="v$(jq -r '.version' package.json)"
echo "::set-output name=version::$version"
echo "Verifying tag $version"
if ! git tag -l | grep -q "$version"; then
echo "Error: Tag $version not found locally."
exit 1
fi
# Download platform-specific artifacts
- name: Download macOS Artifact
uses: actions/download-artifact@v3
with:
name: tauri-app-macos
path: src-tauri/target/release/bundle/dmg

- name: Download Windows Artifact
uses: actions/download-artifact@v3
with:
name: tauri-app-windows
path: src-tauri/target/release/bundle/msi

- name: Download Linux Artifact (deb)
uses: actions/download-artifact@v3
with:
name: tauri-app-linux-deb
path: src-tauri/target/release/bundle/deb

- name: Download Linux Artifact (rpm)
uses: actions/download-artifact@v3
with:
name: tauri-app-linux-rpm
path: src-tauri/target/release/bundle/rpm

# Create GitHub Release with only artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: "${{ steps.verified_version.outputs.version }}"
files: |
src-tauri/target/release/bundle/dmg/*.dmg
src-tauri/target/release/bundle/msi/*.msi
src-tauri/target/release/bundle/deb/*.deb
src-tauri/target/release/bundle/rpm/*.rpm
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "chords-lsl-app",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"tauri": "tauri",
"tauri:build": "tauri build"
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.1",
Expand All @@ -33,4 +35,4 @@
"tailwindcss": "^3.4.1",
"typescript": "^5.7.2"
}
}
}
6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "Chords LSL Connector"
version = "0.1.0"
name = "Chords-Lsl-Connector"
version = "0.1.1"
description = "Rust based LSL connector for device running Chords Firmware."
authors = ["Aman Maheshwari", "Deepak Khatri"]
license = "GPL V3"
repository = "https://github.com/upsidedownlabs/Chords-LSL-Connector"
edition = "2024"
edition = "2021"
rust-version = "1.77.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
18 changes: 10 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ lazy_static! {
fn detect_arduino() -> Result<String, String> {
loop {
let ports = serialport::available_ports().expect("No ports found!");
println!("Attempting to connect to port: {:#?}", ports);


for port_info in ports {
Expand All @@ -52,6 +51,7 @@ fn detect_arduino() -> Result<String, String> {
*PACKET_SIZE.lock().unwrap() = 10; // Change the baud rate dynamically
*CHANNELS.lock().unwrap() = 3; // Change the baud rate dynamically
}

}

match serialport::new(&port_name, *BAUDRATE.lock().unwrap())
Expand Down Expand Up @@ -85,7 +85,12 @@ fn detect_arduino() -> Result<String, String> {
|| response.contains("GIGA-R1")
|| response.contains("RPI-PICO-RP2040")
|| response.contains("UNO-CLONE")
|| response.contains("NANO-CLONE")
{
if response.contains("NANO-CLONE"){
*PACKET_SIZE.lock().unwrap() = 20; // Change the baud rate dynamically
*CHANNELS.lock().unwrap() = 8; // Change the baud rate dynamically
}
println!("Valid device found on port: {}", port_name);
drop(port);
return Ok(port_name); // Return the found port name directly
Expand All @@ -99,7 +104,6 @@ fn detect_arduino() -> Result<String, String> {
}
}
}

println!("Final response from port {}: {}", port_name, response);

drop(port);
Expand Down Expand Up @@ -138,7 +142,8 @@ async fn start_streaming(port_name: String, app_handle: AppHandle) {
// Create StreamOutlet in the same thread
let (tx, rx) = std::sync::mpsc::channel::<Vec<i16>>();
let outlet = Arc::new(Mutex::new(StreamOutlet::new(&info, 0, 360).unwrap()));




// Use spawn_blocking to handle the task in a separate thread
tokio::task::spawn_blocking(move || {
Expand All @@ -151,12 +156,9 @@ async fn start_streaming(port_name: String, app_handle: AppHandle) {
println!("Connected to device on port: {}", port_name);
let start_command = b"START\r\n";

for i in 1..=3 {
for i in 1..=5 {
if let Err(e) = port.write_all(start_command) {
println!("Failed to send START command (attempt {}): {:?}", i, e);
} else {
println!("START command sent (attempt {}).", i);
}
}
thread::sleep(Duration::from_millis(400));
}

Expand Down
9 changes: 7 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2.0.0-rc",
"productName": "chords-lsl-connector",
"version": "0.1.0",
"version": "0.1.1",
"identifier": "com.upsidedownlabs.chords",
"build": {
"frontendDist": "../out",
Expand All @@ -25,7 +25,12 @@
},
"bundle": {
"active": true,
"targets": "all",
"targets": [
"deb",
"msi",
"dmg",
"rpm"
],
"icon": [
"icons/chords-logo.png",
"icons/Chords-logo-128px.ico"
Expand Down

0 comments on commit ef61cc9

Please sign in to comment.