ComputerScienceHouse / ComputerScienceHouse/gatekeeper-door

Test GPIO door functionality

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1
Forks
5
PR merge metrics
No merged PRs in 30d

Description

I made a branch in my fork with some test code, but it looks like you should be able to do this:

```
use gpio::{GpioOut};
use std::{thread, time};

/*
On the board,
Pin 87 -> Motor Rev
Pin 89 -> Motor Fwd
*/

/*
Here's how you'd do it in BASH

ON:
# echo 89 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio49/direction
# echo 1 > /sys/class/gpio/gpio49/value
*/
fn door_open() {
// Motor Forward for 0.5 seconds.
gpio89.set_value(value).expect("could not set gpio89");
thread::sleep(time::Duration::from_millis(500));
value = !value;
gpio89.set_value(value).expect("could not set gpio89");
}

fn door_close() {
// Motor backwards for 0.5 seconds.
gpio87.set_value(value).expect("could not set gpio87");
thread::sleep(time::Duration::from_millis(500));
value = !value;
gpio87.set_value(value).expect("could not set gpio87");
}

fn yeet_door() {
// Let's try to open GPIO 87 and 89.
let mut gpio87 = gpio::sysfs::SysFsGpioInput::open(87).unwrap();
let mut gpio89 = gpio::sysfs::SysFsGpioOutput::open(89).unwrap();

// GPIO87 and 89 will be toggled every 0.5 sec in the background by a different thread
// This should cause the door to lock and unlock.
let mut value = false;
thread::spawn(move || loop {
// Motor Forward for 0.5 seconds.
gpio89.set_value(value).expect("could not set gpio89");
thread::sleep(time::Duration::from_millis(500));
value = !value;
gpio89.set_value(value).expect("could not set gpio89");
thread::sleep(time::Duration::from_millis(3000)); // Leave it in that state for 3 secs
// Motor backwards for 0.5 seconds.
gpio87.set_value(value).expect("could not set gpio87");
thread::sleep(time::Duration::from_millis(500));
value = !value;
gpio87.set_value(value).expect("could not set gpio87");
thread::sleep(time::Duration::from_millis(3000)); // Leave it in that state for 3 secs
});
}
```

This needs to be tested, though. I haven't gotten a chance. The Beagle appears to be intelligent about its GPIO pin assignment in the OS, so pin 87 should actually be 87, and standard pin assignment libraries should work.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.