initial commit

This commit is contained in:
Rudis Muiznieks 2024-08-29 13:54:20 -05:00
commit 54e54a90e7
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
7 changed files with 444 additions and 0 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

44
.gitignore vendored Normal file
View File

@ -0,0 +1,44 @@
/target
.env
# Added by cargo
#
# already existing elements were commented out
#/target
# Added by cargo
#
# already existing elements were commented out
#/target
# Added by cargo
#
# already existing elements were commented out
#/target
# Added by cargo
#
# already existing elements were commented out
#/target
# Added by cargo
#
# already existing elements were commented out
#/target
# Added by cargo
#
# already existing elements were commented out
#/target

273
Cargo.lock generated Normal file
View File

@ -0,0 +1,273 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]]
name = "byte-slice-cast"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "display-interface"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7517c040926d7b02b111884aa089177db80878533127f7c1b480d852c5fb4112"
[[package]]
name = "display-interface-i2c"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4895cd4e54e5536ef370d7f1eec787aad8275dd8ad15815aebfa71dd847b4ebf"
dependencies = [
"display-interface",
"embedded-hal 0.2.7",
]
[[package]]
name = "display-interface-spi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "489378ad054862146fbd1f09f51d585ccbe4bd1e2feadcda2a13ac33f840e1a5"
dependencies = [
"byte-slice-cast",
"display-interface",
"embedded-hal 0.2.7",
]
[[package]]
name = "embedded-graphics"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
dependencies = [
"az",
"byteorder",
]
[[package]]
name = "embedded-hal"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
dependencies = [
"nb 0.1.3",
"void",
]
[[package]]
name = "embedded-hal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
[[package]]
name = "embedded-hal-nb"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
dependencies = [
"embedded-hal 1.0.0",
"nb 1.1.0",
]
[[package]]
name = "float-cmp"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
dependencies = [
"num-traits",
]
[[package]]
name = "libc"
version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
[[package]]
name = "micromath"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
[[package]]
name = "nb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
dependencies = [
"nb 1.1.0",
]
[[package]]
name = "nb"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "pipod"
version = "0.1.0"
dependencies = [
"embedded-graphics",
"rppal",
"ssd1306",
]
[[package]]
name = "rppal"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b37e992f3222e304708025de77c9e395068a347449d0d7164f52d3beccdbd8d"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
"embedded-hal-nb",
"libc",
"nb 0.1.3",
"spin_sleep",
"void",
]
[[package]]
name = "spin_sleep"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64bd7227d85bfd1b8df51e0d83da36d9baaee85eb75730386ef8e3ab6f2a2ea3"
dependencies = [
"windows-sys",
]
[[package]]
name = "ssd1306"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b37918f6137f2b58427181c3e10a731bef1061a9756b13ffbade64f21892acc6"
dependencies = [
"display-interface",
"display-interface-i2c",
"display-interface-spi",
"embedded-graphics-core",
"embedded-hal 0.2.7",
]
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "pipod"
version = "0.1.0"
edition = "2021"
[dependencies]
embedded-graphics = "0.8.1"
rppal = { version = "0.19.0", features = ["hal"] }
ssd1306 = "0.8.4"

53
cmd Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail
if [ -f "./.env" ]; then
set -a
source .env
set +a
else
echo "No .env file found."
exit 1
fi
if [ "$#" -gt 0 ]; then
cmd=$1
shift
else
cmd="help"
fi
ssh_run_cmd() {
ssh -i "$SSH_KEY" "$SSH_HOST" "$@"
}
copy_and_run() {
file=$1
scp -i "$SSH_KEY" "$file" "$SSH_HOST":"$SSH_DEST_DIR"
ssh_run_cmd "${SSH_DEST_DIR:-.}/pipod"
}
{
set -euo pipefail
case "$cmd" in
"clean") cargo clean;;
"build") cargo build --target arm-unknown-linux-gnueabihf;;
"release") cargo build --release --target arm-unknown-linux-gnueabihf;;
"debug") ./cmd build && copy_and_run ./target/arm-unknown-linux-gnueabihf/debug/pipod;;
"run") ./cmd release && copy_and_run ./target/arm-unknown-linux-gnueabihf/release/pipod;;
"remote-clean") ssh_run_cmd rm -f "${SSH_DEST_DIR:-.}/pipod";;
"help")
echo "Usage: ./cmd [task]"
echo "Tasks: clean, build, release, debug, run, remote-clean, help"
;;
*)
echo "Unrecognized task '$cmd'."
exit 1
;;
esac
} || {
code=$?
echo "An error occurred while executing the command ($code)."
exit $code
}

3
example.env Normal file
View File

@ -0,0 +1,3 @@
SSH_HOST=pipod.ln0.us
SSH_KEY=~/.ssh/id_ed25519.pipod
SSH_DEST_DIR=

53
src/main.rs Normal file
View File

@ -0,0 +1,53 @@
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
pixelcolor::BinaryColor,
prelude::*,
primitives::{Circle, PrimitiveStyleBuilder, Rectangle, Triangle},
text::{Baseline, Text},
};
use rppal::i2c::I2c;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
const ADDR_PISUGAR: u16 = 0x57;
const REG_PERCENT: u8 = 0x2a;
const REG_RTC: u8 = 0x68;
fn main() {
let mut batt_i2c = I2c::new().unwrap();
batt_i2c.set_slave_address(ADDR_PISUGAR);
let mut buf = [0u8; 1];
batt_i2c.block_read(REG_PERCENT, &mut buf).unwrap();
let display_i2c = I2c::new().unwrap();
let interface = I2CDisplayInterface::new(display_i2c);
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();
display.init().unwrap();
/*let style = PrimitiveStyleBuilder::new()
.stroke_width(1)
.stroke_color(BinaryColor::On)
.build();
Rectangle::new(Point::new(0, 0), Size::new(127, 63))
.into_styled(style)
.draw(&mut display)
.unwrap();
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(BinaryColor::On)
.build();
Text::with_baseline(
&format!("Battery: {}%", buf[0]),
Point::new(2, 2),
text_style,
Baseline::Top,
)
.draw(&mut display)
.unwrap();*/
display.flush().unwrap();
}