-
Notifications
You must be signed in to change notification settings - Fork 0
/
roomba.php
60 lines (44 loc) · 1.13 KB
/
roomba.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class roomba
{
/**
* @var Serial
*/
protected $connection;
public function run()
{
$this->connect();
$this->initialize();
$time = time();
$endTime = $time + 15;
$response = '';
$sum = 0;
while ($time < $endTime) {
$this->connection->send_data([142, 100]);
$line = $this->connection->get_binary(80);
for ($i = 0; $i < strlen($line); $i++) {
$response .= ord($line[$i]) . ' ';
$sum++;
if ((($i + 1) % 16 == 0) || ($i + 1 == strlen($line))) {
$response .= PHP_EOL;
}
}
cOut($response);
$response = '';
$time = time();
usleep(500000);
}
cOut($sum);
$this->connection->close();
}
protected function initialize()
{
//initialize Roomba interface
$this->connection->send_data(128);
}
protected function connect()
{
$this->connection = new serial('/dev/ttyS1', 19200);
$this->connection->open();
}
}