Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help getting it to work #3

Open
onuralpbicer opened this issue Jul 28, 2018 · 28 comments
Open

Need help getting it to work #3

onuralpbicer opened this issue Jul 28, 2018 · 28 comments

Comments

@onuralpbicer
Copy link

Hey, I'm a fellow computer science student, but I don't have too much experience with visual studio nor c++. I was trying to get this working on a MSI x470 Gaming Plus board but I can't seem to get it to work. Could you help if you're still around?

@SimoDax
Copy link
Owner

SimoDax commented Jul 28, 2018

What issue are you facing?

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 28, 2018

So basically when I load your code into visual studio 2017 and try to compile, I get an error saying "Unable to start program '(path-to-folder)\x64\Debug\MSI-mystic-light-tool.exe'. The system can't find the file specified."

I have mystic light 3 installed if that would change anything.

Also in the editor, lots of things are underlined with red lines, starting with the #include "MysticLight_SDK.h"

As I said, I'm not familiar with visual studio. Maybe I made a mistake trying to import the project into the ide? How was I supposed to actually get the project into visual studio?

@SimoDax
Copy link
Owner

SimoDax commented Jul 28, 2018

Theoretically you just need to clone the repo and open the .sln file in visual studio. Anyway, try doing it manually: go to files>new>project. On the left go to Visual C++>Windows desktop and create a new windows console application. Name it MSI-mystic-light-tool. Close visual studio and replace all the .cpp and .h files with the ones on this repo. Copy MysticLight_SDK.dll and MysticLight_SDK.h too. That should do it.
I noticed you're compiling for 64 bit, change it to x86 or it won't load the dll

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 28, 2018

Alright, it is compiling now at least. I'm getting "Function returned status code: Request is complete." and then nothing for a bit. Then I got a Debug Assertion Failed runtime library error in atlsafe.h line 273, expression m_psa != 0. If I don't do anything in that window for a while on the console I get "Function returned status code: MLAPI_Initialize is timeout." And then press any key to continue

I'm guessing that might be because I'm running ML3?

@SimoDax
Copy link
Owner

SimoDax commented Jul 28, 2018

Try running visual studio as administrator, the program will inherit admin rights.
If it doesn't work with that I guess it's ML3 and you need to wait for an update to the sdk from msi. You could try installing mystic light 2 and see what happens

@onuralpbicer
Copy link
Author

Admin rights did work, though the led count is 14966932 so obviously that's wrong, but that should be fine, I'm only trying to make a color cycle effect. I am actually going to try to use logitech's sdk alongside msi's to synchronize my keyboard and mouse with the motherboard.

Actually, as I was typing all this. After I press enter to continue after I see my device id, I get another assertion fail at atlsafe.h at line 199 expression (((HRESULT)(hRes)) >= 0)

@SimoDax
Copy link
Owner

SimoDax commented Jul 28, 2018

That's odd, I don't know what it could be, try looking at the call stack to see what function caused that call. I wouldn't give it much weight tho, as it happens just before the program closes.

As for the led count, I had begun making a user interface with Qt, and this snippet should return the proper value (j):

int j = 1;
BSTR ledName;
CComSafeArray<BSTR> ledStyles;

status = ml.getLedInfo(devices.GetAt(i), (DWORD)j, &ledName, &(ledStyles.m_psa));

while(status == 0){     //try getting led info until there are no more and it fails

                //create a list of led names & styles if you need...

                status = ml.getLedInfo(devices.GetAt(i), (DWORD)j, &ledName, &(ledStyles.m_psa));
                j++;
}

@onuralpbicer
Copy link
Author

