Elnu 6 months ago
parent a4a69a89fd
commit 23ec580178

@ -1,5 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./helloworld/Cargo.toml",
"./dorm-controller/Cargo.toml",
]
}

237
Cargo.lock generated

@ -3,5 +3,240 @@
version = 3
[[package]]
name = "helloworld"
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]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "dorm-controller"
version = "0.1.0"
dependencies = [
"lipsum",
"serialport",
]
[[package]]
name = "libc"
version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[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]]
name = "lipsum"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c5e9ef2d2ad6fe67a59ace27c203c8d3a71d195532ee82e3bbe0d5f9a9ca541"
dependencies = [
"rand",
"rand_chacha",
]
[[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]]
name = "memchr"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[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]]
name = "pkg-config"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "regex"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[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 2.0.2",
"cfg-if",
"libudev",
"mach2",
"nix",
"regex",
"scopeguard",
"winapi",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

@ -1,3 +1,3 @@
[workspace]
members = ["helloworld"]
members = ["dorm-controller"]
resolver = "2"

@ -1,8 +1,10 @@
[package]
name = "helloworld"
name = "dorm-controller"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lipsum = "0.9.0"
serialport = "4.2.2"

@ -0,0 +1,21 @@
use std::time::Duration;
fn main() {
let ports = serialport::available_ports().unwrap();
println!("Available ports:");
for p in ports {
println!("{}", p.port_name);
}
let mut port = serialport::new("/dev/ttyACM0", 115_200)
.timeout(Duration::from_millis(1000))
.open().expect("Failed to open port");
loop {
let mut angle = String::new();
std::io::stdin().read_line(&mut angle).unwrap();
angle
.trim()
.parse()
.map(|angle| port.write(&[angle]).unwrap())
.unwrap();
}
}

@ -0,0 +1,96 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1698924604,
"narHash": "sha256-GCFbkl2tj8fEZBZCw3Tc0AkGo0v+YrQlohhEGJ/X4s0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fa804edfb7869c9fb230e174182a8a1a7e512c40",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1699150490,
"narHash": "sha256-G+S+UjK365fm64uejAJ3ChANUDKgLb0YCz8pb9t/5sc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "0e45a692657ec4b6993e65dd38b62b0d1459664c",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

@ -1,6 +1,6 @@
/*
TODO
1. Find and replace "helloworld" with your package name for **ALL FILES IN REPOSITORY**
1. Find and replace "dorm-controller" with your package name for **ALL FILES IN REPOSITORY**
2. Add a flake description that describes the workspace on line 27
3. Add a package description on line 70
4. (optional) uncomment `nativeBuildInputs` and `buildInputs` on lines 43 and 44 if you need openssl
@ -13,8 +13,8 @@ TODO
Some utility commands:
- `nix flake update --commit-lock-file`
- `nix flake lock update-input <input>`
- `nix build .#helloworld` or `nix build .`
- `nix run .#helloworld` or `nix run .`
- `nix build .#dorm-controller` or `nix build .`
- `nix run .#dorm-controller` or `nix run .`
*/
{
@ -34,8 +34,8 @@ Some utility commands:
};
rustSettings = with pkgs; {
src = ./.;
#nativeBuildInputs = [ pkg-config ];
#buildInputs = [ openssl ];
nativeBuildInputs = [ pkg-config ];
buildInputs = [ libudev-zero ];
cargoHash = nixpkgs.lib.fakeHash;
};
meta = with nixpkgs.lib; {
@ -53,14 +53,14 @@ Some utility commands:
cargo-edit
bacon
];
inputsFrom = with self.packages.${system}; [ helloworld ];
inputsFrom = with self.packages.${system}; [ dorm-controller ];
};
packages.${system} = {
default = self.packages.${system}.helloworld;
helloworld = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "helloworld";
default = self.packages.${system}.dorm-controller;
dorm-controller = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "dorm-controller";
version = "0.1.0";
buildAndTestSubdir = "helloworld";
buildAndTestSubdir = "dorm-controller";
cargoHash = "sha256-+TaGIiKf+Pz2bTABeG8aCZz0/ZTCKl5398+qbas4Nvo=";
meta = meta // {
description = "";
@ -71,14 +71,14 @@ Some utility commands:
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
options.services.helloworld = {
enable = lib.mkEnableOption (lib.mdDoc "helloworld service");
options.services.dorm-controller = {
enable = lib.mkEnableOption (lib.mdDoc "dorm-controller service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.helloworld;
defaultText = "pkgs.helloworld";
default = self.packages.${system}.dorm-controller;
defaultText = "pkgs.dorm-controller";
description = lib.mdDoc ''
The helloworld package that should be used.
The dorm-controller package that should be used.
'';
};
port = lib.mkOption {
@ -89,16 +89,16 @@ Some utility commands:
'';
};
};
config.systemd.services.helloworld = let
cfg = config.services.helloworld;
pkg = self.packages.${system}.helloworld;
config.systemd.services.dorm-controller = let
cfg = config.services.dorm-controller;
pkg = self.packages.${system}.dorm-controller;
in lib.mkIf cfg.enable {
description = pkg.meta.description;
after = [ "network.target" ];
wantedBy = [ "network.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/helloworld --port ${builtins.toString cfg.port}
${cfg.package}/bin/dorm-controller --port ${builtins.toString cfg.port}
'';
Restart = "always";
DynamicUser = true;

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}
Loading…
Cancel
Save