nagisa / msi-rgb

Linux utility for controlling RGB header on select MSI motherboards
ISC License
418 stars 40 forks source link

CPU temp mode (far better than windows one) and pulsing when not told to. #102

Closed bpiero closed 1 year ago

bpiero commented 4 years ago

My MB (mortar max) was sometimes turning mad and pulsing when not told to, and I noticed that it can't be stopped ( sudo ./target/release/msi-rgb FFFFFFFF FFFFFFFF FFFFFFFF --disable ). I suspected that there should be some kind of memory that wasn't flushed, so I did reboot under windows and I turned off the lights in Mystic Light, reboot under linux and it solved the issue.

Now that's working well (excepted that I have to use -ir -ig -ib, I was thinking it was related to my color blindness), I wanted to share a small python script. It's made from the example of the readme "Hue wheel", feel free to test and improve (I don't know well python).

First of all, you'll need to find your CPU temperature sensor (I don't know if lm-sensors is needed). Mine is /sys/class/hwmon/hwmon0/temp7_input but your one can be another and in another place. You may find it with the help of cat /sys/class/hwmon/hwmon0/temp1_label and cat /sys/class/hwmon/hwmon0/temp2_input (no, your computer is not burning, 32 000 is 32°C), testing temp1, temp2, temp3... until you have the good one (or you can monitor your chipset or MB temperature if you want).

You have also to copy msi-rgb to /usr/local/bin/ ( sudo cp ./target/release/msi-rgb /usr/local/bin/ ), or change the path in the script.

Now create the script ( sudo gedit /usr/local/sbin/tCPUtoRGBleds.py ), and copy/paste:

import colorsys, time, subprocess
while True:
  file=open('/sys/class/hwmon/hwmon0/temp7_input', 'r')
  subprocess.call(['/usr/local/bin/msi-rgb', '-p'] + list(map(lambda x: ('{0:01x}'.format(int(15*x)))*8, colorsys.hsv_to_rgb((0.6667-float(file.readline())*0.00001111)%1, 1, 1))))
  file.close()
  time.sleep(0.2)

You may change the temp7_input with your one, and if you have a flipping colors MB like I have, change ['/usr/local/bin/msi-rgb', '-p'] with ['/usr/local/bin/msi-rgb', '-ir', '-ig', '-ib', '-p']. Save, close, run the script: sudo python /usr/local/sbin/tCPUtoRGBleds.py, and enjoy.

The script like it is should be tuned with everyone's needs, it's blue at 0°C, cyan at 15, green at 30 (idle), yellow at 45, orange at 52.5, red at 60, and become magenta after. But if you're an Eskimo, a Tuareg, or an overclocker, you may want to tune it for your needs. 0.6667 is the 0° color (blue) colors, it's the hue property between 0 and 1 (if you want green at 0° it's 0.3333). To calculate the second value (0.00001111), you have to divide the first by the red color temperature you want (X1000), so if you want green at 0° and red at 70°, you'll do 0.3333/70 000 = 0.000004762

If you want that the script launch each time you boot, here's how to do on debian 10, you should use your distribution's specific way.

Create a script (sudo gedit /etc/init.d/tCPUtoRGBleds), and copy/paste:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          tCPUtoRGBleds
# Required-Start:    msi-rgb, lm-sensors
# Required-Stop:     
# Default-Start:     S
# Default-Stop:      
# Short-Description: tCPUtoRGBleds
# Description:       change leds color for CPU temperature monitoring
### END INIT INFO

case "$1" in
  start)
    echo "Starting tCPUtoRGBleds"
    python /usr/local/sbin/tCPUtoRGBleds.py &
    ;;
  stop)
    echo "Stopping tCPUtoRGBleds"
    killall python
    /usr/local/bin/msi-rgb FFFFFFFF FFFFFFFF FFFFFFFF --disable
    ;;
  *)
    echo "Usage: /etc/init.d/tCPUtoRGBleds{start|stop}"
    exit 1
    ;;
esac

exit 0

Save and close, chmod it: chmod 755 /etc/init.d/tCPUtoRGBleds, create symlinks debian way: sudo update-rc.d tCPUtoRGBleds start 60 S . test: sudo /etc/init.d/tCPUtoRGBleds stop and sudo /etc/init.d/tCPUtoRGBleds start. You can reboot to test and enjoy!

