Commit b40f5522 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) spaces and curly braces in led.inc

parent 05456e7d
...@@ -11,13 +11,14 @@ $led_root = "/dev/led/led"; ...@@ -11,13 +11,14 @@ $led_root = "/dev/led/led";
/* /*
* Send the control string to an LED * Send the control string to an LED
*/ */
function led_ctl($led, $str) { function led_ctl($led, $str)
global $led_root; {
if (led_exists($led)) { global $led_root;
exec("/bin/echo " . escapeshellarg($str) . " > {$led_root}{$led}"); if (led_exists($led)) {
return true; exec("/bin/echo " . escapeshellarg($str) . " > {$led_root}{$led}");
} return true;
return false; }
return false;
} }
/* /*
...@@ -25,270 +26,280 @@ function led_ctl($led, $str) { ...@@ -25,270 +26,280 @@ function led_ctl($led, $str) {
* Letters A-J are on from 1/10s to 1s * Letters A-J are on from 1/10s to 1s
* Letters a-j are off from 1/10s to 1s * Letters a-j are off from 1/10s to 1s
*/ */
function led_pattern($led, $pattern, $repeat=true) { function led_pattern($led, $pattern, $repeat=true)
/* End with a . to stop after one iteration. */ {
$end = $repeat ? "" : "."; /* End with a . to stop after one iteration. */
return led_ctl($led, "s{$pattern}{$end}"); $end = $repeat ? "" : ".";
return led_ctl($led, "s{$pattern}{$end}");
} }
/* /*
* Encode a text message into morse code, and send it to an LED * Encode a text message into morse code, and send it to an LED
*/ */
function led_morse($led, $message) { function led_morse($led, $message)
return led_ctl($led, "m" . str_to_morse($message)); {
return led_ctl($led, "m" . str_to_morse($message));
} }
/* /*
* Turn an LED on * Turn an LED on
*/ */
function led_on($led) { function led_on($led)
led_ctl($led, "1"); {
led_ctl($led, "1");
} }
/* /*
* Turn an LED off * Turn an LED off
*/ */
function led_off($led) { function led_off($led)
led_ctl($led, "0"); {
led_ctl($led, "0");
} }
/* /*
* Find the number of LEDs present on the system. * Find the number of LEDs present on the system.
*/ */
function led_count() { function led_count() {
global $led_root; global $led_root;
$count = 0; $count = 0;
$leds = array(); $leds = array();
if (is_dir(dirname($led_root))) { if (is_dir(dirname($led_root))) {
$leds = glob("{$led_root}*"); $leds = glob("{$led_root}*");
$count = count($leds); $count = count($leds);
} }
return $count; return $count;
} }
/* /*
* Test to see if a given LED exists. * Test to see if a given LED exists.
*/ */
function led_exists($led) { function led_exists($led) {
global $led_root; global $led_root;
if (!is_numeric($led)) if (!is_numeric($led)) {
return false; return false;
return file_exists("{$led_root}{$led}"); }
return file_exists("{$led_root}{$led}");
} }
/* /*
* Sweep across three LEDs in a K.I.T.T.-like way. * Sweep across three LEDs in a K.I.T.T.-like way.
*/ */
function led_kitt() { function led_kitt()
led_pattern(1, 'AaaaaA'); {
led_pattern(2, 'aAaaAa'); led_pattern(1, 'AaaaaA');
led_pattern(3, 'aaAAaa'); led_pattern(2, 'aAaaAa');
led_pattern(3, 'aaAAaa');
} }
/* /*
* Custom pattern for assigning interfaces * Custom pattern for assigning interfaces
*/ */
function led_assigninterfaces() { function led_assigninterfaces()
led_pattern(1, 'AaaAaaaaaaaaaaaa'); {
led_pattern(2, 'aaaaaAaaAaaaaaaa'); led_pattern(1, 'AaaAaaaaaaaaaaaa');
led_pattern(3, 'aaaaaaaaaaAaaAaa'); led_pattern(2, 'aaaaaAaaAaaaaaaa');
led_pattern(3, 'aaaaaaaaaaAaaAaa');
} }
/* /*
* Return the three LEDs to a standard setup (1=on, 2 and 3 = off) * Return the three LEDs to a standard setup (1=on, 2 and 3 = off)
*/ */
function led_normalize() { function led_normalize()
led_on(1); {
led_off(2); led_on(1);
led_off(3); led_off(2);
led_off(3);
} }
/* /*
* Translate a string to morse code. Characters not known to have a * Translate a string to morse code. Characters not known to have a
* valid morse code representation will be ignored. * valid morse code representation will be ignored.
*/ */
function str_to_morse($string) { function str_to_morse($string)
$i = 0; {
$morsestring = ""; $i = 0;
while ($i < strlen($string)) { $morsestring = "";
$morsestring .= char_to_morse(substr($string, $i++, 1)) . " "; while ($i < strlen($string)) {
} $morsestring .= char_to_morse(substr($string, $i++, 1)) . " ";
return $morsestring . "\n"; }
return $morsestring . "\n";
} }
/* /*
* Translate a single character to morse code. Characters not known * Translate a single character to morse code. Characters not known
* to have a valid morse code representation will be ignored. * to have a valid morse code representation will be ignored.
*/ */
function char_to_morse($char) { function char_to_morse($char)
switch (strtoupper($char)) { {
case "A": switch (strtoupper($char)) {
return ".-"; case "A":
break; return ".-";
case "B": break;
return "-..."; case "B":
break; return "-...";
case "C": break;
return "-.-."; case "C":
break; return "-.-.";
case "D": break;
return "-.."; case "D":
break; return "-..";
case "E": break;
return "."; case "E":
break; return ".";
case "F": break;
return "..-."; case "F":
break; return "..-.";
case "G": break;
return "--."; case "G":
break; return "--.";
case "H": break;
return "...."; case "H":
break; return "....";
case "I": break;
return ".."; case "I":
break; return "..";
case "J": break;
return ".---"; case "J":
break; return ".---";
case "K": break;
return "-.-"; case "K":
break; return "-.-";
case "L": break;
return ".-.."; case "L":
break; return ".-..";
case "M": break;
return "--"; case "M":
break; return "--";
case "N": break;
return "-."; case "N":
break; return "-.";
case "O": break;
return "---"; case "O":
break; return "---";
case "P": break;
return ".--."; case "P":
break; return ".--.";
case "Q": break;
return "--.-"; case "Q":
break; return "--.-";
case "R": break;
return ".-."; case "R":
break; return ".-.";
case "S": break;
return "..."; case "S":
break; return "...";
case "T": break;
return "-"; case "T":
break; return "-";
case "U": break;
return "..-"; case "U":
break; return "..-";
case "V": break;
return "...-"; case "V":
break; return "...-";
case "W": break;
return ".--"; case "W":
break; return ".--";
case "X": break;
return "-..-"; case "X":
break; return "-..-";
case "Y": break;
return "-.--"; case "Y":
break; return "-.--";
case "Z": break;
return "--.."; case "Z":
break; return "--..";
case "0": break;
return "-----"; case "0":
break; return "-----";
case "1": break;
return ".----"; case "1":
break; return ".----";
case "2": break;
return "..---"; case "2":
break; return "..---";
case "3": break;
return "...--"; case "3":
break; return "...--";
case "4": break;
return "....-"; case "4":
break; return "....-";
case "5": break;
return "....."; case "5":
break; return ".....";
case "6": break;
return "-...."; case "6":
break; return "-....";
case "7": break;
return "--..."; case "7":
break; return "--...";
case "8": break;
return "---.."; case "8":
break; return "---..";
case "9": break;
return "----."; case "9":
break; return "----.";
case ".": break;
return ".-.-.-"; case ".":
break; return ".-.-.-";
case ",": break;
return "--..--"; case ",":
break; return "--..--";
case "?": break;
return "..--.."; case "?":
break; return "..--..";
case "'": break;
return ".----."; case "'":
break; return ".----.";
case "!": break;
return "-.-.--"; case "!":
break; return "-.-.--";
case "/": break;
return "-..-."; case "/":
break; return "-..-.";
case "(": break;
return "-.--."; case "(":
break; return "-.--.";
case ")": break;
return "-.--.-"; case ")":
break; return "-.--.-";
case "&": break;
return ".-..."; case "&":
break; return ".-...";
case ":": break;
return "---..."; case ":":
break; return "---...";
case ";": break;
return "-.-.-."; case ";":
break; return "-.-.-.";
case "=": break;
return "-...-"; case "=":
break; return "-...-";
case "+": break;
return ".-.-."; case "+":
break; return ".-.-.";
case "-": break;
return "-....-"; case "-":
break; return "-....-";
case "_": break;
return "..--.-"; case "_":
break; return "..--.-";
case "$": break;
return "...-..-"; case "$":
break; return "...-..-";
case "@": break;
return ".--.-."; case "@":
break; return ".--.-.";
case '"': break;
return ".-..-."; case '"':
break; return ".-..-.";
default: break;
return ""; default:
break; return "";
} break;
}
} }
?> ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment