File source
<?php
include "Port.php";
include "NetPort.php";
include "Img.php";
include "Screen.php";
include "ScreenManager.php";
include "Weather.php";
include "HomeScreen.php";
include "WeatherMetar.php";
include 'TestScreen.php';
include 'WeatherSource.php';
include 'Shmu.php';
include "CalendarSource.php";
include "GarageSource.php";
include "Garage.php";
include "db.php";
//$com = new NetPort("10.0.0.2", 1234);
$com = new NetPort("192.168.88.1", 1234);
$com->open();
declare(ticks = 1);
function sig_handler($signo)
{
global $com;
switch ($signo) {
case SIGTERM:
// handle shutdown tasks
$com->close();
exit;
break;
case SIGHUP:
// handle
break;
default:
// handle all other signals
}
}
// setup signal handlers
if(function_exists("pcntl_signal")){
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
}else{
echo "Signal handlers not registered! \n";
}
/* init screens */
$weather = new Shmu("TN");
$calendar = new CalendarSource();
$gs = new GarageSource();
$w = new WeatherScreen($weather);
$t = new TestScreen();
$home = new HomeScreen($weather, $calendar, $gs);
$garage = new GarageScreen($gs);
/* init screen manager, register screens */
$sm = new ScreenManager($com);
$sm->register($w);
$sm->register($t);
$sm->register($home);
$sm->register($garage);
$sm->activate("home");
/* Sisyphus loop */
while(true){
$sm->work();
}
$com->close();
/** reads from file/stream, non-blocking
* returns false on error
*/
function non_block_read($fd, &$data) {
$read = array($fd);
$write = array();
$except = array();
$result = stream_select($read, $write, $except, 0);
if($result === false) throw new Exception('stream_select failed');
if($result === 0) return false;
$data = stream_get_line($fd, 1);
return true;
}