1# Copyright 2014-2015 ARM Limited 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15 16 17from devlib.module import Module 18from devlib.utils.serial_port import open_serial_connection 19 20 21class MbedFanActiveCoolingModule(Module): 22 23 name = 'mbed-fan' 24 timeout = 30 25 26 @staticmethod 27 def probe(target): 28 return True 29 30 def __init__(self, target, port='/dev/ttyACM0', baud=115200, fan_pin=0): 31 super(MbedFanActiveCoolingModule, self).__init__(target) 32 self.port = port 33 self.baud = baud 34 self.fan_pin = fan_pin 35 36 def start(self): 37 with open_serial_connection(timeout=self.timeout, 38 port=self.port, 39 baudrate=self.baud) as target: 40 target.sendline('motor_{}_1'.format(self.fan_pin)) 41 42 def stop(self): 43 with open_serial_connection(timeout=self.timeout, 44 port=self.port, 45 baudrate=self.baud) as target: 46 target.sendline('motor_{}_0'.format(self.fan_pin)) 47 48 49class OdroidXU3ctiveCoolingModule(Module): 50 51 name = 'odroidxu3-fan' 52 53 @staticmethod 54 def probe(target): 55 return target.file_exists('/sys/devices/odroid_fan.15/fan_mode') 56 57 def start(self): 58 self.target.write_value('/sys/devices/odroid_fan.15/fan_mode', 0, verify=False) 59 self.target.write_value('/sys/devices/odroid_fan.15/pwm_duty', 255, verify=False) 60 61 def stop(self): 62 self.target.write_value('/sys/devices/odroid_fan.15/fan_mode', 0, verify=False) 63 self.target.write_value('/sys/devices/odroid_fan.15/pwm_duty', 1, verify=False) 64