@@ -36,9 +36,15 @@ def thermal_get_thresholds(
3636 :param adjust: The adjustment to apply to the temperature. Default is -273 to convert from Kelvin to Celsius.
3737 :return: A list of tuples containing the (warn, high, halt) thresholds.
3838 """
39- data = struct .pack ("<B " , sensor_num )
39+ data = struct .pack ("<I " , sensor_num )
4040 thresh_count : Final = EcTempThresholds .EC_TEMP_THRESH_COUNT .value
41- resp = ec .command (1 , EC_CMD_THERMAL_GET_THRESHOLD , 1 , 4 * thresh_count + 4 * thresh_count + 4 + 4 , data )
41+ resp = ec .command (
42+ 1 ,
43+ EC_CMD_THERMAL_GET_THRESHOLD ,
44+ 4 ,
45+ 4 * thresh_count + 4 * thresh_count + 4 + 4 ,
46+ data ,
47+ )
4248 config = struct .unpack (f"<{ thresh_count } I{ thresh_count } III" , resp )
4349 return {
4450 "temp_host" : [(i + adjust ) for i in config [0 :thresh_count ]],
@@ -50,6 +56,31 @@ def thermal_get_thresholds(
5056 }
5157
5258
59+ def thermal_set_thresholds (
60+ ec : CrosEcClass ,
61+ sensor_num : int ,
62+ config : dict [str , list [int | float ] | int | float ],
63+ adjust : int | float = 273 ,
64+ ) -> None :
65+ """
66+ Set the temperature thresholds for a given sensor.
67+ :param ec: The CrOS_EC object.
68+ :param sensor_num: The sensor number.
69+ :param config: A dictionary containing the threshold configuration.
70+ :param adjust: The adjustment to apply to the temperature. Default is 273 to convert from Celsius to Kelvin.
71+ """
72+ thresh_count : Final = EcTempThresholds .EC_TEMP_THRESH_COUNT .value
73+ data = struct .pack (
74+ f"<I{ thresh_count } I{ thresh_count } III" ,
75+ sensor_num ,
76+ * [int (i + adjust ) for i in config ["temp_host" ]],
77+ * [int (i + adjust ) for i in config ["temp_host_release" ]],
78+ int (config ["temp_fan_off" ] + adjust ),
79+ int (config ["temp_fan_max" ] + adjust ),
80+ )
81+ ec .command (1 , EC_CMD_THERMAL_SET_THRESHOLD , len (data ), 0 , data )
82+
83+
5384EC_CMD_THERMAL_AUTO_FAN_CTRL : Final = 0x0052
5485
5586
0 commit comments