Class: Pifan::Process
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(parameters) ⇒ Process
constructor
A new instance of Process.
- #start ⇒ Object
Methods included from Logging
Constructor Details
#initialize(parameters) ⇒ Process
Returns a new instance of Process.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pifan/process.rb', line 11 def initialize(parameters) @control_pin = parameters[:control_pin] @refresh_time = parameters[:refresh_time] @pwm_frequency = parameters[:pwm_frequency] @temp_steps = parameters[:temperature_steps] @speed_steps = parameters[:speed_steps] RPi::GPIO.set_numbering :bcm RPi::GPIO.setup @control_pin, as: :output, initialize: :low @fan = RPi::GPIO::PWM.new(@control_pin, @pwm_frequency) @fan.start(0) end |
Instance Method Details
#cleanup ⇒ Object
52 53 54 |
# File 'lib/pifan/process.rb', line 52 def cleanup RPi::GPIO.clean_up end |
#start ⇒ Object
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 |
# File 'lib/pifan/process.rb', line 24 def start hyst = 1 cpu_temp_old = 0 fan_speed_old = 0 # Run at full speed for 2 secs to avoid not starting at small speed @fan.duty_cycle = 100 sleep 2 loop do cpu_temp_current = cpu_temp logger.debug("New temperature: #{cpu_temp_current}") if (cpu_temp_current - cpu_temp_old).abs > hyst fan_speed_current = fan_speed if fan_speed_current != fan_speed_old logger.debug("New fan speed: #{fan_speed_current}") @fan.duty_cycle = fan_speed_current fan_speed_old = fan_speed_current end cpu_temp_old = cpu_temp_current end sleep @refresh_time end end |