Blinkit | Logitech RGB Keyboard preparation

in #utopian-io6 years ago (edited)

Last week I made a post about the connection between the Logitech LCD and
the Steemit blockchain. Here

A few days ago @techtek presented me his project 'Blinkit' on discord, and he asked me to make it possible to use Logitech Keyboards with RGB Backlight too.

The plan

We talked about how the idea of a flashing keyboard can be integrated into his existing project.
Blinkit itself is written in VB.NET/VBScript. So I had to find a way to get this working.
Here are the things I have used to solve this task:

  • Logitech LED SDK Wrapper.dll You can get it here
  • VB.net as the programming language to create a new .dll
    (I will tell you later why we need another .dll file)
  • VBScript as the final project language
  • Visual Studio Community Edition 2017 Download
  • Notepad ++ Download

The program I created runs by itself, but it is designed to be integrated into the BlinkIt project.

The resulted problem

The problem is that the LogitechLedEnginesWrapper.dll is not coded in a vb.net
compatible format. So if I want to load this DLL in vbs it does not run and gives an error.

dim dll
set dll = CreateObject("LogitechLedEnginesWrapper.dll")

The solution

I created ,in VB.NET, a DLL that imports the functions needed from the Original .dll so VBScript can read the new dll.

To accomplish that follow these steps:

Step 1

  • open Visual Studio 2017 with administrator privileges
  • file -> new Project
  • choose Class Library(.net framework) and give it a name as you like
  • This should now pop up
  • rightclick Class1.vb and delete it
  • Now go to project -> add new item
  • There should pop up a new window:
  • There you choose COM Class and press Add
  • Visual studio created some lines of code for us:

(You can rename the ComClass1 if you like)

At first there is a warning saying:

'Microsoft.VisualBasic.ComClassAttribute' is specified for class 'ComClass1' but 'ComClass1' has no public members that can be exposed to COM; therefore, no COM interfaces are generated.

Don't get confused by that. We will fix it later.

We have set everything up to start coding :D

Step 2

To import native dll files we need to use the System.Runtime.InteropServices library.

  • Import this library in the top of the project
  • Include the attribute as shown in the red box
    After renaming the class and opening the #Region it should look like this:

    The ClassID, InterfaceID and EventsID variable is set by the IDE. Don't change these values.
    We will need the ClassID later.

Step 3

  • Include the code that imports the functions from the Logitech DLL

    We have to specify the correct name of the function in that specific dll like LogiLedInit()
    and the right return value and also the right parameters have to be set. You can get these informations in the
    documentary of the original dll.

Step 4

  • Create a function that make the keyboard flashing in different colors

    The function is called LogiLed and it takes two parameters. The color as a string and the time how long the effect should be played.
    The return value is an integer. See now the error described above is gone :D

Explanation of the function

  • To start the connection with the keyboard we have to initialise the keyboard (line 39)
  • This takes a little while so we put a Sleep function after that (line 40)
  • The Select function chooses which color we want to be shown (line 42)
  • If one case gets executed the LogiLedFlashLighting function gets called (lines 44,47,50)

The function takes 5 parameters:

  • red - percentage of the color red 0-100
  • green - percentage of the color green 0-100
  • blue - percentage of the color blue 0-100
  • time - how long the effect should show up in ms
  • interval - the time between each on/off cycle in ms

If this function gets called the keyboard starts flashing but the programm goes on and does not wait
until the keyboard stopped. So we have to wait as long as we want the effect to go on.
After the effect is gone we disconnect our application from the keyboard with the
LogiLedShutdown function (line 54)

Thats the hole program!

Step 5

Now we have to add a "Strong name" to our dll. This is done by rightclicking the project.

and go to properties.

This should pop up.

On the left go to "Signing" and tick the box "Sign the assembly"

In the drop down menu choose <new..>

Choose a name and disable the "protect my keyfile with a password".
Now you can close the window in the tab menu.

If not done yet save the project. Go to file -> save all.


Make sure that the marked tick box is ticked^^

After that being done. We can build our dll file by rightclicking the project like we did last time
and hit build. You will get an error if Visual Studio is not opened with administrator privileges!

Here is a picture of the complete code:

Now we can close Visual Studio.
Next go to the directory where you saved your project.
(pathtoproject\bin\Debug) There you can find your .dll file.

As the next step we have to register this dll to windows.
This is done by the use of the RegAsm.exe found in:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

Open a command prompt and go to this directory.
After that type:

RegAsm.exe pathtoproject\bin\Debug\name.dll /codebase

This registers the dll in windows. If you want to remove the registration type:

RegAsm.exe pathtoproject\bin\Debug\name.dll /u

To check everthing worked open regedit.exe.
There you press Ctrl+f to start a search. Put in there the ClassID from the beginning.

It should show something like this:

There you can see the path where the dll is located.

Starting with VBScript

Create a new file and add .vbs as the format.
Open that file with an editor like Notepad++
and write in there:

dim logi
set logi = CreateObject(LogitechDll.LogitechDll) 'or parameter that is shown in the registry under Class
logi.LogiLed "blue",3000

First we create a new variable called logi. After that we set it as a new object from the dll.
At this point we can access the functions inside the dll.
Then we call the function LogiLed and pass the string that defines the color and the time how
long the effect should be shown.
Make sure the LogitechLedEnginesWrapper.dll is in the same directory as the .vbs file!

If you run this file it should look like this:

And thats it!

You created your own "bridge" between a native dll and VBScript, if you dont want to make everything by yourself you can use the files i build and uploaded!

You can download the project files here.

Blinkit can be downloaded here.

I hope everything is easy to follow, and if anything is unclear please let me know in the comments or on the github project page.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

I am afraid that your contribution cannot be accepted because it does not follow the rules:

  1. Outdated or low quality code (such as containing the local file path) will lead to rejection.
  2. Trivial code snippets, example code or simple templates will not be accepted.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @justyy, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Thank you for helping and contributing to the Blinkit project, and for adjusting your code, to make it prepared for Blinkit. It was a lot of fun getting in touch, and your a very fast programmer, and i hope to see more contributions from you in the future.

The new interface for Blinkit is worked on and unfinished but it's going well, and i'm looking forward to have it all in place and functional, Thanks again for your help.

another fantastic way to receive notifications with Blinkit !! This really shows how Blinkit is flexible and awesome !! more to come soon with new integrations (by me) and new interface (by @techtek). Let's make the world blink with Blinkit

Congratulations This post has been upvoted by SteemMakers. We are a community-based project that aims to support makers and DIYers on the blockchain in every way possible.

Join our Discord Channel to connect with us and nominate your own or somebody else's posts in our review channel.

Help us to reward you for making it ! Join our voting trail or delegate steem power to the community account.

Your post is also presented on the community website www.steemmakers.com where you can find other selected content.

If you like our work, please consider upvoting this comment to support the growth of our community. Thank you.
Loading...

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64104.40
ETH 3148.52
USDT 1.00
SBD 4.25