<?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); } }