Skip to content

Commit

Permalink
Merge pull request #65 from mengmeet/dev
Browse files Browse the repository at this point in the history
Fix GPD devices with oxpec
  • Loading branch information
honjow authored Mar 25, 2024
2 parents 6d14ce8 + 6ed0450 commit 8b8fc6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
6 changes: 2 additions & 4 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,14 @@
},
"pwm_write":{
"pwm_write_max":{
"default":255,
"ONEXPLAYER F1":255,
"ONEXPLAYER F1 EVA-01":255
"default":255
},
"pwm_write_path":"pwm1"
},
"pwm_input":{
"hwmon_label":"oxpec",
"pwm_read_path":"fan1_input",
"pwm_read_max": 5030
"pwm_read_max": 6000
},
"temp_mode":0
}],
Expand Down
10 changes: 5 additions & 5 deletions backend/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def set_cpuTDP(self, value: int):

command = f"{sys_ryzenadj_path} -a {stapm_limit} -b {fast_minit} -c {slow_limit} -f {tctl_temp}"
command_args = command.split()
logging.info(f"set_cpuTDP command: {command}")
logging.info(f"set_cpuTDP {value}")
logging.debug(f"set_cpuTDP command: {command}")
logging.debug(f"set_cpuTDP {value}")
process = subprocess.run(command_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.stdout.decode('utf-8'), process.stderr.decode('utf-8')
logging.info(f"set_cpuTDP result:\n{stdout}")
logging.debug(f"set_cpuTDP result:\n{stdout}")
if stderr:
logging.error(f"set_cpuTDP error:\n{stderr}")

Expand All @@ -145,7 +145,7 @@ def set_cpuTDP(self, value: int):

def set_cpuOnline(self, value: int):
try:
logging.info("set_cpuOnline {} {}".format(value,cpu_maxNum))
logging.debug("set_cpuOnline {} {}".format(value,cpu_maxNum))
global enable_cpu_num
enable_cpu_num = value

Expand All @@ -167,7 +167,7 @@ def set_cpuOnline(self, value: int):
#
# cpu_num 作为索引, 取出对应的核心, 作为开启的最大 cpuid, 关闭大于最大 cpuid 的线程
max_enable_cpuid = self.cps_ids[enable_cpu_num - 1]
logging.info(f"enable_cpu_num {enable_cpu_num}, max_enable_cpuid {max_enable_cpuid}")
logging.debug(f"enable_cpu_num {enable_cpu_num}, max_enable_cpuid {max_enable_cpuid}")
if enable_cpu_num is not None and enable_cpu_num < len(enabled_cores):
for processor_id, core_id in cpu_topology.items():
if int(core_id) > max_enable_cpuid:
Expand Down
14 changes: 13 additions & 1 deletion backend/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse_fan_configuration(self):

#若已获取到风扇hwmon信息则不再获取ec信息
if len(self.fan_config_list) > 0:
logging.debug(f"已获取到风扇hwmon信息:{[config.FAN_HWMON_NAME for config in self.fan_config_list]}")
logging.info(f"已获取到风扇hwmon信息:{[config.FAN_HWMON_NAME for config in self.fan_config_list]}")
else:
logging.debug(f"未获取到风扇hwmon信息,开始获取风扇ec信息")
#转化ec信息
Expand Down Expand Up @@ -287,6 +287,13 @@ def set_fanAuto(self, index:int, value:bool):
return False
else:
fanIsManual = enable_manual_value

# GPD 设备没有实际的单独的控制位。但是在oxpec中有控制位,写入手动控制时会将转速设置为 70%。所以添加判断,只在需要时写入控制位
currentFanIsManual = int(open(hwmon_pwm_enable_path).read().strip())
if currentFanIsManual == fanIsManual:
logging.debug(f"currentFanIsManual:{currentFanIsManual} fanIsManual:{fanIsManual} 无需写入")
return True

open(hwmon_pwm_enable_path,'w').write(str(fanIsManual))
logging.debug(f"写入hwmon数据 写入hwmon地址:{hwmon_pwm_enable_path} 写入风扇是否控制:{fanIsManual}")
return True
Expand Down Expand Up @@ -357,6 +364,11 @@ def set_fanPercent(self, index:int,value:int):
try:
if is_find_hwmon and hwmon_mode == 0:
fanWriteValue = max(min(int(value/100*rpm_write_max),rpm_write_max),0)
currentVal = int(open(hwmon_pwm_path).read().strip())
# 转速相差小于5%时不写入
if currentVal > 0 and abs(currentVal - fanWriteValue) / currentVal < 0.05:
logging.debug(f"当前风扇转速{currentVal} 与目标转速{fanWriteValue} 相差小于5% 不写入")
return True
open(hwmon_pwm_path,'w').write(str(fanWriteValue))
logging.debug(f"写入hwmon数据 写入hwmon地址:{hwmon_pwm_path} 风扇转速百分比{value} 风扇最大值{rpm_write_max} 风扇转速写入值:{fanWriteValue}")
return True
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def get_settings(self):

async def set_settings(self, settings):
self.settings.setSetting(CONFIG_KEY, settings)
logging.info(f"save Settings: {settings}")
# logging.info(f"save Settings: {settings}")
return True

async def _unload(self):
Expand Down

0 comments on commit 8b8fc6b

Please sign in to comment.