Exemplo n.º 1
0
 def _send_set_cooling(self):
     assert len(self._fan_names) <= 2, 'cannot yet fit all fan data'
     data = bytearray(_SET_COOLING_DATA_LENGTH)
     data[0: len(_SET_COOLING_DATA_PREFIX)] = _SET_COOLING_DATA_PREFIX
     data[_PROFILE_LENGTH_OFFSET] = _PROFILE_LENGTH
     for fan, (imode, iduty, iprofile) in zip(self._fan_names, _FAN_OFFSETS):
         mode = _FanMode(self._data.load(f'{fan}_mode', of_type=int))
         if mode is _FanMode.FIXED_DUTY:
             stored = self._data.load(f'{fan}_duty', of_type=int, default=100)
             duty = clamp(stored, 0, 100)
             data[iduty] = fraction_of_byte(percentage=duty)
             _LOGGER.info('setting %s to %i%% duty cycle', fan, duty)
         elif mode is _FanMode.CUSTOM_PROFILE:
             stored = self._data.load(f'{fan}_profile', of_type=list, default=[])
             profile = _prepare_profile(stored)  # ensures correct len(profile)
             pairs = ((temp, fraction_of_byte(percentage=duty)) for temp, duty in profile)
             data[iprofile: iprofile + _PROFILE_LENGTH * 2] = itertools.chain(*pairs)
             _LOGGER.info('setting %s to follow profile %r', fan, profile)
         else:
             raise ValueError(f'Unsupported fan {mode}')
         data[imode] = mode.value
     pump_mode = _PumpMode(self._data.load('pump_mode', of_type=int))
     data[_PUMP_MODE_OFFSET] = pump_mode.value
     _LOGGER.info('setting pump mode to %s', pump_mode.name.lower())
     return self._send_command(_FEATURE_COOLING, _CMD_SET_COOLING, data=data)
Exemplo n.º 2
0
    def _generate_cooling_payload(self, fan_names):

        data = bytearray(_SET_COOLING_DATA_LENGTH)
        data[0:len(_SET_COOLING_DATA_PREFIX)] = _SET_COOLING_DATA_PREFIX
        data[_PROFILE_LENGTH_OFFSET] = _PROFILE_LENGTH

        for fan, (imode, iduty, iprofile) in zip(fan_names, _FAN_OFFSETS):
            mode = _FanMode(self._data.load(f'{fan}_mode', of_type=int))
            if mode is _FanMode.FIXED_DUTY:
                stored = self._data.load(f'{fan}_duty',
                                         of_type=int,
                                         default=100)
                duty = clamp(stored, 0, 100)
                data[iduty] = fraction_of_byte(percentage=duty)
                _LOGGER.info('setting %s to %d%% duty cycle', fan, duty)
            elif mode is _FanMode.CUSTOM_PROFILE:
                stored = self._data.load(f'{fan}_profile',
                                         of_type=list,
                                         default=[])
                profile = _prepare_profile(
                    stored)  # ensures correct len(profile)
                pairs = ((temp, fraction_of_byte(percentage=duty))
                         for temp, duty in profile)
                data[iprofile:iprofile +
                     _PROFILE_LENGTH * 2] = itertools.chain(*pairs)
                _LOGGER.info('setting %s to follow profile %r', fan, profile)
            else:
                raise ValueError(f'unsupported fan {mode}')
            data[imode] = mode.value

        return data
Exemplo n.º 3
0
    def _send_set_cooling(self):
        for fan in self._fan_names:
            fanIndex = 0
            if fan == 'fan1':
                fanIndex = 0
            else:
                fanIndex = 1

            mode = _FanMode(self._data.load(f'{fan}_mode', of_type=int))

            if mode is _FanMode.FIXED_DUTY:
                dataPackages =  list()
                stored = self._data.load(f'{fan}_duty', of_type=int, default=100)
                duty = clamp(stored, 0, 100)
                dataPackages.append(self._build_data_package(_COMMAND_FAN_SELECT, _OP_CODE_WRITE_ONE_BYTE, params=bytes([fanIndex])))
                dataPackages.append(self._build_data_package(_COMMAND_FAN_MODE, _OP_CODE_WRITE_ONE_BYTE, params=bytes([mode.value])))
                dataPackages.append(self._build_data_package(_COMMAND_FAN_FIXED_PWM, _OP_CODE_WRITE_ONE_BYTE, params=bytes([fraction_of_byte(percentage=duty)])))
                LOGGER.info('setting %s to %d%% duty cycle', fan, duty)
                self._send_command(dataPackages)

            elif mode is _FanMode.CUSTOM_PROFILE:
                stored = self._data.load(f'{fan}_profile', of_type=list, default=[])
                profile = _prepare_profile(stored)  # ensures correct len(profile)
                pairs = ((temp, fraction_of_byte(percentage=duty)) for temp, duty in profile)

                fanTemperatureData = list()
                fanTemperatureData.append(0x0A) # 'magical' 0x0A in front of curve definition packages
                
                fanDutyData = list()
                fanDutyData.append(0x0A) # 'magical' 0x0A in front of curve definition packages
                
                for temp, duty in profile:
                    fanTemperatureData.append(0x00)
                    fanTemperatureData.append(temp)
                    rpm = duty * _MAX_FAN_RPM / 100
                    fanDutyData.append(int(rpm % 255))
                    fanDutyData.append(int(rpm - (rpm % 255)) >> 8)
                
                # Send temperature profile
                self._send_command([self._build_data_package(_COMMAND_FAN_TEMP_TABLE, _OP_CODE_WRITE_THREE_BYTES, params=bytes(fanTemperatureData))])
                # Send duty cycle Profile
                self._send_command([self._build_data_package(_COMMAND_FAN_RPM_TABLE, _OP_CODE_WRITE_THREE_BYTES, params=bytes(fanDutyData))])

                # Change mode to custom Profile
                dataPackages =  list()
                dataPackages.append(self._build_data_package(_COMMAND_FAN_SELECT, _OP_CODE_WRITE_ONE_BYTE, params=bytes([fanIndex])))
                dataPackages.append(self._build_data_package(_COMMAND_FAN_MODE, _OP_CODE_WRITE_ONE_BYTE, params=bytes([mode.value])))
                self._send_command(dataPackages)

                LOGGER.info('setting %s to follow profile %r', fan, profile)
            else:
                raise ValueError(f'Unsupported fan {mode}')
        
        pump_mode = _PumpMode(self._data.load('pump_mode', of_type=int))
        
        dataPackages =  list()
        dataPackages.append(self._build_data_package(_COMMAND_FAN_SELECT, _OP_CODE_WRITE_ONE_BYTE, params=bytes([_PUMP_INDEX])))
        if pump_mode == _PumpMode.QUIET:
            dataPackages.append(self._build_data_package(_COMMAND_FAN_FIXED_RPM, _OP_CODE_WRITE_TWO_BYTES, params=bytes(_PUMP_DEFAULT_QUIET)))
        elif pump_mode == _PumpMode.EXTREME:
            dataPackages.append(self._build_data_package(_COMMAND_FAN_FIXED_RPM, _OP_CODE_WRITE_TWO_BYTES, params=bytes(_PUMP_DEFAULT_EXTREME)))
        self._send_command(dataPackages)
        
        LOGGER.info('setting pump mode to %s', pump_mode.name.lower())