grid.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:OpenHWControl 作者: kusti8 项目源码 文件源码
def set_fan(ser, fan, voltage, lock):
    """Sets voltage of a specific fan.
    Note:
        The Grid only supports voltages between 4.0V and 12.0V in 0.5V steps (e.g. 4.0, 7.5. 12.0)
        Configuring "0V" stops a fan.
    """

    # Valid voltages and corresponding data (two bytes)
    speed_data = {0:    [0x00, 0x00],  # 0%     (Values below 4V is not supported by the Grid, fans will be stopped)
                  4.0:  [0x04, 0x00],  # 33.3%  (4.0V)
                  4.5:  [0x04, 0x50],  # 37.5%  (4.5V)
                  5.0:  [0x05, 0x00],  # 41.7%  (5V)
                  5.5:  [0x05, 0x50],  # 45.8%  (5.5V)
                  6.0:  [0x06, 0x00],  # 50.0%  (6V)
                  6.5:  [0x06, 0x50],  # 54.2%  (6.5V)
                  7.0:  [0x07, 0x00],  # 58.3%  (7V)
                  7.5:  [0x07, 0x50],  # 62.5%  (7.5V)
                  8.0:  [0x08, 0x00],  # 66.7%  (8V)
                  8.5:  [0x08, 0x50],  # 70.1%  (8.5V)
                  9.0:  [0x09, 0x00],  # 75.0%  (9.0V)
                  9.5:  [0x09, 0x50],  # 79.2%  (9.5V)
                  10.0: [0x0A, 0x00],  # 83.3%  (10.0V)
                  10.5: [0x0A, 0x50],  # 87.5%  (10.5V)
                  11.0: [0x0B, 0x00],  # 91.7%  (11.0V)
                  11.5: [0x0B, 0x50],  # 95.8%  (11.5V)
                  12.0: [0x0C, 0x00]}  # 100.0% (12.0V)

    fan_data = {1: 0x01,  # Fan 1
                2: 0x02,  # Fan 2
                3: 0x03,  # Fan 3
                4: 0x04,  # Fan 4
                5: 0x05,  # Fan 5
                6: 0x06}  # Fan 6

    # Define bytes to be sent to the Grid for configuring a specific fan's voltage
    # Format is seven bytes:
    # 44 <fan id> C0 00 00 <voltage integer> <voltage decimal>
    #
    # Example configuring "7.5V" for fan "1":
    # 44 01 C0 00 00 07 50
    serial_data = [0x44, fan_data[fan], 0xC0, 0x00, 0x00, speed_data[voltage][0], speed_data[voltage][1]]

    try:
        with lock:
            bytes_written = ser.write(serial.to_bytes(serial_data))
            time.sleep(WAIT_GRID)

            # TODO: Check reponse
            # Expected response is one byte
            response = ser.read(size=1)
            print("Fan " + str(fan) + " updated")
    except Exception as e:
        helper.show_error("Could not set speed for fan " + str(fan) + ".\n\n"
                          "Please check settings for serial port " + str(ser.port) + ".\n\n"
                          "Exception:\n" + str(e) + "\n\n"
                          "The application will now exit.")
        sys.exit(0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号