diff options
| -rwxr-xr-x | main.py | 22 | 
1 files changed, 15 insertions, 7 deletions
@@ -66,21 +66,27 @@ class TempCurve:          (low_temp, low_speed) = self.points[lower]          (high_temp, high_speed) = self.points[lower + 1] -        return floor(low_speed + (((temp - low_temp) / (high_temp - low_temp)) * (high_speed - low_speed))) +        coefficient = (temp - low_temp) / (high_temp - low_temp) +        value = low_speed + (coefficient * (high_speed - low_speed)) + +        return floor(value) +  def read_curves(path: str) -> [TempCurve]: +    def read_points(obj): +        return [(i["temp"], i["speed"]) for i in obj["curve"]]      curves = []      with open(path, "r") as fp:          json = load(fp) -        for obj in json: -            curves.append(TempCurve(obj["sensor"], obj["channel"], -                                    [(i["temp"], i["speed"]) -                                     for i in obj["curve"]])) +        curves = [ +            TempCurve(obj["sensor"], obj["channel"], read_points(obj)) +            for obj in json +        ]      return curves  def compile_unisync(curves: [TempCurve]): -    # Setup the version of curves we want +    # Compile curves into something to fit into the uni-sync config      indexed_curves = dict()      for curve in curves:          indexed_curves[curve.channel] = curve.current_speed @@ -93,6 +99,8 @@ def compile_unisync(curves: [TempCurve]):      current_config = None      with open(UNI_SYNC_FILEPATH, "r") as fp:          current_config = load(fp) + +    # inject compiled_curves into the configuration      current_config["configs"][0]["channels"] = compiled_curves      return current_config @@ -102,7 +110,7 @@ def run_unisync():  if __name__ == '__main__':      curves = read_curves(PROFILE_FILEPATH)      for curve in curves: -        print(f"Channel [{curve.channel}]: Sensor={curve.sensor} => Speed={curve.current_speed} based on {curve.current_temp}") +        print(f"[{curve.channel}] {curve.sensor}: {curve.current_temp}°C => {curve.current_speed}%")      new_config = compile_unisync(curves)      with open(UNI_SYNC_FILEPATH, "w") as fp:          dump(new_config, fp)  | 
