Newer
Older
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace App\Subroutines\Fan;
use App\Application;
use App\Concerns\InteractiveConsole;
use App\Model\Fan\HwmonFan;
use App\Service\Utils;
use Hugga\Console;
use Hugga\Input\Question\Choice;
use Hugga\Input\Question\Confirmation;
class EditFan
{
use InteractiveConsole;
/** @var Application */
protected $app;
public function __construct(Application $app, Console $console)
{
$this->app = $app;
$this->console = $console;
}
public function main(HwmonFan $fan)
{
do {
$this->table([$fan->toRow()], ['Name', 'hwmon', 'Fan', 'PWM', 'start', 'max']);
$answer = $this->ask(new Choice([
'rename fan',
'adjust start value',
'define limit',
'done / exit',
], 'What to change?', 'done / exit'));
switch ($answer) {
case 'adjust start value':
$this->warn('Going to stop the fan. If you experience overheating shut stop the application' .
' immediately by hitting ctrl+c');
$speed = $fan->setPwmAndWait(0);
$this->line('at 0 pwm the fan runs at ' . $speed . ' rpm');
$startValue = $this->ask('What value to try?', $fan->getStartValue());
do {
$speed = $fan->setPwmAndWait($startValue);
$this->line('at ' . $startValue . ' pwm the fan runs at ' . $speed . ' rpm');
$answer = $this->ask('Try another value or keep this value?', 'keep');
} while ($answer !== 'keep' && $startValue = $answer);
$fan->resetState();
$fan->setStartValue($startValue);
break;
case 'define limit':
$this->info('Accelerating fan to current limit...');
$maxValue = $fan->getMaxValue();
$startValue = $fan->getStartValue();
do {
$speed = $fan->setPwmAndWait($maxValue);
$this->line('at ' . $maxValue . ' pwm the fan runs at ' . $speed . ' rpm');
$answer = $this->ask(
'Try another value (between ' . $startValue . ' and 255) or keep this value?',
'keep'
);
} while ($answer !== 'keep' && $maxValue = $answer);
$fan->resetState();
$fan->setMaxValue($maxValue);
break;
case 'rename fan':
$name = $this->ask('New name: ', $fan->name);
$fan->name = $name;
break;
case 'done / exit':
return 0;
}
} while (true);
}
}