cgs-labs commented 4 years ago

I tried your script with the inverts -ir -ig -ib, but for my Mortar Max B450M everything stays black.

Thanks for inspiration anyway. I just hacked something to get the few colour we got to work on my Mortar Max B450M.

import time
import subprocess

def reset_colors():
    subprocess.run(['/usr/bin/msi-rgb', 'FFFFFFFF', 'FFFFFFFF', 'FFFFFFFF', '--disable'])

def set_red():
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ig', '-ib'])

def set_blue():                                             
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ir', '-ig'])

def set_green():                                            
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ir', '-ib'])

def set_cyan():                                             
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ir'])

def set_purple():                                           
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ig'])

def set_yellow():                                           
    subprocess.run(['/usr/bin/msi-rgb', '0', '0', '0', '-p', '-ib'])

def cpuTemp2Color():

    reset_colors()

    while True:
        file=open('/sys/class/hwmon/hwmon0/temp1_input', 'r')
        temp = float(file.readline())/1000.0
        file.close()

        if temp<35.0:
            set_blue()
        elif temp<40.0:
            set_cyan()
        elif temp<45.0:
            set_green()
        elif temp<50.0:
            set_yellow()
        elif temp<60.0:
            set_red()
        elif temp>=75.0:
            set_purple();

        time.sleep(2)

cpuTemp2Color()

A few colours is better than nothing. The yellow is only a bit a lighter green, but anyway.

Cheers, Chris

bpiero commented 4 years ago

Awesome! I love that state of mind: "it doesn't work, it'll work anyway!" Did you tried the example of the readme "Hue wheel"? Does it work? For me the msi-rgb doesn't work anymore, I don't know why. I'll try to found the time to search why.

cgs-labs commented 4 years ago

Yes I tried the Hue-Wheel. It does change the colours, somehow. Even when I kill python it keeps changing colours :-) in a weird way.

The thing is that these chips contain some kind of microcontroller that changes the colour. msi-rgb just configures the settings. Now this is a new, proprietary chip, where some configuration registers have changed compared to the known ones. Some settings still work, like the invert und the pulsing, but the rest is just try and error.

It would be good if somebody would reverse engineer what the windows tool does. Ideally MSI should publish the docs.

bpiero commented 4 years ago

Chris, I got the same MB, and my script was working before. I'll try your's, but I'm quite sure it will work. What I don't understand is why mine doesn't anymore, and why it doesn't work at all for you. I guess python didn't change neither msi-rgb. It may be related to recent kernel changes maybe the chip module. I'll work on it tomorrow, can you tell me which kernel do you use?

bpiero commented 4 years ago

Ok it's now reworking. I just rebooted to windows (it still stayed black), tried mystic light (I tried the cpu temp mode, but a Hue-Wheel was working instead). I guess I was becoming as silly as this light system, when I remembered that I tried the msi-rgb for windows (with a Hue-Wheel). I turned off the lights in Mystic Light and in msi-rgb for windows, it was still lighting anyway. I rebooted to linux, it was still working anyway (with the Hue-Wheel). Then when it finished booting, my script did rework automatically. I guess it's a kind of memory in the microcontroller, that they can reach in windows. Do you have a dual boot? If yes do you tried Mystic Light or msi-rgb for windows?

cgs-labs commented 4 years ago

I don't have Windows on this box, so I am sorry I can't try that. I am using Arch Linux here so this should be some recent Linux stuff. Kernel here 5.6.11 and 5.4.39.

I wonder if the Windows tools configure something that is stored in the chip, so it works after a reboot.

bpiero commented 4 years ago

Yes, that's exactly what I've seen. But you shouldn't be concerned because you don't have windows. My kernel is the 5.4.0, so I guess your one should not be faulty. I can't understand why my script doesn't work for you, if your script and the hue wheel work, can you retry?

cgs-labs commented 4 years ago

I think there was a misunderstanding. The hue-wheel does not work for me.

It changes colours yes, but not in a way a hue wheel does. It is mostly white, with some pulses of other colours, but it is not a hue-wheel.

bpiero commented 4 years ago

You can try a clear CMOS, and/or bios upgrade...