Permalink
Browse files

Merge pull request #11 from fkromer/d-led

add D script to control a led
  • Loading branch information...
derekmolloy committed Aug 7, 2017
2 parents 4ff7eca + e7e4ade commit a151288cb828679054af073b77e598484bbe62b8
Showing with 47 additions and 0 deletions.
  1. +3 −0 chp05/dLED/build
  2. +44 −0 chp05/dLED/dLED.d
View
@@ -0,0 +1,3 @@
#!/bin/bash
echo "Building the D led example script led"
gdc dLED.d -o led
View
@@ -0,0 +1,44 @@
import std.file;
import std.getopt;
import std.stdio;
int main (string[] args) {
int ARGUMENT_COUNT = 2;
string LED3_PATH = "/sys/class/leds/beaglebone:green:usr3";
enum Command : string
{
on = "on",
off = "off",
flash = "flash"
}
enum ReturnCode : int
{
pass = 0,
fail = 1
}
if (args.length != ARGUMENT_COUNT) {
writeln("too many or too little arguments");
return ReturnCode.fail;
}
string cmd = "invalid"; // no default, value force validation below to fail
getopt(args, "command", &cmd);
chdir(LED3_PATH);
if (cmd == Command.on) {
std.file.write("brightness", "1");
} else if (cmd == Command.off) {
std.file.write("brightness", "0");
} else if (cmd == Command.flash) {
std.file.write("trigger", "timer");
} else {
writeln("command not supported");
return ReturnCode.fail;
}
return ReturnCode.pass;
}

0 comments on commit a151288

Please sign in to comment.