gpio_utils/commands/
gpio_write.rs1use config::GpioConfig;
10use options::GpioWriteOptions;
11use std::process::exit;
12use sysfs_gpio::Direction;
13
14pub fn main(config: &GpioConfig, opts: &GpioWriteOptions) {
15 let pin_config = match config.get_pin(opts.pin) {
16 Some(pin) => pin,
17 None => {
18 println!("Unable to find config entry for pin '{}'", opts.pin);
19 exit(1);
20 }
21 };
22
23 let pin = pin_config.get_pin();
24 pin.set_direction(Direction::Out).unwrap_or_else(|e| {
25 println!("Error setting GPIO direction: {:?}", e);
26 exit(1)
27 });
28 pin.set_value(opts.value).unwrap_or_else(|e| {
29 println!("There was an error writing to the gpio: {:?}", e);
30 exit(1);
31 });
32}