mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-01 13:54:19 +01:00
track duration of button hold
This commit is contained in:
@@ -49,6 +49,8 @@ fn main() -> Result<()> {
|
||||
// BUTTON thread
|
||||
button_loop(pins.gpio8, led_tx.clone());
|
||||
|
||||
// thread::sleep(Duration::from_secs(100));
|
||||
|
||||
led_tx.send(Status::MountingSDCard).unwrap();
|
||||
println!("About to mount the sdcard...");
|
||||
while let Err(_e) = mount_sd_card() {
|
||||
|
||||
@@ -5,24 +5,44 @@ use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
const MILLIS: u16 = 10_000;
|
||||
|
||||
const PAUSE: u16 = 15;
|
||||
|
||||
pub fn button_loop(gpio8: gpio::Gpio8, tx: mpsc::Sender<Status>) {
|
||||
thread::spawn(move || {
|
||||
let mut button = PinDriver::input(gpio8).unwrap();
|
||||
button.set_pull(Pull::Down).unwrap();
|
||||
let mut high = false;
|
||||
let mut high_times = 0;
|
||||
let mut low_times = 0;
|
||||
loop {
|
||||
// we are using thread::sleep here to make sure the watchdog isn't triggered
|
||||
thread::sleep(Duration::from_millis(15));
|
||||
thread::sleep(Duration::from_millis(PAUSE.into()));
|
||||
if button.is_high() {
|
||||
if !high {
|
||||
high = true;
|
||||
log::info!("=> GPIO8 HIGH!");
|
||||
high_times = 0;
|
||||
}
|
||||
if high {
|
||||
high_times = high_times + 1;
|
||||
if PAUSE * high_times > MILLIS {
|
||||
// stayed held down?
|
||||
}
|
||||
}
|
||||
tx.send(Status::Reset1).unwrap();
|
||||
} else {
|
||||
if high {
|
||||
high = false;
|
||||
log::info!("=> GPIO8 LOW!");
|
||||
tx.send(Status::Reset1).unwrap();
|
||||
low_times = 0;
|
||||
}
|
||||
if !high {
|
||||
low_times = low_times + 1;
|
||||
if PAUSE * low_times > MILLIS {
|
||||
// stayed not held down?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
sphinx-key/up.sh
Executable file
66
sphinx-key/up.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
check_exists() {
|
||||
command -v "$1" > /dev/null
|
||||
}
|
||||
check_port() {
|
||||
cargo espflash board-info "$1" &> /dev/null
|
||||
}
|
||||
if ! check_exists esptool.py
|
||||
then
|
||||
echo "esptool.py not installed!"
|
||||
echo "install with this command: pip install esptool"
|
||||
exit 1
|
||||
fi
|
||||
if ! check_exists ldproxy
|
||||
then
|
||||
echo "ldproxy not installed!"
|
||||
echo "install with this command: cargo install ldproxy"
|
||||
exit 1
|
||||
fi
|
||||
if ! check_exists cargo-espflash
|
||||
then
|
||||
echo "cargo-espflash not installed!"
|
||||
echo "install with this command: cargo install cargo-espflash"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SSID" ]
|
||||
then
|
||||
echo "Please set environment variable SSID to the SSID of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$PASS" ]
|
||||
then
|
||||
echo "Please set environment variable PASS to the password of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ ${#PASS} -lt 8 ]
|
||||
then
|
||||
echo "Please set PASS to a password longer than 7 characters."
|
||||
exit 1
|
||||
fi
|
||||
for FILE in /dev/tty.*
|
||||
do
|
||||
# Check for port on macOS
|
||||
if check_port $FILE
|
||||
then
|
||||
PORT=$FILE
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$PORT" ]
|
||||
then
|
||||
# Check for port on linux
|
||||
if check_port /dev/ttyUSB0
|
||||
then
|
||||
PORT=/dev/ttyUSB0
|
||||
fi
|
||||
fi
|
||||
if [ -z "$PORT" ]
|
||||
then
|
||||
echo "ESP likely not connected! Exiting now."
|
||||
echo "Make sure the ESP is connected with a data USB cable, and try again."
|
||||
exit 1
|
||||
fi
|
||||
cargo build --release &&
|
||||
esptool.py --chip esp32c3 elf2image target/riscv32imc-esp-espidf/release/sphinx-key &&
|
||||
esptool.py --chip esp32c3 -p $PORT -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x10000 target/riscv32imc-esp-espidf/release/sphinx-key.bin &&
|
||||
espmonitor $PORT
|
||||
Reference in New Issue
Block a user