Skip to content

Commit

Permalink
Minor fixes (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarpoole authored Nov 7, 2022
1 parent 79451b0 commit c865ce2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ use super::{
tle8108em::tle8108em::{Channel, ChannelMode, TLE8108EM},
};
use async_trait::async_trait;
use std::time::Duration;

// EC2-5TNU relay datasheet specifies 2ms operating time
const SWITCHING_TIME_MS: u64 = 10;

const BLUE_ACTIVE: Channel = Channel::CH4;
const BLUE_PASSIVE: Channel = Channel::CH8;
Expand Down Expand Up @@ -37,9 +41,9 @@ impl Driver for HardwareDriver {
.set_channel(ORANGE_ACTIVE, ChannelMode::ON)
.set_channel(GREEN_ACTIVE, ChannelMode::ON)
.set_channel(BROWN_ACTIVE, ChannelMode::ON)
.update()
.await?;
self.tle8108em.reset_channels().update().await?;
.update()?;
wait_for_switch().await;
self.tle8108em.reset_channels().update()?;
self.mode = DriverMode::ACTIVE;
} else {
self.tle8108em
Expand All @@ -48,9 +52,9 @@ impl Driver for HardwareDriver {
.set_channel(ORANGE_PASSIVE, ChannelMode::ON)
.set_channel(GREEN_PASSIVE, ChannelMode::ON)
.set_channel(BROWN_PASSIVE, ChannelMode::ON)
.update()
.await?;
self.tle8108em.reset_channels().update().await?;
.update()?;
wait_for_switch().await;
self.tle8108em.reset_channels().update()?;
self.mode = DriverMode::PASSIVE;
}
Ok(())
Expand All @@ -59,3 +63,7 @@ impl Driver for HardwareDriver {
Ok(self.mode)
}
}

async fn wait_for_switch() {
sleep(Duration::from_millis(SWITCHING_TIME_MS)).await;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use spidev::{SpiModeFlags, Spidev, SpidevOptions, SpidevTransfer};
use std::io;
use std::time::Duration;
use tokio::time::sleep;

const SWITCHING_TIME_MS: u64 = 500;
const TLE8108EM_SPI_SCLK_HZ: u32 = 100000;
const TLE8108EM_SPI_MODE: SpiModeFlags = SpiModeFlags::SPI_MODE_1;

Expand Down Expand Up @@ -137,18 +135,13 @@ impl TLE8108EM {
self.modes = Register::<ChannelMode>::reset();
return self;
}
pub async fn update(&mut self) -> io::Result<()> {
pub fn update(&mut self) -> io::Result<()> {
let response = transfer(&mut self.spidev, self.modes.pack())?;
self.diags = response.unpack();
wait_for_switch().await;
Ok(())
}
}

async fn wait_for_switch() {
sleep(Duration::from_millis(SWITCHING_TIME_MS)).await;
}

fn transfer(spi: &mut Spidev, payload: BinaryRegister) -> io::Result<BinaryRegister> {
println!("SPI TX: 0x{:X}{:X}", payload[1], payload[0]);
let mut response = [0; 2];
Expand Down
8 changes: 8 additions & 0 deletions backend/etherweasel_rs_container/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo "Installing..."
if ! command -v redis-cli &> /dev/null; then
echo "Installing redis..."
sudo apt install redis -y
fi
echo "Installed"
2 changes: 2 additions & 0 deletions backend/etherweasel_rs_container/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ if [[ $TARGET = "raspi" ]]; then
--target $RASPI_TARGET --release
# Transfer the binary
sshpass -p "$PASSWORD" rsync ./etherweasel_rs/target/$RASPI_TARGET/release/etherweasel_rs "$HOST":~/etherweasel_rs
sshpass -p "$PASSWORD" rsync ./install.sh "$HOST":~/install.sh
# Run the binary
sshpass -p "$PASSWORD" ssh -t "$HOST" ~/install.sh
sshpass -p "$PASSWORD" ssh -t "$HOST" ~/etherweasel_rs --driver=hardware "$@"
fi

0 comments on commit c865ce2

Please sign in to comment.