1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JarvisPHP\Plugins\RaspPIVolume_plugin; |
4
|
|
|
|
5
|
|
|
use JarvisPHP\Core\JarvisSession; |
6
|
|
|
use JarvisPHP\Core\JarvisPHP; |
7
|
|
|
use JarvisPHP\Core\JarvisLanguage; |
8
|
|
|
use JarvisPHP\Core\JarvisTTS; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* RaspberryPI Volume Control Plugin |
12
|
|
|
* @author Stefano Bianchini |
13
|
|
|
* @website http://www.stefanobianchini.net |
14
|
|
|
* Bash script from http://www.dronkert.net/rpi/vol.html |
15
|
|
|
*/ |
16
|
|
|
class RaspPIVolume_plugin implements \JarvisPHP\Core\JarvisPluginInterface{ |
17
|
|
|
/** |
18
|
|
|
* Priority of plugin |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
var $priority = 1; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* the behaviour of plugin |
25
|
|
|
* @param string $command |
26
|
|
|
*/ |
27
|
|
|
function answer($command) { |
|
|
|
|
28
|
|
|
$answer = ''; |
|
|
|
|
29
|
|
|
|
30
|
|
|
if(preg_match(JarvisLanguage::translate('preg_match_mute',get_called_class()), $command)) { |
31
|
|
|
//Mute command |
32
|
|
|
exec(_JARVISPHP_ROOT_PATH.'/Plugins/RaspPIVolume_plugin/vol.sh 0'); |
33
|
|
|
} else if(preg_match(JarvisLanguage::translate('preg_match_unmute',get_called_class()), $command)) { |
34
|
|
|
//Unmute command |
35
|
|
|
exec(_JARVISPHP_ROOT_PATH.'/Plugins/RaspPIVolume_plugin/vol.sh 65'); |
36
|
|
|
} else if(preg_match(JarvisLanguage::translate('preg_match_volume_up',get_called_class()), $command)) { |
37
|
|
|
//Volume up command |
38
|
|
|
exec(_JARVISPHP_ROOT_PATH.'/Plugins/RaspPIVolume_plugin/vol.sh +'); |
39
|
|
|
} else if(preg_match(JarvisLanguage::translate('preg_match_volume_down',get_called_class()), $command)) { |
40
|
|
|
//Volume down |
41
|
|
|
exec(_JARVISPHP_ROOT_PATH.'/Plugins/RaspPIVolume_plugin/vol.sh -'); |
42
|
|
|
} |
43
|
|
|
$answer = JarvisLanguage::translate('command_executed',get_called_class()); |
44
|
|
|
$response = new \JarvisPHP\Core\JarvisResponse($answer, JarvisPHP::getRealClassName(get_called_class()), true); |
45
|
|
|
$response->send(); |
46
|
|
|
} |
47
|
|
|
/** |
48
|
|
|
* Get plugin's priority |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
function getPriority() { |
|
|
|
|
52
|
|
|
return $this->priority; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Is it the right plugin for the command? |
57
|
|
|
* @param string $command |
58
|
|
|
* @return boolean |
59
|
|
|
*/ |
60
|
|
|
function isLikely($command) { |
|
|
|
|
61
|
|
|
return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Does the plugin need a session? |
66
|
|
|
* @return boolean |
67
|
|
|
*/ |
68
|
|
|
function hasSession() { |
|
|
|
|
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.