Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from fkromer/d-led
add D script to control a led
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
#!/bin/bash | |||
echo "Building the D led example script led" | |||
gdc dLED.d -o led |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
} |