misc fixes (#1894)

This commit is contained in:
Aiden McClelland
2022-10-27 15:53:34 -06:00
parent 26c37ba824
commit 17d39143ac
6 changed files with 5660 additions and 54 deletions

1
.gitignore vendored
View File

@@ -20,3 +20,4 @@ secrets.db
/GIT_HASH.txt /GIT_HASH.txt
/embassyos-*.tar.gz /embassyos-*.tar.gz
/*.deb /*.deb
/target

5607
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -42,10 +42,8 @@ path = "src/bin/avahi-alias.rs"
[features] [features]
avahi = ["avahi-sys"] avahi = ["avahi-sys"]
default = ["avahi", "metal", "sound", "js_engine"] default = ["avahi", "js_engine"]
dev = [] dev = []
metal = []
sound = []
unstable = ["patch-db/unstable"] unstable = ["patch-db/unstable"]
[dependencies] [dependencies]

View File

@@ -146,21 +146,18 @@ where
{ {
#[instrument(skip(self))] #[instrument(skip(self))]
pub async fn play(&self) -> Result<(), Error> { pub async fn play(&self) -> Result<(), Error> {
#[cfg(feature = "sound")] let mut sound = SoundInterface::lease().await?;
{ for (note, slice) in self.note_sequence.clone() {
let mut sound = SoundInterface::lease().await?; match note {
for (note, slice) in self.note_sequence.clone() { None => tokio::time::sleep(slice.to_duration(self.tempo_qpm)).await,
match note { Some(n) => {
None => tokio::time::sleep(slice.to_duration(self.tempo_qpm)).await, sound
Some(n) => { .play_for_time_slice(self.tempo_qpm, &n, &slice)
sound .await?
.play_for_time_slice(self.tempo_qpm, &n, &slice) }
.await? };
}
};
}
sound.close().await?;
} }
sound.close().await?;
Ok(()) Ok(())
} }
} }

View File

@@ -18,7 +18,7 @@ use crate::logs::{
use crate::shutdown::Shutdown; use crate::shutdown::Shutdown;
use crate::util::display_none; use crate::util::display_none;
use crate::util::serde::{display_serializable, IoFormat}; use crate::util::serde::{display_serializable, IoFormat};
use crate::{Error, ErrorKind}; use crate::{Error, ErrorKind, ResultExt};
pub const SYSTEMD_UNIT: &'static str = "embassyd"; pub const SYSTEMD_UNIT: &'static str = "embassyd";
@@ -238,7 +238,7 @@ impl<'de> Deserialize<'de> for GigaBytes {
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]
pub struct MetricsGeneral { pub struct MetricsGeneral {
#[serde(rename = "Temperature")] #[serde(rename = "Temperature")]
temperature: Celsius, temperature: Option<Celsius>,
} }
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]
pub struct MetricsMemory { pub struct MetricsMemory {
@@ -283,7 +283,6 @@ pub struct MetricsDisk {
} }
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Metrics { pub struct Metrics {
#[cfg(feature = "metal")]
#[serde(rename = "General")] #[serde(rename = "General")]
general: MetricsGeneral, general: MetricsGeneral,
#[serde(rename = "Memory")] #[serde(rename = "Memory")]
@@ -316,20 +315,14 @@ pub async fn launch_metrics_task<F: FnMut() -> Receiver<Option<Shutdown>>>(
mut mk_shutdown: F, mut mk_shutdown: F,
) { ) {
// fetch init temp // fetch init temp
let init_temp; let init_temp = match get_temp().await {
loop { Ok(a) => Some(a),
match get_temp().await { Err(e) => {
Ok(a) => { tracing::error!("Could not get initial temperature: {}", e);
init_temp = a; tracing::debug!("{:?}", e);
break; None
}
Err(e) => {
tracing::error!("Could not get initial temperature: {}", e);
tracing::debug!("{:?}", e);
}
} }
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; };
}
// fetch init cpu // fetch init cpu
let init_cpu; let init_cpu;
let proc_stat; let proc_stat;
@@ -383,7 +376,6 @@ pub async fn launch_metrics_task<F: FnMut() -> Receiver<Option<Shutdown>>>(
} }
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
} }
#[cfg(feature = "metal")]
{ {
// lock for writing // lock for writing
let mut guard = cache.write().await; let mut guard = cache.write().await;
@@ -397,28 +389,30 @@ pub async fn launch_metrics_task<F: FnMut() -> Receiver<Option<Shutdown>>>(
disk: init_disk, disk: init_disk,
}) })
} }
// launch persistent temp task
#[cfg(feature = "metal")]
let temp_task = launch_temp_task(cache, mk_shutdown());
// launch persistent cpu task
let cpu_task = launch_cpu_task(cache, proc_stat, mk_shutdown());
// launch persistent mem task
let mem_task = launch_mem_task(cache, mk_shutdown());
// launch persistent disk task
let disk_task = launch_disk_task(cache, mk_shutdown());
let mut task_vec = Vec::new(); let mut task_vec = Vec::new();
task_vec.push(cpu_task.boxed()); // launch persistent temp task
task_vec.push(mem_task.boxed()); if cache
task_vec.push(disk_task.boxed()); .read()
.await
#[cfg(feature = "metal")] .as_ref()
task_vec.push(temp_task.boxed()); .unwrap()
.general
.temperature
.is_some()
{
task_vec.push(launch_temp_task(cache, mk_shutdown()).boxed());
}
// launch persistent cpu task
task_vec.push(launch_cpu_task(cache, proc_stat, mk_shutdown()).boxed());
// launch persistent mem task
task_vec.push(launch_mem_task(cache, mk_shutdown()).boxed());
// launch persistent disk task
task_vec.push(launch_disk_task(cache, mk_shutdown()).boxed());
futures::future::join_all(task_vec).await; futures::future::join_all(task_vec).await;
} }
#[cfg(feature = "metal")]
async fn launch_temp_task( async fn launch_temp_task(
cache: &RwLock<Option<Metrics>>, cache: &RwLock<Option<Metrics>>,
mut shutdown: Receiver<Option<Shutdown>>, mut shutdown: Receiver<Option<Shutdown>>,
@@ -427,7 +421,7 @@ async fn launch_temp_task(
match get_temp().await { match get_temp().await {
Ok(a) => { Ok(a) => {
let mut lock = cache.write().await; let mut lock = cache.write().await;
(*lock).as_mut().unwrap().general.temperature = a (*lock).as_mut().unwrap().general.temperature = Some(a)
} }
Err(e) => { Err(e) => {
tracing::error!("Could not get new temperature: {}", e); tracing::error!("Could not get new temperature: {}", e);
@@ -512,8 +506,10 @@ async fn launch_disk_task(
#[instrument] #[instrument]
async fn get_temp() -> Result<Celsius, Error> { async fn get_temp() -> Result<Celsius, Error> {
let milli = tokio::fs::read_to_string("/sys/class/thermal/thermal_zone0/temp") let temp_file = "/sys/class/thermal/thermal_zone0/temp";
.await? let milli = tokio::fs::read_to_string(temp_file)
.await
.with_ctx(|_| (crate::ErrorKind::Filesystem, temp_file))?
.trim() .trim()
.parse::<f64>()?; .parse::<f64>()?;
Ok(Celsius(milli / 1000.0)) Ok(Celsius(milli / 1000.0))

View File

@@ -25,8 +25,15 @@ sed -i "s/http:/https:/g" /etc/apt/sources.list /etc/apt/sources.list.d/*.list
. /usr/lib/embassy/scripts/add-apt-sources . /usr/lib/embassy/scripts/add-apt-sources
KERN=$(dpkg -s raspberrypi-kernel | grep Version | awk '{print $2}')
apt-get update apt-get update
apt-get upgrade -y apt-get upgrade -y
if [ "$KERN" != "$(dpkg -s raspberrypi-kernel | grep Version | awk '{print $2}')" ]; then
echo "Kernel updated, restarting..."
sync
reboot
fi
apt-get install -y $(cat /usr/lib/embassy/depends) apt-get install -y $(cat /usr/lib/embassy/depends)
apt-get remove --purge -y $(cat /usr/lib/embassy/conflicts) beep apt-get remove --purge -y $(cat /usr/lib/embassy/conflicts) beep
apt-get autoremove -y apt-get autoremove -y