Commit b40f5522 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) spaces and curly braces in led.inc

parent 05456e7d
...@@ -11,7 +11,8 @@ $led_root = "/dev/led/led"; ...@@ -11,7 +11,8 @@ $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; global $led_root;
if (led_exists($led)) { if (led_exists($led)) {
exec("/bin/echo " . escapeshellarg($str) . " > {$led_root}{$led}"); exec("/bin/echo " . escapeshellarg($str) . " > {$led_root}{$led}");
...@@ -25,7 +26,8 @@ function led_ctl($led, $str) { ...@@ -25,7 +26,8 @@ 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 with a . to stop after one iteration. */
$end = $repeat ? "" : "."; $end = $repeat ? "" : ".";
return led_ctl($led, "s{$pattern}{$end}"); return led_ctl($led, "s{$pattern}{$end}");
...@@ -34,7 +36,8 @@ function led_pattern($led, $pattern, $repeat=true) { ...@@ -34,7 +36,8 @@ function led_pattern($led, $pattern, $repeat=true) {
/* /*
* 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));
} }
...@@ -42,14 +45,16 @@ function led_morse($led, $message) { ...@@ -42,14 +45,16 @@ function led_morse($led, $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");
} }
...@@ -72,15 +77,17 @@ function led_count() { ...@@ -72,15 +77,17 @@ function led_count() {
*/ */
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(1, 'AaaaaA');
led_pattern(2, 'aAaaAa'); led_pattern(2, 'aAaaAa');
led_pattern(3, 'aaAAaa'); led_pattern(3, 'aaAAaa');
...@@ -89,7 +96,8 @@ function led_kitt() { ...@@ -89,7 +96,8 @@ function led_kitt() {
/* /*
* Custom pattern for assigning interfaces * Custom pattern for assigning interfaces
*/ */
function led_assigninterfaces() { function led_assigninterfaces()
{
led_pattern(1, 'AaaAaaaaaaaaaaaa'); led_pattern(1, 'AaaAaaaaaaaaaaaa');
led_pattern(2, 'aaaaaAaaAaaaaaaa'); led_pattern(2, 'aaaaaAaaAaaaaaaa');
led_pattern(3, 'aaaaaaaaaaAaaAaa'); led_pattern(3, 'aaaaaaaaaaAaaAaa');
...@@ -98,7 +106,8 @@ function led_assigninterfaces() { ...@@ -98,7 +106,8 @@ function led_assigninterfaces() {
/* /*
* 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_on(1);
led_off(2); led_off(2);
led_off(3); led_off(3);
...@@ -108,7 +117,8 @@ function led_normalize() { ...@@ -108,7 +117,8 @@ function led_normalize() {
* 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; $i = 0;
$morsestring = ""; $morsestring = "";
while ($i < strlen($string)) { while ($i < strlen($string)) {
...@@ -121,7 +131,8 @@ function str_to_morse($string) { ...@@ -121,7 +131,8 @@ function str_to_morse($string) {
* 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)) { switch (strtoupper($char)) {
case "A": case "A":
return ".-"; return ".-";
......
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