<?php
class blink1 {
public function __construct() {
// $this->blink1Tool('-m 0 --off');
}
protected function blink1Tool($arg) {
$last_line = system('blink1-tool ' . $arg, $retval);
echo $last_line;
return $retval;
}
protected function rgb($r, $g, $b, $ms = 500) {
$this->blink1Tool("-m {$ms} --rgb {$r},{$g},{$b}");
}
protected function turnOnOne($r1, $g1, $b1, $r2, $g2, $b2, $ms = 500) {
$this->blink1Tool("-l 1 -m {$ms} --rgb {$r1},{$g1},{$b1} && blink1-tool -l 2 -m {$ms} --rgb {$r2},{$g2},{$b2}");
}
private function repeatFlashes($r, $g, $b, $repeat) {
for($i = 0; $i < $repeat; $i++) {
$this->rgb($r, $g, $b);
usleep(500000);
$this->rgb(0, 0, 0);
usleep(500000);
}
}
public function red($repeat = 3) {
$this->repeatFlashes(255, 0, 0, $repeat);
}
public function green($repeat = 3) {
$this->repeatFlashes(0, 255, 0, $repeat);
}
public function blue($repeat = 3) {
$this->repeatFlashes(0, 0, 255, $repeat);
}
public function white($repeat = 3) {
$this->repeatFlashes(255, 255, 255, $repeat);
}
public function yellow($repeat = 3) {
$this->repeatFlashes(255, 255, 0, $repeat);
}
public function purple($repeat = 3) {
$this->repeatFlashes(255, 0, 255, $repeat);
}
public function policecar($repeat = 6) {
for($i = 0; $i < $repeat * 2; $i++) {
$this->turnOnOne(
255, 0, 0,
0, 0, 0,
300
);
usleep(300000);
$this->turnOnOne(
0, 0, 0,
0, 0, 255,
300
);
usleep(300000);
$this->rgb(0, 0, 0, 100);
usleep(100000);
}
}
public function fireengine($repeat = 6) {
for($i = 0; $i < $repeat * 2; $i++) {
$this->turnOnOne(
255, 0, 0,
0, 0, 0,
300
);
usleep(300000);
$this->turnOnOne(
0, 0, 0,
255, 0, 0,
300
);
usleep(300000);
$this->rgb(0, 0, 0, 100);
usleep(100000);
}
}
} |