I was just typing an edit, that didn't happen again after that time so I guess that's fine. I just tried a setColor just to test if I can use it though but it didn't work. I don't really need styles, I will write the color change myself with increasing/decreasing rgb values(I've already done that for logitech's sdk so I'll just put bunch of setColors).

ml.setColor(devices.GetAt(i), 0, 255, 0, 0);

That was the function call I used, most likely wrong because I have 0 as the second parameter but I'm assuming it should have something else. How would I call that function to set all LED's to the same color?

@SimoDax
Copy link
Owner

SimoDax commented Jul 28, 2018

You can't do it directly, look at the reference:
int MLAPI_SetLedColor(BSTR type, DWORD index, DWORD R, DWORD G, DWORD B)

You need to pass both the device and the led index. which ranges from 1 to how many leds areas are in your device. So you need a loop to call the function for each index

edit:
jugglingcode linked a stub on how to do it days ago, see issue #1

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 28, 2018 via email

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 29, 2018

So I've been trying to play around with it for a bit, but right now if I put any code after the print device type and led count in your sample loop(whether it is in the loop after that line or out of the loop) it just doesn't execute. I even threw in some prints to see if they worked but after your device type print, nothing else happens it just says press any key to continue.

I tired jugglingcode's example as well, I'm still getting the same behavior. I put another print after that print and it worked, but the mlapi function calls after that don't work, and neither do the printStatus functions.

"Exception thrown at 0x00000000 in MSI-mystic-light-tool.exe: 0xC0000005: Access violation executing location 0x00000000." is what I'm getting in the debugger when I try to call setColor after getting device info stuff.

@SimoDax
Copy link
Owner

SimoDax commented Jul 29, 2018

I even threw in some prints to see if they worked but after your device type print, nothing else happens it just says press any key to continue

Seems like it runs the old code instead of compiling the new one. Have you tried cleaning and rebuilding the solution?

"Exception thrown at 0x00000000 in MSI-mystic-light-tool.exe: 0xC0000005: Access violation executing location 0x00000000." is what I'm getting in the debugger when I try to call setColor after getting device info stuff.

Put your code on gist or pastebin, I can't understand what you did

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 29, 2018

I'm uploading everything to git at https://github.com/onuralpbicer/mystic-light-sdk-test I haven't really done almost any changes to the code anyways, I just added a setColor.

Just to add, when I run with ctrl+f5, it doesn't give an error it just doesn't do anything after the initialization and getDevInfo. When I run it with the windows debugger button, it breaks with an exception at the first mlapi function I try to call(i've tried different functions too) after getDevInfo.

@SimoDax
Copy link
Owner

SimoDax commented Jul 29, 2018

You forgot to initialize the aditional pointers to the mystic light functions. By default they have a NULL value, which is a C macro for 0, which is a forbidden memory address, resulting in an access violation.

Add the initialization in loadLib(), my stub only used init, errorMsg and getDevInfo so you'll want to add at least
ml.setColor = (LPMLAPI_SetLedColor)GetProcAddress(MLinstance, "MLAPI_SetLedColor");

@onuralpbicer
Copy link
Author

Ohhhhh, that makes a lot of sense. I'll try that in a bit.

@onuralpbicer
Copy link
Author

Alright, when I did that looks like everything is working. Though, I was still getting an exception because of the safearrays when the program quits, and I figured out why that happened. You need to add the following code to the end of the program before you exit.

SafeArrayDestroy(devices);
devices.m_psa = NULL;
SafeArrayDestroy(ledCount);
ledCount.m_psa = NULL;

I should be able to figure out the rest of the stuff and get it working with Logitech's sdk too to get both devices synched up. Thanks a lot!

@onuralpbicer
Copy link
Author

Another little snag, everything about what you've written is working and the sdk is working properly, but my board can apparently only have 7 colors, even in sdk. So I either need to figure out a way to make it show more colors which I'd assume isn't possible, or I have to make it kind of a breathing effect when changing colors. The problem with that is, this motherboard also doesn't support setLedBright function. Do you have any idea how I could try to implement an effect like that?

@SimoDax
Copy link
Owner

SimoDax commented Jul 29, 2018

Oh, wow, even the SDK is locked. Just MSI bullshit, I'm not buying again from them. I too have only 7 colors in Mystic Light, but if I change the file that ML uses to remember the last led color it was set to I can arbitrarily choose a color, and it works perfectly. It's not that your hardware can't do it, they block it via software. I'm sorry you're in the same boat. I have no idea how to solve this.

@onuralpbicer
Copy link
Author

onuralpbicer commented Jul 29, 2018

Hmm, if I could make it arbitrarily choose a color with 0-255 rgb values that would actually be perfect for me, since that's what I already do with my logitech sdk anyways. So do you mean that's doable or not doable?

If not, I'm experimenting with breathing animations and stuff, maybe I can at least sync the color changes with the brightness going down in that setting, and then time the keyboard color change accordingly too.

Edit: The breathing thing isn't working since I have no way of knowing when the led's are on and when they're off in the software, since because the function isn't supported, getBright still returns 103(which is max) even when the led's are turned off...

Edit 2: I turned the project from a console application to a Win32 application, but I can't run my exe in the debug folder for some reason...

@SimoDax
Copy link
Owner

SimoDax commented Jul 29, 2018

Here's the method I use (scroll down), but it takes A LOT because you need to close mystic light and wait for it to open again, so it's not doable unless you want a static color: https://forum-en.msi.com/index.php?topic=294645.0

I guess your last resort is buying a proper rgb driver to connect the cooler lights to..

Edit 2: I turned the project from a console application to a Win32 application, but I can't run my exe in the debug folder for some reason...

That's for creating visual interfaces with buttons etc. So it won't run unless you make an UI, which is pretty difficult and frustrating to do using Visual C++. I suggest you stay away from that :)

@onuralpbicer
Copy link
Author

I see. Ohhh really? I was researching a bit online i thought it could be used to have an app without the console. How can I do that then?

@onuralpbicer
Copy link
Author

So I just discovered something. In mystic light 2 yes I am stuck to only 7 colors, however in mystic light 3, I can choose any 0-255 r, g, b values in the software. How could I get that functionality in the sdk too? Would ml3 maybe have a new dll file?

@SimoDax
Copy link
Owner

SimoDax commented Jul 31, 2018

I honestly don't know, the sdk hasn't been update since last year. Try issuing a ticket to msi support.
That's further proof of their seriousness.

@onuralpbicer
Copy link
Author

Hey, it's me again. It's been a while, and I've been corresponding with msi for a bit. Apparently, since the chip on my specific motherboard does not support more than 7 colors, so they said the functionality of setting your own colors on the mystic light software currently is there by accident and will be removed. After about 10 updates to mystic light 3 it's still there though so I don't know if they'll actually remove it.

They also said they will add support to brightness changing, since they use it for the breathing animation so chip clearly does support that feature. Now since those emails, there has been a bunch of updates to mystic light, almost all of which saying "Modify LED control method". I was thinking maybe they actually have added the support, but I don't know how to check if the SDK has been updated. How do I do it?

@SimoDax
Copy link
Owner

SimoDax commented Sep 23, 2018

Sorry, but I'm missing something here: you said that with Mystic Light 3 you can set an arbitrary color, but once you apply it does it actually work on the leds? Or it just sets whichever of the 7 colors is closer?

Checking the SDK is very simple, just download it and look at when the files have been created. It still says 2017-08-19

@onuralpbicer
Copy link
Author

onuralpbicer commented Sep 23, 2018 via email

@SimoDax
Copy link
Owner

SimoDax commented Sep 24, 2018

The link is in the project description (https://msi.com/Landing/mystic-light-motherboard#extension), just scroll down till you see the download button.
Anyway, since the rgb led is controlled with just three square waves with a variable duty cycle (based on how bright you want eanch R G and B color) it means that the chip is actually capable of generating a square wave, it just needs some tuning. 7 colors is what you get if you can't generate any wave at all and you just toggle each color on or off. So their saying that it's not supported sounds like a big shortcut to avoid investing time into it

@erkr
Copy link

erkr commented May 9, 2020

Hi all
I found out that setting the LedStyle to L"Steady" on my MSI B360 gaming plus boards resolves two issues:
The Set Color method doesn't return error -103 anymore (it did when the style is L"Default")
Free to set any RGB color combination I like
Code:
BSTR newStyle = ::SysAllocString(L"Steady"); status = ml.setStyle(devices.GetAt(0), 0, newStyle); ::SysFreeString(newStyle);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants