diff --git a/.gitignore b/.gitignore index bd8a624..761066c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ -target -*.wav \ No newline at end of file +**/target +**/*.wav +package +result +.wifi-name +.wifi-password +*.pem \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 89482d9..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -install: - cd scripts && setup-raspberry-pi.sh - -build-audio: - cd audio-logger && cargo build --release - -start-all: - cd scripts && start-all.sh diff --git a/README.md b/README.md index a049b5f..93ef9cd 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,106 @@ # Hydrophonitor -A software package to record audio and related metadata from a configuration -of hydrophones. - -For setup instructions, see `docs/setup.md`. +A NixOS flake based operating system for Raspberry Pi 3 (tested on v1.2) and Raspberry Pi 4 (tested on 4B), configured for recording audio through hydrophones via a USB sound card, logging GPS data through a USB GPS dongle, and recording depth through a pressure sensor and an analog-to-digital converter (depth recording not implemented yet). ## Overview Module | Description -----------------|- -audio-logger | Receive an audio signal from the DAC and write it on disk in `.wav` format. -gps-logger | Record position and time of the device in `.csv` format. -depth-logger | Record depth of the device and save it in `.csv` format. -*lcd-display | Provide information on the device's LCD screen +audio-recorder | Receive an audio signal from the DAC and write it on disk in `.wav` format. +gps-recorder | Record position and time of the device in `.json` format. +*depth-recorder | Record depth of the device and save it in `.csv` format. +real-time-clock | Configure and use an RTC to update system time from hardware clock when not connected to the internet. +shutdown-button | Gracefully shut down the system using a button attached to the GPIO pin. *device-controls | Provide device control using physical buttons. *) todo, not implemented yet -## Data Formats +### Data Formats -Type | Output file format | Output file name | Output structure | Content -------------|--------------------|--------------------------------------|------------------|- -Audio Data | .wav | _audio.wav | Each recorded chunk will be written to its own file in `audio` folder | Wav audio data, configuration defined in XXX -GPS Data | .csv | _gps.wav | All data written to a single file | Csv data with following fields: GPS time UTC, latitude, longitude, speed, satellites in view -Depth data | .csv | _depth.wav | All data written to a single file | Csv data with following fields: date and time, voltage of depth sensor (V), depth (m) -Log data | .txt | _log.txt | All data written to a single file | Text file where each entry contains the following: date and time, process that writes the entry, logged information +Type | Output file format | Output file name | Output structure +------------|--------------------|--------------------------------------|------------------ +Audio Data | .wav | `.wav` | Each recorded batch will be written to its own file in `/output/audio` folder +GPS Data | .json | `.json` | All data written to a single file in `/output/gps` -## Output Locations +### Notes on Modules and Configuration Options -The location for the output directories is defined by a configurable value OUTPUT_PATH in `hydrophonitor-config.txt`. If directories along this path do not exist, they will be created. If an error occurs or the location is not writable, output will be written to the default location (DEFAULT_OUTPUT_PATH in hydrophonitor-config.txt) instead. +- `audio-recorder` module + - `audio-recorder` systemd service connects to a USB soundcard and starts recording by default in batches to a specified output directory + - configuration options and default values: + - `output-folder` (/output/audio) + - `sample-rate` (192000) + - `sample-format` (S32_LE) + - `channels` (4) + - `max-file-time-secs`(300) +- `gps-recorder` module: fetched from hydrophonitor-gps repository + - enables gpsd + - `gps-recorder` systemd service starts `gps-recorder` program that listens for and logs GPS data to a json file in a specified directory + - configuration options and default values: + - `output-folder` (/output/gps) + - `interval-secs` (10) +- `real-time-clock` module + - `i2c-rtc-start` systemd service configures I2C bus to connect to DS3231 RTC attached to GPIO pins of the RPi and updates system time to hardware clock time + - configuration options and default values: + - `i2c-bus` (1) +- `shutdown-button` module (currently only for RPi 4) + - `shutdown-button` service runs `shutdown-button` program that listens for a button press (by default from GPIO pin 21) and once button press is detected, runs a graceful shutdown + - configuration options yet to be implemented in the program: + - `gpio-pin` (21) + - `shutdown-press-secs` (1) -SSD card mounting is not yet configured in the setup. -A recording session starts when the Raspberry Pi is turned on or booted, and ends on shutdown. Each session will have its output written in its own directory that will be named _recordings. \ No newline at end of file +## Other Configurations + +- user `kaskelotti` is created with sudo privileges +- ssh enabled with password authentication +- `i2c-dev`, `i2c_bcm2708`, and `rtc_1307` kernel modules enabled for i2c-rtc, `i2c-tools` package installed +- `deploy-rs` used for deployments (after initial bootstrapping and connecting the pi over wifi or ethernet) + +### Enabling WiFi + +Add the following to targets//default.nix where "SSID name" is replaced with the network name and "SSID password" is the network password: + +```nix + networking = { + hostName = "kaskelotti"; + wireless = { + enable = true; + networks = { + "SSID name" = { + psk = "SSID password"; + }; + }; + interfaces = ["wlan0"]; + }; + }; +``` + +## Building the Image on Mac M1 + +Image has been built with UTM (virtualization for silicon Macs, now running on 2020 M1 Air) on Ubuntu 22.04 VM (with nix installed) with the following command: +``` +nix build .#systems.raspberry-pi-4.config.system.build.sdImage --extra-experimental-features "nix-command flakes" +``` +The result image has to be copied from the VM nix store path to the directory that was shared between the client and the host. +``` +cp -rL result/sd-image/nixos-sd-image-23.11.20230908.db9208a-aarch64-linux.img . +``` + +Initially, image is flashed to the SD card with the following command (on the host) +``` +diskutil list # check SD card, here /dev/disk4 +diskutil unmountdisk /dev/disk4 +sudo dd if=../UTM/hydrophonitor/nixos-sd-image-23.11.20230702.0fbe93c-aarch64-linux.img of=/dev/disk4 status=progress +diskutil eject /dev/disk4 +``` + +After bootstrapping and connecting the Pi to the local network, deploy-rs can be used for deployments from UTM (update correct IP address to the deploy configuration): +``` +nix run github:serokell/deploy-rs .#raspberry-pi-4 +``` + +## Notes + +- On Raspberry Pi 4, we use the [Argon One m.2](https://argon40.com/products/argon-one-m-2-case-for-raspberry-pi-4) case with [Intenso M.2 TOP SATA III 1TB SSD](https://www.intenso.de/en/products/solid-state-drives/M.2-SSD-Top) and boot from SSD. We lacked a USB extension cable that would have allowed us to flash the SD card image directly to the SSD from the computer, so we ended up booting the Pi from a USB stick, copying the SD card image to the system on the USB stick, and from there flashing the image with `dd` to the SSD (which showed up as /dev/sda). After removing the USB stick, the Raspberry Pi successfully booted from the SSD. The setup also works using an ordinary SD card without an SSD. It would also be possible to run the operating system from the SD card, add an additional SSD, partition and format it and configure the outputs to be written to the SSD. +- On Raspberry Pi 3, we only tested with an SD card without the SSD, and witnessed some buffer overruns with `arecord` with the default settings, i.e. some audio output is lost. Also, running the `shutdown-button` program on Raspberry Pi 3 failed with permission denied on /dev/mem, even though the service is run as root. + diff --git a/audio-logger/.gitignore b/audio-logger/.gitignore deleted file mode 100644 index 5b3eb2d..0000000 --- a/audio-logger/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -*.wav -recordings \ No newline at end of file diff --git a/audio-logger/Cargo.lock b/audio-logger/Cargo.lock deleted file mode 100644 index 86808a2..0000000 --- a/audio-logger/Cargo.lock +++ /dev/null @@ -1,1430 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "alsa" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5915f52fe2cf65e83924d037b6c5290b7cee097c6b5c8700746e6168a343fd6b" -dependencies = [ - "alsa-sys", - "bitflags", - "libc", - "nix 0.23.1", -] - -[[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_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "audio" -version = "0.1.0" -dependencies = [ - "alsa", - "anyhow", - "chrono", - "clap", - "cpal 0.13.5", - "ctrlc", - "hound", - "jack 0.9.2", - "libc", - "nix 0.23.1", - "parking_lot 0.12.1", - "rodio", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bindgen" -version = "0.59.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "peeking_take_while", - "proc-macro2 1.0.43", - "quote 1.0.21", - "regex", - "rustc-hash", - "shlex", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bumpalo" -version = "3.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" - -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" -dependencies = [ - "jobserver", -] - -[[package]] -name = "cesu8" -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 = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-integer", - "num-traits", - "time", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "clang-sys" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" -dependencies = [ - "glob", - "libc", - "libloading 0.7.3", -] - -[[package]] -name = "clap" -version = "3.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" -dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "once_cell", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_derive" -version = "3.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "claxon" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688" - -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "memchr", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - -[[package]] -name = "coreaudio-rs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11894b20ebfe1ff903cbdc52259693389eea03b94918a2def2c30c3bf227ad88" -dependencies = [ - "bitflags", - "coreaudio-sys", -] - -[[package]] -name = "coreaudio-sys" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dff444d80630d7073077d38d40b4501fd518bd2b922c2a55edcc8b0f7be57e6" -dependencies = [ - "bindgen", -] - -[[package]] -name = "cpal" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74117836a5124f3629e4b474eed03e479abaf98988b4bb317e29f08cfe0e4116" -dependencies = [ - "alsa", - "core-foundation-sys", - "coreaudio-rs", - "jack 0.8.3", - "jni", - "js-sys", - "lazy_static", - "libc", - "mach", - "ndk 0.6.0", - "ndk-glue", - "nix 0.23.1", - "oboe", - "parking_lot 0.11.2", - "stdweb", - "thiserror", - "web-sys", - "winapi", -] - -[[package]] -name = "cpal" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d466b47cf0ea4100186a7c12d7d0166813dda7cf648553554c9c39c6324841b" -dependencies = [ - "alsa", - "core-foundation-sys", - "coreaudio-rs", - "jni", - "js-sys", - "libc", - "mach", - "ndk 0.7.0", - "ndk-context", - "nix 0.23.1", - "oboe", - "once_cell", - "parking_lot 0.12.1", - "stdweb", - "thiserror", - "web-sys", - "windows", -] - -[[package]] -name = "ctrlc" -version = "3.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d91974fbbe88ec1df0c24a4f00f99583667a7e2e6272b2b92d294d81e462173" -dependencies = [ - "nix 0.25.0", - "winapi", -] - -[[package]] -name = "cty" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" - -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2 1.0.43", - "quote 1.0.21", - "strsim", - "syn 1.0.100", -] - -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "dlib" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" -dependencies = [ - "libloading 0.7.3", -] - -[[package]] -name = "dlopen" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71e80ad39f814a9abe68583cd50a2d45c8a67561c3361ab8da240587dda80937" -dependencies = [ - "dlopen_derive", - "lazy_static", - "libc", - "winapi", -] - -[[package]] -name = "dlopen_derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f236d9e1b1fbd81cea0f9cbdc8dcc7e8ebcd80e6659cd7cb2ad5f6c05946c581" -dependencies = [ - "libc", - "quote 0.6.13", - "syn 0.15.44", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hound" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d13cdbd5dbb29f9c88095bbdc2590c9cba0d0a1269b983fef6b2cdd7e9f4db1" - -[[package]] -name = "iana-time-zone" -version = "0.1.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "js-sys", - "once_cell", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "jack" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3902a02287c3dcad784edd1ecc5f487774b63a5fe77dd9842ea9a993d0a4a23" -dependencies = [ - "bitflags", - "jack-sys 0.2.2", - "lazy_static", - "libc", - "log", -] - -[[package]] -name = "jack" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1c526d2fb3a79b52ba3459a9ede300393d7a9774e781576b71904fc01be2060" -dependencies = [ - "bitflags", - "dlib", - "jack-sys 0.3.4", - "lazy_static", - "libc", - "log", -] - -[[package]] -name = "jack-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57983f0d72dfecf2b719ed39bc9cacd85194e1a94cb3f9146009eff9856fef41" -dependencies = [ - "lazy_static", - "libc", - "libloading 0.6.7", -] - -[[package]] -name = "jack-sys" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9e233f62be3591634748e2a7ea1966605807e50f2687dd8d4a6b42ae894cd4" -dependencies = [ - "dlib", - "dlopen", - "lazy_static", - "libc", - "libloading 0.7.3", - "pkg-config", -] - -[[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-sys" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" - -[[package]] -name = "jobserver" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" -dependencies = [ - "libc", -] - -[[package]] -name = "js-sys" -version = "0.3.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -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.133" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" - -[[package]] -name = "libloading" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "libloading" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "minimp3" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985438f75febf74c392071a975a29641b420dd84431135a6e6db721de4b74372" -dependencies = [ - "minimp3-sys", - "slice-deque", - "thiserror", -] - -[[package]] -name = "minimp3-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e21c73734c69dc95696c9ed8926a2b393171d98b3f5f5935686a26a487ab9b90" -dependencies = [ - "cc", -] - -[[package]] -name = "ndk" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" -dependencies = [ - "bitflags", - "jni-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", - "jni-sys", - "ndk-sys 0.4.0", - "num_enum", - "raw-window-handle", - "thiserror", -] - -[[package]] -name = "ndk-context" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" - -[[package]] -name = "ndk-glue" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0c4a7b83860226e6b4183edac21851f05d5a51756e97a1144b7f5a6b63e65f" -dependencies = [ - "lazy_static", - "libc", - "log", - "ndk 0.6.0", - "ndk-context", - "ndk-macro", - "ndk-sys 0.3.0", -] - -[[package]] -name = "ndk-macro" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df7ac00c4672f9d5aece54ee3347520b7e20f158656c7db2e6de01902eb7a6c" -dependencies = [ - "darling", - "proc-macro-crate", - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "ndk-sys" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5a6ae77c8ee183dcbbba6150e2e6b9f3f4196a7666c02a715a95692ec1fa97" -dependencies = [ - "jni-sys", -] - -[[package]] -name = "ndk-sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21d83ec9c63ec5bf950200a8e508bdad6659972187b625469f58ef8c08e29046" -dependencies = [ - "jni-sys", -] - -[[package]] -name = "nix" -version = "0.23.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nix" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" -dependencies = [ - "autocfg", - "bitflags", - "cfg-if", - "libc", -] - -[[package]] -name = "nom" -version = "7.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_enum" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" -dependencies = [ - "proc-macro-crate", - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "oboe" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27f63c358b4fa0fbcfefd7c8be5cfc39c08ce2389f5325687e7762a48d30a5c1" -dependencies = [ - "jni", - "ndk 0.6.0", - "ndk-context", - "num-derive", - "num-traits", - "oboe-sys", -] - -[[package]] -name = "oboe-sys" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3370abb7372ed744232c12954d920d1a40f1c4686de9e79e800021ef492294bd" -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.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" - -[[package]] -name = "os_str_bytes" -version = "6.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" - -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.5", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core 0.9.3", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - -[[package]] -name = "proc-macro-crate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" -dependencies = [ - "once_cell", - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2 1.0.43", -] - -[[package]] -name = "raw-window-handle" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" -dependencies = [ - "cty", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "rodio" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb10b653d5ec0e9411a2e7d46e2c7f4046fd87d35b9955bd73ba4108d69072b5" -dependencies = [ - "claxon", - "cpal 0.14.0", - "hound", - "lewton", - "minimp3", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "serde" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" - -[[package]] -name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - -[[package]] -name = "slice-deque" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25" -dependencies = [ - "libc", - "mach", - "winapi", -] - -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - -[[package]] -name = "stdweb" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid", -] - -[[package]] -name = "syn" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - -[[package]] -name = "thiserror" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", -] - -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "unicode-ident" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" - -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" -dependencies = [ - "same-file", - "winapi", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasm-bindgen" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" -dependencies = [ - "quote 1.0.21", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.100", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" - -[[package]] -name = "web-sys" -version = "0.3.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[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-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -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-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[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_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_i686_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[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_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" diff --git a/audio-logger/Cargo.toml b/audio-logger/Cargo.toml deleted file mode 100644 index 4b7b6ab..0000000 --- a/audio-logger/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "audio" -version = "0.1.0" -edition = "2021" - -[dependencies] -clap = { url = "https://github.com/clap-rs/clap", features = ["derive"] } -cpal= { version = "0.13.5", features = ["jack"] } -anyhow = "1.0.61" -hound = "3.4.0" -chrono = "0.4.22" -ctrlc = "3.2.3" -rodio = "0.16.0" - -[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))'.dependencies] -alsa = "0.6" -nix = "0.23" -libc = "0.2.65" -parking_lot = "0.12" -jack = { version = "0.9", optional = true } \ No newline at end of file diff --git a/audio-logger/Makefile b/audio-logger/Makefile deleted file mode 100644 index aba5ce7..0000000 --- a/audio-logger/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -all: - cargo build --release - -test: all - mkdir -p recordings - bash run_test.sh - -clean: - cargo clean - -fclean: clean - rm -rf recordings - -re: fclean all - -.PHONY: all clean fclean re test diff --git a/audio-logger/README.md b/audio-logger/README.md deleted file mode 100644 index 5578099..0000000 --- a/audio-logger/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Audio Logger - -CLI-tool for recording audio in a Linux environment. - -## Usage - -```bash - -USAGE: - audio-logger [OPTIONS] --name - -ARGS: - Host API to use [possible values: alsa, jack] - -OPTIONS: - -b, --batch-recording (optional) Will record in [SECONDS] batches - --buffer-size Buffer size in frames - --channels Channels to record - -h, --help Print help information - -n, --name Filename will be `[NAME]-yyyy-mm-dd-H:M:S.wav` - -o, --output Path to save the file(s) - --print-configs Output the available devices and their configurations - --sample-rate Sample rate in Hz (default = 44,000Hz) - -``` - -## Testing - -Use the Makefile commands to build the project and run a simple test. diff --git a/audio-logger/run_test.sh b/audio-logger/run_test.sh deleted file mode 100644 index a4fdc59..0000000 --- a/audio-logger/run_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -target/release/audio rec \ - --name test \ - --output recordings/ \ - --batch-recording 3 \ - --sample-rate 44100 \ - --channels 2 \ - --buffer-size 1024 \ - alsa \ diff --git a/audio-logger/src/cli.rs b/audio-logger/src/cli.rs deleted file mode 100644 index 0832a28..0000000 --- a/audio-logger/src/cli.rs +++ /dev/null @@ -1,100 +0,0 @@ -use clap::{Parser, ValueEnum, Subcommand}; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] -pub enum Hosts { - Alsa, - Jack, - CoreAudio, - Asio, -} - -#[derive(Subcommand)] -#[clap(about = "A tool to record audio on Linux using the command line.")] -pub enum Commands { - /// Record audio either continously or in batches (in case a possible - /// interruption is an issue) - Rec(Rec), - /// Play audio from a .wav file - Play(Play), - /// Merge audio resulting from a batch recording into a single file - Merge(Merge), - /// Get reports of system's audio resources - Info(Info), -} - -#[derive(Parser, Debug)] -#[clap(about = "Merge audio resulting from a batch recording into a single - file. -")] -pub struct Merge { - /// The directory to look for files to merge. - #[clap(short, long, default_value = "./", required = true)] - pub input: std::path::PathBuf, - - /// The directory to save the merged file to. - #[clap(short, long, default_value = "./")] - pub output: std::path::PathBuf, -} - -#[derive(Parser, Debug)] -#[clap(about = "Record audio either continously or in batches (in case a - possible interruption is an issue). -")] -pub struct Rec { - - /// Filename will be `[NAME]-yyyy-mm-dd-H:M:S.wav` - #[clap(required = true, short, long)] - pub name: String, - - /// Path to save the file(s) - #[clap(long, short, value_parser, value_name = "PATH", value_hint = clap::ValueHint::DirPath)] - pub output: Option, - - /// (optional) Will record in [SECONDS] batches - #[clap(short, long, value_name = "SECONDS")] - pub batch_recording: Option, - - /// (optional) Will record for a total of [SECONDS] - #[clap(short, long, value_name = "MAX_SECONDS")] - pub max_seconds: Option, - - /// Host API to use - #[clap(value_enum)] - pub host: Hosts, - - /// Sample rate in Hz (default = 44,000Hz) - #[clap(long)] - pub sample_rate: Option, - - /// Channels to record - #[clap(long, value_name = "CHANNELS")] - pub channels: Option, - - /// Buffer size in frames - #[clap(long, value_name = "FRAMES")] - pub buffer_size: Option, -} -#[derive(Parser, Debug)] -#[clap(about = "Play audio from a .wav file. -")] -pub struct Play { - /// Path to the file to play - #[clap(value_parser, value_name = "PATH", value_hint = clap::ValueHint::FilePath)] - pub input: std::path::PathBuf, -} - -#[derive(Parser, Debug)] -#[clap(about = "Get reports of system's audio resources.")] -pub struct Info { - /// Output the available devices and their configurations - #[clap(long)] - pub print_configs: bool, -} - -#[derive(Parser)] -#[clap(author, version, about, long_about = None)] -#[clap(propagate_version = true)] -pub struct Cli { - #[clap(subcommand)] - pub command: Commands, -} \ No newline at end of file diff --git a/audio-logger/src/constants.rs b/audio-logger/src/constants.rs deleted file mode 100644 index 7fa1495..0000000 --- a/audio-logger/src/constants.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub const DEFAULT_SAMPLE_RATE: u32 = 44100; -pub const DEFAULT_CHANNEL_COUNT: u16 = 1; -pub const DEFAULT_BUFFER_SIZE: u32 = 1024; -pub const ALLOWED_SAMPLE_RATES: [u32; 6] = [44100, 48000, 88200, 96000, 176400, 192000]; -pub const MAX_CHANNEL_COUNT: u16 = 2; -pub const MIN_BUFFER_SIZE: usize = 64; -pub const MAX_BUFFER_SIZE: usize = 8192; \ No newline at end of file diff --git a/audio-logger/src/getters.rs b/audio-logger/src/getters.rs deleted file mode 100644 index e417977..0000000 --- a/audio-logger/src/getters.rs +++ /dev/null @@ -1,113 +0,0 @@ -use super::*; -use cpal::{ - StreamConfig, - SupportedStreamConfig, - Device, - HostId, - Host, - SampleRate, - BufferSize, - traits::{DeviceTrait, HostTrait}, -}; -use hound::WavSpec; -use std::path::PathBuf; -use chrono::*; -use anyhow::{Error, Result, anyhow}; - -/// # Get Host -/// -/// Returns the host with the given id if it's available. -pub fn get_host(host: HostId) -> Result { - Ok(cpal::host_from_id(cpal::available_hosts() - .into_iter() - .find(|id| *id == host) - .ok_or(anyhow!("Requested host device not found"))? - )?) -} - -/// # Get Device -/// -/// Returns the default input device for the host if it's available. -pub fn get_device(host: Host) -> Result { - Ok(host.default_input_device() - .ok_or(anyhow!("No input device available. Try running `jackd -R -d alsa -d hw:0`", - ))?) -} - -/// # Get Default Config -/// -/// Get the default config for the given device. -pub fn get_default_config(device: &Device) -> Result { - Ok(device.default_input_config()?) -} - -/// # Get User Config -/// -/// Overrides certain fields of the default stream config with the user's config. -/// -/// sample_rate: The user's sample rate if it is supported by the device, otherwise the default sample rate. -/// channels: The user's number of channels if it is supported by the device, otherwise the default number of channels. -/// buffer_size: The user's buffer size if it is supported by the device, otherwise the default buffer size. -pub fn get_user_config(sample_rate: u32, channels: u16, buffer_size: u32) -> Result { - if !ALLOWED_SAMPLE_RATES.contains(&sample_rate) { - return Err(anyhow!( - "Sample rate {} is not supported. Allowed sample rates: {:?}", - sample_rate, - ALLOWED_SAMPLE_RATES - )); - } - if !(channels >= 1 && channels <= MAX_CHANNEL_COUNT) { - return Err(anyhow!( - "Channel count {} is not supported. Allowed channel counts: 1-{}", - channels, - MAX_CHANNEL_COUNT - )); - } - if !(buffer_size >= MIN_BUFFER_SIZE as u32 && buffer_size <= MAX_BUFFER_SIZE as u32) { - return Err(anyhow!( - "Buffer size {} is not supported. Allowed buffer sizes: {}-{}", - buffer_size, - MIN_BUFFER_SIZE, - MAX_BUFFER_SIZE - )); - } - Ok(StreamConfig { - channels, - sample_rate: SampleRate(sample_rate), - buffer_size: BufferSize::Fixed(buffer_size), - }) -} - -/// # Get WAV Spec -/// -/// Get the WAV spec for the given stream config. -pub fn get_wav_spec(default_config: &SupportedStreamConfig, user_config: &StreamConfig) -> Result { - Ok(WavSpec { - channels: user_config.channels, - sample_rate: user_config.sample_rate.0, - bits_per_sample: (default_config.sample_format().sample_size() * 8) as u16, - sample_format: match default_config.sample_format() { - cpal::SampleFormat::U16 => hound::SampleFormat::Int, - cpal::SampleFormat::I16 => hound::SampleFormat::Int, - cpal::SampleFormat::F32 => hound::SampleFormat::Float, - }, - }) -} - -pub fn get_date_time_string() -> String { - let now: DateTime = Local::now(); - format!( - "{:02}-{:02}-{:02}_{:02}:{:02}:{:02}", - now.year(), now.month(), now.day(), - now.hour(), now.minute(), now.second(), - ) -} -/// # Get Filename -/// -/// Get the filename for the current recording according to the given format, -/// the current date and time, and the name prefix. -pub fn get_filename(name: &str, path: &PathBuf) -> String { - let mut filename = path.clone(); - filename.push(format!("{}_{}.wav", get_date_time_string(), name)); - filename.to_str().unwrap().to_string() -} diff --git a/audio-logger/src/input_handling.rs b/audio-logger/src/input_handling.rs deleted file mode 100644 index 129c3b1..0000000 --- a/audio-logger/src/input_handling.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::*; -use std::sync::{ - Arc, - Mutex, - Condvar, - atomic::{AtomicBool, Ordering} -}; - -type StreamInterrupt = Arc<(Mutex, Condvar)>; -type BatchInterrupt= Arc; - -/// # Interrupts Handling -/// -/// The `Recorder` struct has two interrupt mechanisms: -/// -/// 1. `stream_interrupt` is used to interrupt the stream when the user presses `ctrl+c`. -/// 2. `batch_interrupt` is used to interrupt the batch recording when the user presses `ctrl+c`. -#[derive(Clone)] -pub struct InterruptHandles { - batch_interrupt: BatchInterrupt, - stream_interrupt: StreamInterrupt, - max_seconds: Option, -} - -impl InterruptHandles { - pub fn new(max_seconds: Option) -> Result { - let stream_interrupt = Arc::new((Mutex::new(false), Condvar::new())); - let stream_interrupt_cloned = stream_interrupt.clone(); - - let batch_interrupt = Arc::new(AtomicBool::new(false)); - let batch_interrupt_cloned = batch_interrupt.clone(); - - ctrlc::set_handler(move || { - // Set batch interrupt to true - batch_interrupt_cloned.store(true, Ordering::SeqCst); - - // Release the stream - let &(ref lock, ref cvar) = &*stream_interrupt_cloned; - let mut started = lock.lock().unwrap(); - *started = true; - cvar.notify_one(); - })?; - Ok(Self { - batch_interrupt, - stream_interrupt, - max_seconds, - }) - } - - pub fn stream_wait(&self) { - let &(ref lock, ref cvar) = &*self.stream_interrupt; - let mut started = lock.lock().unwrap(); - let now = std::time::Instant::now(); - while !*started { - match self.max_seconds { - Some(secs) => { - if now.elapsed().as_secs() >= secs { - break; - } - } - None => (), - } - started = cvar.wait(started).unwrap(); - } - } - - pub fn batch_is_running(&self) -> bool { - !self.batch_interrupt.load(Ordering::SeqCst) - } -} \ No newline at end of file diff --git a/audio-logger/src/main.rs b/audio-logger/src/main.rs deleted file mode 100644 index 048bd68..0000000 --- a/audio-logger/src/main.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! # Main -mod cli; -mod recorder; -mod print_configs; -mod getters; -mod input_handling; -mod merge; -mod constants; -mod play; - -use print_configs::*; -use cli::*; -use merge::*; -use recorder::*; -use constants::*; -use getters::*; -use input_handling::*; -use play::*; -use anyhow::{Error, Result, anyhow}; - -use clap::Parser; - -fn main() -> Result<(), Error> { - let cli = Cli::parse(); - - match &cli.command { - Commands::Rec(args) => { - record(&args)?; - }, - Commands::Play(args) => { - play(&args.input)?; - }, - Commands::Info(args) => { - if args.print_configs { - print_configs()?; - } - }, - Commands::Merge(args) => { - merge_wavs(&args.input, &args.output)?; - } - } - Ok(()) -} diff --git a/audio-logger/src/merge.rs b/audio-logger/src/merge.rs deleted file mode 100644 index bebc093..0000000 --- a/audio-logger/src/merge.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hound::{WavReader, WavWriter}; -use anyhow::{Result, Error}; - -pub fn merge_wavs(input: &std::path::PathBuf, output: &std::path::PathBuf) -> Result<(), Error> { - // Read files from input directory - let mut files = std::fs::read_dir(input)? - .filter_map(|entry| entry.ok()) - .filter(|entry| entry.file_type().ok().map(|t| t.is_file()).unwrap_or(false)) - .filter(|entry| entry.path().extension().unwrap_or_default() == "wav") - .collect::>(); - - // Sort files by name - files.sort_by(|a, b| a.file_name().cmp(&b.file_name())); - - // Use the name of the first file as the name of the output file - let output_name = files.first().unwrap().file_name(); - let output_name = output_name.to_str().unwrap(); - - // Get wav spec from file - let spec = WavReader::open(files.first().unwrap().path())?.spec(); - let mut writer = WavWriter::create(output.join(output_name), spec)?; - - match spec.sample_format { - hound::SampleFormat::Float => { - for file in files { - let mut reader = WavReader::open(file.path())?; - for sample in reader.samples::() { - writer.write_sample(sample?)?; - } - } - }, - hound::SampleFormat::Int => { - for file in files { - let mut reader = WavReader::open(file.path())?; - for sample in reader.samples::() { - writer.write_sample(sample?)?; - } - } - }, - } - writer.finalize()?; - Ok(()) -} diff --git a/audio-logger/src/play.rs b/audio-logger/src/play.rs deleted file mode 100644 index 0115156..0000000 --- a/audio-logger/src/play.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Play audio from a .wav file. - -use anyhow::{Error, Result}; -use rodio::{Decoder, OutputStream, Sink}; - -pub fn play(path: &std::path::PathBuf) -> Result<(), Error> { - let file = std::fs::File::open(path)?; - let source = Decoder::new(file).unwrap(); - let (_stream, stream_handle) = OutputStream::try_default()?; - let sink = Sink::try_new(&stream_handle)?; - sink.append(source); - sink.sleep_until_end(); - Ok(()) -} \ No newline at end of file diff --git a/audio-logger/src/print_configs.rs b/audio-logger/src/print_configs.rs deleted file mode 100644 index 45b0fb5..0000000 --- a/audio-logger/src/print_configs.rs +++ /dev/null @@ -1,85 +0,0 @@ -use cpal::traits::{DeviceTrait, HostTrait}; - -// pub fn print_available_hosts() -> Result<(), anyhow::Error> { -// let hosts = cpal::available_hosts(); -// println!("Available hosts:"); -// for host in hosts { -// println!(" {}", host.name()); -// } -// Ok(()) -// } - -// pub fn print_supported_hosts() { -// println!("Supported hosts:"); -// println!("{:?}", cpal::ALL_HOSTS); -// } - -pub fn print_configs() -> Result<(), anyhow::Error> { - println!("Supported hosts:\n {:?}", cpal::ALL_HOSTS); - let available_hosts = cpal::available_hosts(); - println!("Available hosts:\n {:?}", available_hosts); - - for host_id in available_hosts { - println!("{}", host_id.name()); - let host = cpal::host_from_id(host_id)?; - - let default_in = host.default_input_device().map(|e| e.name().unwrap()); - let default_out = host.default_output_device().map(|e| e.name().unwrap()); - println!(" Default Input Device:\n {:?}", default_in); - println!(" Default Output Device:\n {:?}", default_out); - - let devices = host.devices()?; - println!(" Devices: "); - for (device_index, device) in devices.enumerate() { - println!(" {}. \"{}\"", device_index + 1, device.name()?); - - // Input configs - if let Ok(conf) = device.default_input_config() { - println!(" Default input stream config:\n {:?}", conf); - } - let input_configs = match device.supported_input_configs() { - Ok(f) => f.collect(), - Err(e) => { - println!(" Error getting supported input configs: {:?}", e); - Vec::new() - } - }; - if !input_configs.is_empty() { - println!(" All supported input stream configs:"); - for (config_index, config) in input_configs.into_iter().enumerate() { - println!( - " {}.{}. {:?}", - device_index + 1, - config_index + 1, - config - ); - } - } - - // Output configs - if let Ok(conf) = device.default_output_config() { - println!(" Default output stream config:\n {:?}", conf); - } - let output_configs = match device.supported_output_configs() { - Ok(f) => f.collect(), - Err(e) => { - println!(" Error getting supported output configs: {:?}", e); - Vec::new() - } - }; - if !output_configs.is_empty() { - println!(" All supported output stream configs:"); - for (config_index, config) in output_configs.into_iter().enumerate() { - println!( - " {}.{}. {:?}", - device_index + 1, - config_index + 1, - config - ); - } - } - } - } - - Ok(()) -} \ No newline at end of file diff --git a/audio-logger/src/recorder.rs b/audio-logger/src/recorder.rs deleted file mode 100644 index 4414e71..0000000 --- a/audio-logger/src/recorder.rs +++ /dev/null @@ -1,246 +0,0 @@ -use super::*; -use cpal::{ - StreamConfig, - SupportedStreamConfig, - Device, - HostId, - Stream, - traits::{DeviceTrait, StreamTrait}, -}; -use std::{ - fs::File, - io::BufWriter, - path::{PathBuf, Path}, - sync::{Arc, Mutex}, -}; -use anyhow::Error; - -type WriteHandle = Arc>>>>; - -pub struct Recorder { - writer: WriteHandle, - interrupt_handles: InterruptHandles, - default_config: SupportedStreamConfig, - user_config: StreamConfig, - device: Device, - spec: hound::WavSpec, - name: String, - path: PathBuf, - current_file: String, - max_seconds: Option, -} - -/// # Recorder -/// -/// The `Recorder` struct is used to record audio. -/// -/// Use `init()` to initialize the recorder, `record()` to start a continuous recording, -/// and `rec_secs()` to record for a given number of seconds. The Recorder does not -/// need to be reinitialized after a recording is stopped. Calling `record()` or -/// `rec_secs()` again will start a new recording with a new filename according to -/// the time and date. -impl Recorder { - - /// # Init - /// - /// Initializes the recorder with the given host, sample rate, channel count, and buffer size. - pub fn init( - name: String, - path: PathBuf, - host: HostId, - sample_rate: u32, - channels: u16, - buffer_size: u32, - max_seconds: Option, - ) -> Result { - - // Create interrupt handles to be used by the stream or batch loop. - let interrupt_handles = InterruptHandles::new(max_seconds)?; - - // Select requested host. - let host = get_host(host)?; - - // Set up the input device and stream with the default input config. - let device = get_device(host)?; - - // Get default config for the device. - let default_config = get_default_config(&device)?; - - // Override certain fields of the default stream config with the user's config. - let user_config = get_user_config(sample_rate, channels, buffer_size)?; - - // Get the hound WAV spec for the user's config. - let spec = get_wav_spec(&default_config, &user_config)?; - - Ok(Self { - writer: Arc::new(Mutex::new(None)), - interrupt_handles, - default_config, - user_config, - device, - spec, - name, - path, - current_file: "".to_string(), - max_seconds, - }) - } - - fn init_writer(&mut self) -> Result<(), Error> { - let filename = get_filename(&self.name, &self.path); - self.current_file = filename.clone(); - self.writer = Arc::new(Mutex::new(Some(hound::WavWriter::create(filename, self.spec)?))); - Ok(()) - } - - fn create_stream(&self) -> Result { - let writer = self.writer.clone(); - let config = self.user_config.clone(); - let err_fn = |err| { eprintln!("{}: An error occurred on stream: {}", get_date_time_string(), err); }; - - let stream = match self.default_config.sample_format() { - cpal::SampleFormat::F32 => self.device.build_input_stream( - &config.into(), - move |data, _: &_| write_input_data::(data, &writer), - err_fn, - )?, - cpal::SampleFormat::I16 => self.device.build_input_stream( - &config.into(), - move |data, _: &_| write_input_data::(data, &writer), - err_fn, - )?, - cpal::SampleFormat::U16 => self.device.build_input_stream( - &config.into(), - move |data, _: &_| write_input_data::(data, &writer), - err_fn, - )?, - }; - Ok(stream) - } - - /// # Record - /// - /// Start a continuous recording. The recording will be stopped when the - /// user presses `Ctrl+C`. - pub fn record(&mut self) -> Result<(), Error> { - self.init_writer()?; - let stream = self.create_stream()?; - stream.play()?; - println!("REC: {}", self.current_file); - self.interrupt_handles.stream_wait(); - drop(stream); - self.writer.lock().unwrap().take().unwrap().finalize()?; - println!("STOP: {}", self.current_file); - Ok(()) - } - - /// # Record Seconds - /// - /// Record for a given number of seconds or until the user presses `Ctrl+C`. - /// Current batch is finished before stopping. - pub fn record_secs(&mut self, secs: u64) -> Result<(), Error> { - self.init_writer()?; - let stream = self.create_stream()?; - stream.play()?; - let date_time = get_date_time_string(); - println!("REC[{}]: {}", date_time, self.current_file); - let now = std::time::Instant::now(); - while self.interrupt_handles.batch_is_running() { - std::thread::sleep(std::time::Duration::from_millis(1)); - if now.elapsed().as_secs() >= secs { - break; - } - } - drop(stream); - let writer = self.writer.clone(); - let current_file = self.current_file.clone(); - std::thread::spawn(move || { - writer.lock().unwrap().take().unwrap().finalize().unwrap(); - // Print STOP and the time and date - let date_time = get_date_time_string(); - println!("STOP[{}]: {}", date_time, current_file); - }); - Ok(()) - } -} - -fn write_input_data(input: &[T], writer: &WriteHandle) -where - T: cpal::Sample, - U: cpal::Sample + hound::Sample, -{ - if let Ok(mut guard) = writer.try_lock() { - if let Some(writer) = guard.as_mut() { - for &sample in input.iter() { - let sample: U = cpal::Sample::from(&sample); - writer.write_sample(sample).ok(); - } - } - } -} - -fn batch_recording(rec: &mut Recorder, secs: u64) -> Result<(), Error> { - let now = std::time::Instant::now(); - while rec.interrupt_handles.batch_is_running() { - match rec.max_seconds { - Some(max_secs) => { - if now.elapsed().as_secs() >= max_secs { - break; - } - } - None => {} - } - rec.record_secs(secs)?; - } - Ok(()) -} - -fn continuous_recording(rec: &mut Recorder) -> Result<(), Error> { - rec.record()?; - Ok(()) -} - -#[cfg(target_os = "linux")] -fn match_host_platform(host: Hosts) -> Result { - match host { - Hosts::Alsa => Ok(cpal::HostId::Alsa), - Hosts::Jack => Ok(cpal::HostId::Jack), - _ => Err(anyhow!("Host not supported on Linux.")), - } -} - -#[cfg(target_os = "macos")] -fn match_host_platform(host: Hosts) -> Result { - match host { - Hosts::CoreAudio => Ok(cpal::HostId::CoreAudio), - _ => Err(anyhow!("Host not supported on macOS.")), - } -} - -#[cfg(target_os = "windows")] -fn match_host_platform(host: Hosts) -> Result { - match host { - Hosts::Asio => Ok(cpal::HostId::Asio), - _ => Err(anyhow!("Host not supported on Windows.")), - } -} - -pub fn record(args: &Rec) -> Result<(), Error> { - let mut recorder = Recorder::init( - args.name.clone(), - match args.output.clone() { - Some(path) => path, - None => Path::new("./").to_path_buf(), - }, - match_host_platform(args.host)?, - args.sample_rate.unwrap_or(DEFAULT_SAMPLE_RATE), - args.channels.unwrap_or(DEFAULT_CHANNEL_COUNT), - args.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE), - args.max_seconds, - )?; - - match args.batch_recording { - Some(seconds) => batch_recording(&mut recorder, seconds), - None => continuous_recording(&mut recorder), - } -} diff --git a/depth-logger/record-depth.py b/depth-logger/record-depth.py deleted file mode 100644 index 284277d..0000000 --- a/depth-logger/record-depth.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/python3 - -import argparse -import time -import board -import busio -import adafruit_ads1x15.ads1015 as ADS -from adafruit_extended_bus import ExtendedI2C as I2C -from adafruit_ads1x15.analog_in import AnalogIn - -parser = argparse.ArgumentParser(description='GPS Logger') -parser.add_argument('-o', '--output', help='Output directory', required=True) -parser.add_argument('-i', '--interval', help='Interval in seconds', required=False) -parser.add_argument('-b', '--bus', help='Custom i2c bus to use', required=False) - -args = parser.parse_args() - -# Create the I2C bus -if args.bus: - i2c_bus = args.bus - i2c = I2C(i2c_bus) -else: - i2c = busio.I2C(board.SCL, board.SDA) - -# Create the ADC object using the I2C bus -ads = ADS.ADS1015(i2c) - -# Create a single-ended input on channel 1 -depthS = AnalogIn(ads, ADS.P1) - -# Create single-ended input on channel 0 -# tmp36 = AnalogIn(ads, ADS.P0) - -# Subtract the offset from the sensor voltage -# and convert chan.voltage * (1 degree C / 0.01V) = Degrees Celcius -# temperatureC = (tmp36.voltage - 0.5) / 0.01 - -# File to write down the results -filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_depth_data.csv" - -interval = int(args.interval) if args.interval else 5 - -#Attempting to round the figure to a more intelligible figure -#rounddepth = round(depthM, ndigits) -#psi = depthS.voltage * 104.1666667 - 75 -#bar = psi * 14.503773800722 - -with open(filename, "w", 1) as f: - print(f"Writing pressure/depth output to {filename}, interval {interval} seconds", flush=True) - f.write("time and date, Voltage of depth sensor (V), Depth (m)\n") - - try: - while True: - voltage = depthS.voltage - depthM = ((voltage * 31.848) - 22.93) - rounddepth = round(depthM, 2) - roundvolts = round(voltage, 3) - # roundtemp = round(temperatureC, 2) - - print((str(voltage) + " V ") + (str(depthM) + " m ") + (str(roundvolts) + " V ") + (str(rounddepth) + " m"), flush=True) - - f.write(time.strftime("%Y-%m-%dT%H:%M:%S") + "," + str(roundvolts) + "," + str(rounddepth) + "\n") - - time.sleep(interval) - - except (KeyboardInterrupt, SystemExit): # when you press ctrl+c - print("Exiting depth recording.", flush=True) diff --git a/depth-logger/requirements.txt b/depth-logger/requirements.txt deleted file mode 100644 index c652ba9..0000000 --- a/depth-logger/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -Adafruit-Blinka==8.5.0 -adafruit-circuitpython-ads1x15==2.2.21 -adafruit-extended-bus==1.0.2 \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8a72111 --- /dev/null +++ b/flake.lock @@ -0,0 +1,215 @@ +{ + "nodes": { + "deploy-rs": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1694158470, + "narHash": "sha256-yWx9eBDHt6WR3gr65+J85KreHdMypty/P6yM35tIYYM=", + "owner": "serokell", + "repo": "deploy-rs", + "rev": "d0cfc042eba92eb206611c9e8784d41a2c053bab", + "type": "github" + }, + "original": { + "owner": "serokell", + "repo": "deploy-rs", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "hydrophonitor-gps": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1694371631, + "narHash": "sha256-o2lx75F0VnFnBKajbVbEUuQRcbcSHdCxjUVjdaAoAn8=", + "owner": "nordic-dev-net", + "repo": "hydrophonitor-gps", + "rev": "d13bb78ce2d16b842f0be802f9d669ba32a35c3d", + "type": "github" + }, + "original": { + "owner": "nordic-dev-net", + "repo": "hydrophonitor-gps", + "type": "github" + } + }, + "nixos-hardware": { + "locked": { + "lastModified": 1693718952, + "narHash": "sha256-+nGdJlgTk0MPN7NygopipmyylVuAVi7OItIwTlwtGnw=", + "owner": "NixOS", + "repo": "nixos-hardware", + "rev": "793de77d9f83418b428e8ba70d1e42c6507d0d35", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixos-hardware", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1671417167, + "narHash": "sha256-JkHam6WQOwZN1t2C2sbp1TqMv3TVRjzrdoejqfefwrM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bb31220cca6d044baa6dc2715b07497a2a7c4bc7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1694183432, + "narHash": "sha256-YyPGNapgZNNj51ylQMw9lAgvxtM2ai1HZVUu3GS8Fng=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "db9208ab987cdeeedf78ad9b4cf3c55f5ebd269b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1694183432, + "narHash": "sha256-YyPGNapgZNNj51ylQMw9lAgvxtM2ai1HZVUu3GS8Fng=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "db9208ab987cdeeedf78ad9b4cf3c55f5ebd269b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "deploy-rs": "deploy-rs", + "flake-utils": "flake-utils", + "hydrophonitor-gps": "hydrophonitor-gps", + "nixos-hardware": "nixos-hardware", + "nixpkgs": "nixpkgs_3" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9d32021 --- /dev/null +++ b/flake.nix @@ -0,0 +1,94 @@ +{ + description = "NixOS Raspberry Pi configuration flake"; + + inputs = { + nixpkgs = { + url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + flake-utils.url = "github:numtide/flake-utils"; + deploy-rs.url = "github:serokell/deploy-rs"; + hydrophonitor-gps.url = "github:nordic-dev-net/hydrophonitor-gps"; + }; + outputs = { + self, + nixpkgs, + nixos-hardware, + flake-utils, + deploy-rs, + hydrophonitor-gps, + ... + }: let + forEachSystem = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"]; + forEachPkgs = f: forEachSystem (sys: f (nixpkgs.legacyPackages.${sys})); + system = "aarch64-linux"; + pkgs = import nixpkgs { + inherit system; + config = {allowUnfree = true;}; + overlays = [ + (final: super: { + makeModulesClosure = x: + super.makeModulesClosure (x // {allowMissing = true;}); + }) + ]; + }; + in { + systems = { + raspberry-pi-4 = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + specialArgs = {inherit pkgs;}; + modules = [ + ./targets/raspberry-pi-4 + ./modules/audio-recorder.nix + ./modules/real-time-clock/i2c-rtc.nix + ./modules/shutdown-button/service.nix + nixos-hardware.nixosModules.raspberry-pi-4 + hydrophonitor-gps.nixosModules.hydrophonitor-gps + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + ]; + }; + + raspberry-pi-3 = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + specialArgs = {inherit pkgs;}; + modules = [ + ./targets/raspberry-pi-3 + ./modules/audio-recorder.nix + ./modules/real-time-clock/i2c-rtc.nix + hydrophonitor-gps.nixosModules.hydrophonitor-gps + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + ]; + }; + }; + + deploy.nodes = { + raspberry-pi-4 = { + hostname = "192.168.1.76"; + profiles.system = { + sshUser = "kaskelotti"; + sshOpts = ["-t"]; + magicRollback = false; + path = + deploy-rs.lib.aarch64-linux.activate.nixos + self.systems.raspberry-pi-4; + user = "root"; + }; + }; + + raspberry-pi-3 = { + hostname = "192.168.1.117"; + profiles.system = { + sshUser = "kaskelotti"; + sshOpts = ["-t"]; + magicRollback = false; + path = + deploy-rs.lib.aarch64-linux.activate.nixos + self.systems.raspberry-pi-3; + user = "root"; + }; + }; + }; + + formatter = forEachPkgs (pkgs: pkgs.alejandra); + }; +} diff --git a/flash.sh b/flash.sh new file mode 100644 index 0000000..1988f24 --- /dev/null +++ b/flash.sh @@ -0,0 +1,8 @@ +# Flash image to sd-card +# +# Check sd-card device name with lsblk + +SDCARD=$1 +IMAGE=$2 + +sudo dd if=${IMAGE} of=/dev/${SDCARD} status=progress diff --git a/gps-logger/record-gps.py b/gps-logger/record-gps.py deleted file mode 100644 index 9a09409..0000000 --- a/gps-logger/record-gps.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/python3 - -import gpsd -import time -import argparse - -parser = argparse.ArgumentParser(description='GPS Logger') -parser.add_argument('-o', '--output', help='Output directory', required=True) -parser.add_argument('-i', '--interval', help='Interval in seconds', required=False) - -args = parser.parse_args() - -filename = args.output + "/" + time.strftime("%Y-%m-%dT%H-%M-%S") + "_GPS_data.csv" - -interval = int(args.interval) if args.interval else 5 - -with open(filename, "w", 1) as f: - gpsd.connect() - - print(f"Writing GPS output to {filename}, interval {interval} seconds", flush=True) - f.write("system_time,gps_time_utc,latitude,longitude,speed,sats_in_view\n") - - while True: - try: - packet = gpsd.get_current() - gps_time_utc = str(packet.time) if packet.mode >= 2 else "-" - lat = str(packet.lat) if packet.mode >= 2 else "0.0" - lon = str(packet.lon) if packet.mode >= 2 else "0.0" - speed = str(packet.hspeed) if packet.mode >= 2 else "0.0" - sats = str(packet.sats) - system_time = time.strftime("%Y-%m-%dT%H-%M-%S") - f.write(f"{system_time},{gps_time_utc},{lat},{lon},{speed},{sats}\n") - except (KeyboardInterrupt, SystemExit): # when you press ctrl+c - print("Exiting GPS recording.", flush=True) - break - except Exception as e: - print(f"GPS error: {e}, trying again...", flush=True) - - time.sleep(interval) diff --git a/gps-logger/requirements.txt b/gps-logger/requirements.txt deleted file mode 100644 index 2a628b2..0000000 --- a/gps-logger/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -gpsd-py3==0.3.0 \ No newline at end of file diff --git a/hydrophonitor-config.txt b/hydrophonitor-config.txt deleted file mode 100644 index efff13c..0000000 --- a/hydrophonitor-config.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Audio - -SAMPLE_RATE=44100 -CHANNELS=2 -BITRATE=192k - -# in seconds -BATCH_RECORD_LENGTH=60 - -# GPS - -# in seconds -GPS_INTERVAL=5 - -# Depth - -# in seconds -DEPTH_INTERVAL=5 - -# Output location - -# TODO -#TRY_MOUNT_SSD=true -OUTPUT_PATH=/home/pi/data - -HOME_PATH=/home/pi -DEFAULT_OUTPUT_PATH=/home/pi/recordings diff --git a/modules/audio-recorder.nix b/modules/audio-recorder.nix new file mode 100644 index 0000000..cd80487 --- /dev/null +++ b/modules/audio-recorder.nix @@ -0,0 +1,70 @@ +{ + config, + pkgs, + lib, + ... +}: { + options = with lib; { + services.audio-recorder = { + enable = mkEnableOption "Whether to enable the audio recording service."; + + output-folder = mkOption { + type = types.str; + default = "/output/audio"; + description = "The folder to save recordings to."; + }; + + sample-rate = mkOption { + type = types.int; + default = 44100; + description = "The sample rate to use for recording."; + }; + + sample-format = mkOption { + type = types.str; + default = "S32_LE"; + description = "The sample format to use for recording."; + }; + + channels = mkOption { + type = types.int; + default = 2; + description = "The amount of channels to use."; + }; + + max-file-time-secs = mkOption { + type = types.int; + default = 600; + description = "The maximum length of a recording in seconds."; + }; + }; + }; + + config = lib.mkIf config.services.audio-recorder.enable { + systemd.services.audio-recorder = { + description = "Audio Recording Service"; + wantedBy = ["multi-user.target"]; + script = '' + #!/usr/bin/env bash + set -x + ${pkgs.coreutils}/bin/mkdir -p ${config.services.audio-recorder.output-folder} + ${pkgs.alsaUtils}/bin/arecord -l + CARD_ID=$(${pkgs.alsaUtils}/bin/arecord -l | grep "USB Audio" | grep -oP '(?<=card )\d') + DEVICE_ID=$(${pkgs.alsaUtils}/bin/arecord -l | grep "USB Audio" | grep -oP '(?<=device )\d') + ${pkgs.alsaUtils}/bin/arecord \ + --device hw:$CARD_ID,$DEVICE_ID \ + --format ${config.services.audio-recorder.sample-format} \ + --max-file-time ${toString config.services.audio-recorder.max-file-time-secs} \ + --rate ${toString config.services.audio-recorder.sample-rate} \ + --channels ${toString config.services.audio-recorder.channels} \ + --use-strftime \ + ${config.services.audio-recorder.output-folder}/%Y-%m-%d_%H-%M-%S.wav + ''; + serviceConfig = { + User = "root"; # Replace with appropriate user + Restart = "always"; + }; + startLimitIntervalSec = 0; + }; + }; +} diff --git a/modules/real-time-clock/i2c-rtc.nix b/modules/real-time-clock/i2c-rtc.nix new file mode 100644 index 0000000..c4c05ba --- /dev/null +++ b/modules/real-time-clock/i2c-rtc.nix @@ -0,0 +1,49 @@ +{ + config, + pkgs, + lib, + ... +}: { + options = with lib; { + services.i2c-rtc-start = { + enable = mkEnableOption "Whether to enable the audio recording service."; + + i2c-bus = mkOption { + type = types.int; + default = 1; + description = "The I2C bus to use."; + }; + }; + }; + + config = lib.mkIf config.services.i2c-rtc-start.enable { + systemd.services.i2c-rtc-start = { + description = "RTC start service; reads the RTC and sets the system time from it"; + wantedBy = ["multi-user.target"]; + requires = ["systemd-modules-load.service"]; + after = ["systemd-modules-load.service"]; + script = '' + #!/usr/bin/env bash + set -x + # Remove the i2c device if it already exists + if [ -e /sys/class/i2c-adapter/i2c-${toString config.services.i2c-rtc-start.i2c-bus}/new_device ]; then + echo "Try deleting existing i2c device" + echo 0x68 | tee /sys/class/i2c-adapter/i2c-${toString config.services.i2c-rtc-start.i2c-bus}/delete_device || true + fi + echo "Adding i2c device" + echo ds1307 0x68 | tee /sys/class/i2c-adapter/i2c-${toString config.services.i2c-rtc-start.i2c-bus}/new_device + echo "Current hwclock time:" + /run/current-system/sw/bin/hwclock -r + echo "Current system time:" + date + echo "Setting system time from hwclock" + /run/current-system/sw/bin/hwclock -s + ''; + serviceConfig = { + User = "root"; + Type = "oneshot"; + }; + startLimitIntervalSec = 0; + }; + }; +} diff --git a/modules/shutdown-button/Cargo.lock b/modules/shutdown-button/Cargo.lock new file mode 100644 index 0000000..d8cd016 --- /dev/null +++ b/modules/shutdown-button/Cargo.lock @@ -0,0 +1,41 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "rppal" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb26758c881b4837b2f4aef569e4251f75388e36b37204e1804ef429c220121c" +dependencies = [ + "lazy_static", + "libc", +] + +[[package]] +name = "rust_gpiozero" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef0e15226913de082030649dc55bb1db057ffc1c7c2b418454912a85b40523f3" +dependencies = [ + "rppal", +] + +[[package]] +name = "shutdown-button" +version = "0.1.0" +dependencies = [ + "rust_gpiozero", +] diff --git a/modules/shutdown-button/Cargo.toml b/modules/shutdown-button/Cargo.toml new file mode 100644 index 0000000..8218d0e --- /dev/null +++ b/modules/shutdown-button/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "shutdown-button" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rust_gpiozero = "^0.2" diff --git a/modules/shutdown-button/default.nix b/modules/shutdown-button/default.nix new file mode 100644 index 0000000..e57cc30 --- /dev/null +++ b/modules/shutdown-button/default.nix @@ -0,0 +1,16 @@ +{ + rustPlatform, + pkg-config, + pkgs, +}: +rustPlatform.buildRustPackage { + pname = "shutdown-button"; + version = "0.1.0"; + + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + allowBuiltinFetchGit = true; + }; +} diff --git a/modules/shutdown-button/service.nix b/modules/shutdown-button/service.nix new file mode 100644 index 0000000..3bd4d40 --- /dev/null +++ b/modules/shutdown-button/service.nix @@ -0,0 +1,43 @@ +{ + config, + pkgs, + lib, + ... +}: let + shutdownButton = pkgs.callPackage ./default.nix {}; +in { + options = { + services.shutdown-button = { + enable = lib.mkEnableOption "Whether to enable the shutdown-button service."; + + gpio-pin = lib.mkOption { + type = lib.types.int; + default = 21; + description = "GPIO pin number to which button is connected"; + }; + + shutdown-press-secs = lib.mkOption { + type = lib.types.int; + default = 1; + description = "How many seconds button must be pushed down to trigger shutdown signal"; + }; + }; + }; + + config = lib.mkIf config.services.shutdown-button.enable { + systemd.services.shutdown-button = { + description = "Shutdown button service"; + wantedBy = ["multi-user.target"]; + script = '' + #!/usr/bin/env bash + set -x + ${shutdownButton}/bin/shutdown-button --gpio-pin ${toString config.services.shutdown-button.gpio-pin} --shutdown-press-secs ${toString config.services.shutdown-button.shutdown-press-secs} + ''; + serviceConfig = { + User = "root"; # Replace with appropriate user + Restart = "always"; + }; + startLimitIntervalSec = 0; + }; + }; +} diff --git a/modules/shutdown-button/src/main.rs b/modules/shutdown-button/src/main.rs new file mode 100644 index 0000000..3492e49 --- /dev/null +++ b/modules/shutdown-button/src/main.rs @@ -0,0 +1,25 @@ +//! Display message in console when a Button is pressed +// use rust_gpiozero::{Button, Debounce}; +use rust_gpiozero::{Button}; +// use std::time::Duration; +use std::process::Command; + +fn main() { + // Create a button which is attached to Pin 21 + let mut button = Button::new(21); + // Add debouncing so that subsequent presses within 100ms don't trigger a press + // .debounce(Duration::from_millis(100)); + + // Add an async interrupt to trigger whenever the button is pressed + // button + // .when_pressed(|_| { + // println!("button pressed"); + // }) + // .unwrap(); + println!("Waiting for shutdown button press"); + button.wait_for_press(None); + println!("Shutdown button pressed"); + Command::new("shutdown") + .output() + .expect("failed to execute shutdown command"); +} diff --git a/pi-config/ssh.txt b/pi-config/ssh.txt deleted file mode 100644 index e69de29..0000000 diff --git a/pi-config/userconf.txt b/pi-config/userconf.txt deleted file mode 100644 index 19ef386..0000000 --- a/pi-config/userconf.txt +++ /dev/null @@ -1 +0,0 @@ -: \ No newline at end of file diff --git a/pi-config/wpa_supplicant.conf b/pi-config/wpa_supplicant.conf deleted file mode 100644 index 11648d1..0000000 --- a/pi-config/wpa_supplicant.conf +++ /dev/null @@ -1,13 +0,0 @@ -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 -country= - -network={ - scan_ssid=1 - ssid="" - psk="" - proto=RSN - key_mgmt=WPA-PSK - pairwise=CCMP - auth_alg=OPEN -} \ No newline at end of file diff --git a/scripts/audio-setup-utils.sh b/scripts/audio-setup-utils.sh deleted file mode 100755 index d879fa2..0000000 --- a/scripts/audio-setup-utils.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env sh - -# Install utils for cpu freq -sudo apt-get install cpufrequtils -sudo cpufreq-set -r -g performance -sudo echo "ENABLE="true" -GOVERNOR="performance" -MAX_SPEED="0" -MIN_SPEED="0" " | sudo tee -a /etc/default/cpufrequtils - -# Set CPU governor -sudo sed -i 's/exit 0/sudo cpufreq-set -r -g performance/g' /etc/rc.local -sudo echo "exit 0" | sudo tee -a /etc/rc.local - -# Set realtime priority and memlock -sudo echo " -@audio nice -15 -@audio - rtprio 90 # maximum realtime priority -@audio - memlock unlimited # maximum locked-in-memory address space (KB) -" | sudo tee -a /etc/security/limits.conf - -# Set swappiness -# This setting changes the so-called swappiness of your system, -# or in other words, the moment when your system starts to use its swap partition. -sudo echo " -vm.swappiness = 10 -fs.inotify.max_user_watches = 524288 -" | sudo tee /etc/sysctl.conf diff --git a/scripts/export-config-values.sh b/scripts/export-config-values.sh deleted file mode 100644 index 4602fce..0000000 --- a/scripts/export-config-values.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -if [ $# -eq 1 ]; then - CONFIG_FILE=$1 -else - CONFIG_FILE=/boot/hydrophonitor/hydrophonitor-config.txt -fi - -# Select non-comment lines in CONFIG_FILE, clean horizontal whitespace -args=$(grep -v '^#' $CONFIG_FILE | tr -d '[:blank:]' | tr '\n' ' ') - -for arg in $args; do - echo "export $arg" - export "${arg?}" -done diff --git a/scripts/list-usb-devices.sh b/scripts/list-usb-devices.sh deleted file mode 100755 index 8bb091f..0000000 --- a/scripts/list-usb-devices.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do - ( - syspath="${sysdevpath%/dev}" - devname="$(udevadm info -q name -p $syspath)" - [[ "$devname" == "bus/"* ]] && exit - eval "$(udevadm info -q property --export -p $syspath)" - [[ -z "$ID_SERIAL" ]] && exit - echo "/dev/$devname - $ID_SERIAL" - ) -done diff --git a/scripts/setup-audio.sh b/scripts/setup-audio.sh deleted file mode 100755 index f0c5e5b..0000000 --- a/scripts/setup-audio.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -set -ex - -echo "Setting up audio recording" - -# Install packages -sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-dev - -# Get ID and number of the USB audio device -card_number=$(aplay -l | grep -i usb | grep -i audio | cut -d ' ' -f 2 | cut -d ':' -f 1) - -# Change default audio device -sudo touch /etc/asound.conf - -config="pcm.!default { - type plug - slave { - pcm \"hw:$card_number,0\" - } -} - -ctl.!default { - type hw - card $card_number -}" - -if ! grep -q "$config" /etc/asound.conf; then - echo "$config" | sudo tee -a /etc/asound.conf -fi - -cd $HOME/hydrophonitor/audio-logger && cargo build --release diff --git a/scripts/setup-gps.sh b/scripts/setup-gps.sh deleted file mode 100755 index 3749a2e..0000000 --- a/scripts/setup-gps.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -ex - -echo "Setting up GPS recording" - -sudo apt-get update && sudo apt-get install -y gpsd gpsd-clients - -sudo pip install -r $HOME/hydrophonitor/gps-logger/requirements.txt - -sudo systemctl stop gpsd.socket -sudo systemctl disable gpsd.socket - -device="/dev/ttyUSB0" - -sudo gpsd ${device} -F /var/run/gpsd.sock - -sudo sed -i "s|DEVICES=\"\"|DEVICES=\"${device}\"|g" /etc/default/gpsd - -config="START_DAEMON=\"true\"" - -if ! grep -q "$config" /etc/default/gpsd; then - echo "$config" | sudo tee -a /etc/default/gpsd -fi diff --git a/scripts/setup-pressure-depth.sh b/scripts/setup-pressure-depth.sh deleted file mode 100644 index 6f5f9d8..0000000 --- a/scripts/setup-pressure-depth.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -ex - -SDA_GPIO_PIN=10 -SCL_GPIO_PIN=11 -I2C_BUS=3 - -echo "Setting up depth recording" - -# Enable i2c -sudo raspi-config nonint do_i2c 0 - -# Enable i2c on bus 3 and GPIO pins sda=23 and scl=24 -config="dtoverlay=i2c-gpio,bus=$I2C_BUS,i2c_gpio_sda=$SDA_GPIO_PIN,i2c_gpio_scl=$SCL_GPIO_PIN" - -if ! grep -q "$config" /boot/config.txt; then - echo "$config" | sudo tee -a /boot/config.txt -fi - -# Install packages -sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip - -sudo pip install -r $HOME/hydrophonitor/depth-logger/requirements.txt diff --git a/scripts/setup-raspberry-pi.sh b/scripts/setup-raspberry-pi.sh deleted file mode 100644 index 42e526d..0000000 --- a/scripts/setup-raspberry-pi.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash - -set -ex - -BOOT_DIR_PATH=/boot/hydrophonitor -LOG_FILE=$BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-setup-log.txt - -# Output from commands within the curly braces is written -# to $LOG_FILE -{ -DIR_PATH=$HOME - -echo -echo "Starting setup, writing logs to $LOG_FILE" -echo - -echo -echo "### Update file paths in config and start script files" -echo - -# Update hydrophonitor-config.txt HOME_PATH to the current user's home -sudo sed -i "s|^HOME_PATH=.*$|HOME_PATH=$HOME|" $BOOT_DIR_PATH/hydrophonitor-config.txt - -# Update script path in start scripts to the current user's home -sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-all.sh -sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-audio.sh -sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-gps.sh -sudo sed -i "s|^SCRIPT_PATH=.*$|SCRIPT_PATH=$HOME/hydrophonitor/scripts|" $BOOT_DIR_PATH/scripts/start-pressure-depth.sh - -# Copy the files to DIR_PATH -echo -echo "### Copy files to $DIR_PATH" -echo - -mkdir -p "$DIR_PATH" -cd "$DIR_PATH" -rm -rf hydrophonitor -cp -R $BOOT_DIR_PATH/ . - -# Install some development tools -echo -echo "### Install some development tools" -echo - -sudo apt-get update && sudo apt-get install -y build-essential python3-pip - -# Install the Rust programming language toolchain -echo -echo "### Install the Rust toolchain" -echo - -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -source "$HOME/.cargo/env" - -# Setup audio -echo -echo "### Setup audio" -echo - -cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-audio.sh - -# Setup GPS -echo -echo "### Setup GPS" -echo - -cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-gps.sh - -# Setup depth sensor -echo -echo "### Setup depth recording" -echo - -cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-pressure-depth.sh - -# Setup shutdown button -echo -echo "### Setup shutdown button" -echo - -cd "$DIR_PATH" && ./hydrophonitor/scripts/setup-shutdown-button.sh - -# Set up cron job to start the recordings at boot -echo -echo "### Set up a cron job to start the recordings at boot" -echo - -CRON_FILE=/etc/crontab -CRON_LOG_FILE="$BOOT_DIR_PATH/cron-log.txt" -CRON_COMMAND="@reboot root $DIR_PATH/hydrophonitor/scripts/start-all.sh 2>&1 >> $CRON_LOG_FILE" - -# Append command to cron file only if it's not there yet -if ! grep -q "$CRON_COMMAND" "$CRON_FILE"; then - echo "$CRON_COMMAND" | sudo tee -a "$CRON_FILE" -fi - -# Reboot -echo -echo "### Setup ready, run 'sudo reboot' to apply all changes" -echo -} 2>&1 | sudo tee $LOG_FILE \ No newline at end of file diff --git a/scripts/setup-rtc-1.sh b/scripts/setup-rtc-1.sh deleted file mode 100755 index 0f32df1..0000000 --- a/scripts/setup-rtc-1.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -x - -echo "Setting up the real time clock module, part 1" - -# Enable i2c -sudo raspi-config nonint do_i2c 0 - -# Enable i2c rtc on the default i2c pins -config="dtoverlay=i2c-rtc,ds3231" - -if ! grep -q "$config" /boot/config.txt; then - echo "$config" | sudo tee -a /boot/config.txt -fi - -# Disable fake-hwclock -sudo apt-get remove -y fake-hwclock -sudo update-rc.d -f fake-hwclock remove -sudo systemctl disable fake-hwclock - -# Load needed modules at boot -config="i2c-bcm2708 -i2c-dev -rtc-ds1307" - -if ! grep -q "$config" /etc/modules; then - echo "$config" | sudo tee -a /etc/modules -fi - -# Remove some lines from /lib/udev/hwclock-set -sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set - -echo "Setup RTC part 1 done, reboot and run setup-rtc-2.sh" diff --git a/scripts/setup-rtc-2.sh b/scripts/setup-rtc-2.sh deleted file mode 100755 index 44cc833..0000000 --- a/scripts/setup-rtc-2.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -x - -echo "Setting up the real time clock module, part 2" - -I2C_BUS=1 - -echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-$I2C_BUS/new_device - -# Load RTC clock at boot -config="echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-$I2C_BUS/new_device -sudo hwclock -s -exit 0" - -if ! grep -q "$config" /etc/rc.local; then - sudo sed -i "s/^exit 0$//" /etc/rc.local - echo "$config" | sudo tee -a /etc/rc.local -fi - -# Set system time to Internet time -echo "Restarting systmd-timesyncd to update system time" -sudo systemctl restart systemd-timesyncd - -echo "System time now:" -date - -sleep 5 - -# Write system time to the RTC module -echo "Hardware clock time now:" -sudo hwclock -r --verbose - -echo "Writing system time to hardware clock" -sudo hwclock -w --verbose - -echo "Hardware clock time now:" -sudo hwclock -r --verbose diff --git a/scripts/setup-shutdown-button.sh b/scripts/setup-shutdown-button.sh deleted file mode 100644 index acdc2f0..0000000 --- a/scripts/setup-shutdown-button.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -ex - -echo "Setting up shutdown button" - -config="dtoverlay=gpio-shutdown,gpio_pin=21,gpio_pull=up,active_low=1" - -if ! grep -q "$config" /boot/config.txt; then - echo "$config" | sudo tee -a /boot/config.txt -fi diff --git a/scripts/start-all.sh b/scripts/start-all.sh deleted file mode 100755 index a1d395e..0000000 --- a/scripts/start-all.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# Print all commands to standard output -set -x - -BOOT_DIR_PATH=/boot/hydrophonitor -LOG_FILE=$BOOT_DIR_PATH/$(date +"%Y-%m-%dT%H-%M-%S")-startup-log.txt - -{ -SCRIPT_PATH=/home/pi/hydrophonitor/scripts - -# Export the configuration values -. $SCRIPT_PATH/export-config-values.sh - -# Create output directory -OUTPUT_DIR=$OUTPUT_PATH/$(date +"%Y-%m-%d_%H-%M-%S_output") -echo "Create output directory $OUTPUT_DIR" -mkdir -p "$OUTPUT_DIR"/audio - -# Sleep for a little to wait for GPS and sound card to be ready -sleep 10 - -(export OUTPUT_DIR=$OUTPUT_DIR; $SCRIPT_PATH/start-audio.sh & $SCRIPT_PATH/start-gps.sh & $SCRIPT_PATH/start-pressure-depth.sh) 2>&1 | tee "$OUTPUT_DIR"/log.txt -} 2>&1 | tee $LOG_FILE diff --git a/scripts/start-audio.sh b/scripts/start-audio.sh deleted file mode 100755 index e3101c9..0000000 --- a/scripts/start-audio.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -set -x - -# Export the configuration values -SCRIPT_PATH=/home/pi/hydrophonitor/scripts -. $SCRIPT_PATH/export-config-values.sh - -AUDIO_TARGET_EXECUTABLE="audio" - -OPTIONS="rec \ ---name audio_data \ ---output $OUTPUT_DIR/audio \ ---batch-recording $BATCH_RECORD_LENGTH \ ---sample-rate $SAMPLE_RATE \ ---channels $CHANNELS \ ---buffer-size 1024 \ -alsa" - -cd $HOME_PATH/hydrophonitor/audio-logger/target/release && ./$AUDIO_TARGET_EXECUTABLE $OPTIONS diff --git a/scripts/start-gps.sh b/scripts/start-gps.sh deleted file mode 100755 index 495db53..0000000 --- a/scripts/start-gps.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -x - -# Export the configuration values -SCRIPT_PATH=/home/pi/hydrophonitor/scripts -. $SCRIPT_PATH/export-config-values.sh - -OPTIONS="--output $OUTPUT_DIR --interval $GPS_INTERVAL" - -cd $HOME_PATH/hydrophonitor/gps-logger && python record-gps.py $OPTIONS diff --git a/scripts/start-pressure-depth.sh b/scripts/start-pressure-depth.sh deleted file mode 100644 index a4b5506..0000000 --- a/scripts/start-pressure-depth.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -x - -I2C_BUS=3 - -# Export the configuration values -SCRIPT_PATH=/home/pi/hydrophonitor/scripts -. $SCRIPT_PATH/export-config-values.sh - -OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL --bus $I2C_BUS" - -cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS diff --git a/targets/raspberry-pi-3/default.nix b/targets/raspberry-pi-3/default.nix new file mode 100644 index 0000000..61e8ec4 --- /dev/null +++ b/targets/raspberry-pi-3/default.nix @@ -0,0 +1,74 @@ +{ + config, + pkgs, + ... +}: let + system = "aarch64-linux"; +in { + imports = [ + ./i2c.nix + ]; + system.stateVersion = "23.05"; + sdImage.compressImage = false; + + boot = { + # disable internal sound card and vc4 gpu + blacklistedKernelModules = ["snd_bcm2835" "vc4"]; + # enable i2c and rtc modules + kernelModules = ["i2c-dev" "i2c_bcm2708" "rtc_ds1307"]; + kernelPackages = pkgs.linuxKernel.packages.linux_rpi3; + initrd.availableKernelModules = [ + "usbhid" + "usb_storage" + "pcie_brcmstb" # required for the pcie bus to work + "reset-raspberrypi" # required for vl805 firmware to load + ]; + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + }; + + hardware = { + raspberry-pi."3".i2c1.enable = true; + deviceTree.filter = "bcm2711-rpi-*.dtb"; + # Required for the wireless firmware + enableRedistributableFirmware = true; + }; + + environment.systemPackages = with pkgs; [i2c-tools libgpiod]; + + users.users.kaskelotti = { + isNormalUser = true; + initialHashedPassword = "$6$ySDQdXbGH/qDvjpe$Jp5icbEFRSBLsxB2XGxFz.dACxOS/.KYHENxVSUzFED0UYi9R64858JevedVB06sTsFvlKOPSlzBvbACbxNZr1"; + extraGroups = ["wheel" "networkmanager"]; + }; + nix.settings.trusted-users = ["kaskelotti"]; + + sound.enable = true; + + services.openssh = { + enable = true; + settings.PasswordAuthentication = true; + }; + + services.audio-recorder = { + enable = true; + output-folder = "/output/audio"; + sample-rate = 192000; + sample-format = "S32_LE"; + channels = 4; + max-file-time-secs = 300; + }; + + services.gps-recorder = { + enable = true; + output-folder = "/output/gps"; + interval-secs = 10; + }; + + services.i2c-rtc-start = { + enable = true; + i2c-bus = 1; + }; +} diff --git a/targets/raspberry-pi-3/i2c.nix b/targets/raspberry-pi-3/i2c.nix new file mode 100644 index 0000000..6fef833 --- /dev/null +++ b/targets/raspberry-pi-3/i2c.nix @@ -0,0 +1,84 @@ +{ + config, + lib, + ... +}: let + cfg = config.hardware.raspberry-pi."3"; + optionalProperty = name: value: lib.optionalString (value != null) "${name} = <${builtins.toString value}>;"; + simple-overlay = { + target, + status, + frequency, + }: { + name = "${target}-${status}-overlay"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2711"; + fragment@0 { + target = <&${target}>; + __overlay__ { + status = "${status}"; + ${optionalProperty "clock-frequency" frequency} + }; + }; + }; + ''; + }; +in { + options.hardware.raspberry-pi."3" = { + i2c0 = { + enable = lib.mkEnableOption '' + Turn on the VideoCore I2C bus (maps to /dev/i2c-22) and enable access from the i2c group. + After a reboot, i2c-tools (e.g. i2cdetect -F 22) should work for root or any user in i2c. + ''; + frequency = lib.mkOption { + type = lib.types.nullOr lib.types.int; + default = null; + description = '' + interface clock-frequency + ''; + }; + }; + i2c1 = { + enable = lib.mkEnableOption '' + Turn on the ARM I2C bus (/dev/i2c-1 on GPIO pins 3 and 5) and enable access from the i2c group. + After a reboot, i2c-tools (e.g. i2cdetect -F 1) should work for root or any user in i2c. + ''; + frequency = lib.mkOption { + type = lib.types.nullOr lib.types.int; + default = null; + description = '' + interface clock-frequency + ''; + }; + }; + }; + config.hardware = lib.mkMerge [ + (lib.mkIf cfg.i2c0.enable { + i2c.enable = lib.mkDefault true; + deviceTree = { + overlays = [ + (simple-overlay { + target = "i2c0if"; + status = "okay"; + inherit (cfg.i2c0) frequency; + }) + ]; + }; + }) + (lib.mkIf cfg.i2c1.enable { + i2c.enable = lib.mkDefault true; + deviceTree = { + overlays = [ + (simple-overlay { + target = "i2c1"; + status = "okay"; + inherit (cfg.i2c1) frequency; + }) + ]; + }; + }) + ]; +} diff --git a/targets/raspberry-pi-4/default.nix b/targets/raspberry-pi-4/default.nix new file mode 100644 index 0000000..b619a1a --- /dev/null +++ b/targets/raspberry-pi-4/default.nix @@ -0,0 +1,63 @@ +{ + config, + pkgs, + ... +}: let + system = "aarch64-linux"; +in { + system.stateVersion = "23.05"; + sdImage.compressImage = false; + + # disable internal sound card and vc4 gpu + boot.blacklistedKernelModules = ["snd_bcm2835" "vc4"]; + # enable i2c and rtc modules + boot.kernelModules = ["i2c-dev" "i2c_bcm2708" "rtc_ds1307"]; + + hardware = { + raspberry-pi."4".i2c1.enable = true; + raspberry-pi."4".apply-overlays-dtmerge.enable = true; + deviceTree.filter = "bcm2711-rpi-4*.dtb"; + }; + + environment.systemPackages = with pkgs; [i2c-tools]; + + users.users.kaskelotti = { + isNormalUser = true; + initialHashedPassword = "$6$ySDQdXbGH/qDvjpe$Jp5icbEFRSBLsxB2XGxFz.dACxOS/.KYHENxVSUzFED0UYi9R64858JevedVB06sTsFvlKOPSlzBvbACbxNZr1"; + extraGroups = ["wheel" "networkmanager"]; + }; + nix.settings.trusted-users = ["kaskelotti"]; + + sound.enable = true; + + services.openssh = { + enable = true; + settings.PasswordAuthentication = true; + }; + + services.audio-recorder = { + enable = true; + output-folder = "/output/audio"; + sample-rate = 192000; + sample-format = "S32_LE"; + channels = 4; + max-file-time-secs = 300; + }; + + services.gps-recorder = { + enable = true; + output-folder = "/output/gps"; + interval-secs = 10; + }; + + services.i2c-rtc-start = { + enable = true; + i2c-bus = 1; + }; + + services.shutdown-button = { + enable = true; + gpio-pin = 21; # option not implemented yet + shutdown-press-secs = 1; # option not implemented yet + }; +}