Blinkit v2.3 | Blink Logitech devices on Steem actions (backend)

in #utopian-io7 years ago (edited)

<p dir="auto"><span>After getting to know the project and it's owner (<a href="/@techtek">@techtek), i became very excited to work on integrating the work i did to the blinkit project, specialy because the Logitech products are world wide sold and it's probably the most famous brand for keyboards and mice, so it would be wonderful to add it to the Blinkit project. This first integration provide the basic functions but more settings will be added in the future. <p dir="auto">  <h2>What is Blinkit? <p dir="auto">Blinkit is a notification software that can be used to give to regular and widely available devices a Steem purpose. <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/PVPmqV7.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/PVPmqV7.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/PVPmqV7.png 2x" /> <p dir="auto">  <h3>Supported devices/features: <ul> <li>USB Sticks (status light) <li>Philips HUE lamps <li>Sonoff devices <li>Arduino boards (LED's and RGB LED's) <li>Camera status LED blink <li>Take photos on upvote/post/follow <li>Logitech RGB/Backlight Keyboards (new) <p dir="auto"><br /> and can be downloaded from his Github page:<br /><span>Blinkit is a free and open source project created by <a href="/@techtek">@techtek<span> <a href="https://github.com/techtek/Blinkit" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/techtek/Blinkit <p dir="auto">  <p dir="auto"><img src="https://images.hive.blog/0x0/https://assets.logitech.com/assets/64562/88/rgb.gif" /> <p dir="auto">  <h2>New features: <ul> <li>Blink your Logitech RGB/Backlight devices on new upvotes, follows, posts <li>The colors and the number how often the keyboard should blink<br /> can be set for each event individually <li>Also the delay between the keyboard turn on and off can be set <li>To make it compatible to every setup the path to the logitech driver can be changed <p dir="auto">  <h2>Requirements <p dir="auto">To be able to use this new feature it is necessary to have a Logitech device which has either rgb or normal light.<br /> Also you need to have the Logitech Gaming Software installed. <a href="http://support.logitech.com/de_ch/software/lgs" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Download <h3>Compatible Logitech products <p dir="auto">The following Logitech devices are supported:<br /> <em>Keyboards <ul> <li>G910 Orion Spark <li>G810 Orion Spectrum <li>G610 Orion Brown <li>G710+ <li>G510/ G510s <li>G110 <li>G19 / G19s <li>G105 / G105 Call Of Duty <li>G11 <li>G13 <li>G15 v1 / v2 <p dir="auto"><em>Mice <ul> <li>G600 <li>G300 <li>G900 Chaos Spectrum <li>G303 Daedalus Apex <p dir="auto"><em>Headsets <ul> <li>G633 & G933 <p dir="auto">  <p dir="auto"><img src="https://images.hive.blog/0x0/https://i.imgur.com/3Oq4zTx.gif" /> <p dir="auto"> <br />   <h2>How is it implemented <p dir="auto">What the code does is that it reads all information it needs from there related config .txt files, which are created, modified and used by the main program and translated into commands to make the supported device blink. <p dir="auto">To make the device blink, the program has to: <ul> <li>connect to the keyboard <li>turn on and off the colors -> make it blink <li>disconnect <p dir="auto">Logitech provides functions in a Dll called "LogitechLed.dll".<br /> The dll can be found in the installation directory of the Logitech Gaming Software<br /> (Standard: C:\Program Files\Logitech Gaming Software\SDK\LED\x86) <p dir="auto">But it would make no sense to hardcode the path into the program because everyone can have the software installed in a different location.<br /> So what the program does it firstly declares a function from the "kernel32" library<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/kcRgxIp.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/kcRgxIp.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/kcRgxIp.png 2x" /> <p dir="auto">The "SetDllDirectoryA" function adds the given path to a list in which windows tries to find the dll it wants to load. <p dir="auto">The path will be added in the main function. <p dir="auto">To get the functions from the LogitechLed.dll the Dllimport function from the System.Runtime.InteropServices library has to be used.<br /> <em>The LogitechLed.dll is not a .net compiled dll<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/CDFf3Fa.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/CDFf3Fa.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/CDFf3Fa.png 2x" /> <p dir="auto">In these lines of code we first specify the name of the .dll. See there is no path given because the path has been added before with the "SetDllDirectoryA" function. <p dir="auto"><em>But why the path is not directly put into this function you may ask.<br /> Sure it works, but only if the path is a constant... But I want the path to be read out of a file. If done like this there is an error: <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/3W7I2Fw.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/3W7I2Fw.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/3W7I2Fw.png 2x" /> <p dir="auto">Next we have to specify the function with name, parameters and return values. <p dir="auto">These information can also be found in the SDK. <p dir="auto">In addition a new Thread is created to make the form and the main logic run seperatly <pre><code>Private trd As Thread <p dir="auto">Also two Handles have to be made to get the information if the form is loaded and closed<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/mJoEdZi.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/mJoEdZi.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/mJoEdZi.png 2x" /> <p dir="auto">The MyBase.Load handle only starts the new thread with the main function ("Logi"). The MyBase.Closed kills the thread so it can be canceled everytime. <p dir="auto">Thats all about the preparatory work. The code now looks like this: <pre><code>Imports System.Runtime.InteropServices Imports System.Threading Public Class Form1 '------------------------- ' Import the functions needed in the project ' from the logitech driver dll '------------------------- <DllImport("LogitechLed.dll")> Public Shared Function LogiLedInit() As Boolean End Function <DllImport("LogitechLed.dll")> Public Shared Function LogiLedShutdown() As Boolean End Function <DllImport("LogitechLed.dll")> Public Shared Function LogiLedSetLighting(ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer) As Boolean End Function ' Load function from the kernel32 library to set the path to the dll used ' because the dll from the Logitech driver can be installed in different ' locations. Public Declare Function SetDllDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long '------------------------- ' Define new Thread '------------------------- Private trd As Thread '------------------------- ' Function that fires when the form gets loaded '------------------------- Private Sub Form1_load(sender As Object, e As EventArgs) Handles MyBase.Load '------------------------- ' After the Label and Picturebox is shown ' A new thread is started running ' the main program ' (fixes a bug where the label and picturebox does not show up) '------------------------- trd = New Thread(AddressOf Logi) trd.Start() End Sub '------------------------- ' Function that fires when the form gets closed '------------------------- Private Sub Form1_close(sender As Object, e As EventArgs) Handles MyBase.Closed '------------------------- ' Thread has to be terminated after the form gets closed ' else it would run further '------------------------- trd.Abort() End Sub <p dir="auto">  <h2>Main logic <p dir="auto">Firstly all used variables have to be defined (sorted by type):<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/aXMSC3n.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/aXMSC3n.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/aXMSC3n.png 2x" /> <p dir="auto">After that the variables need to be initialized<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/tL5so2G.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/tL5so2G.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/tL5so2G.png 2x" /> <p dir="auto">All values are stored in a separate txt file created by the BlinkIT software. <p dir="auto">The "color" variable holds a string with the rgb values devided with spaces and each value is always three digits long.<br /> e.g.: 255 005 200 <p dir="auto">The next step is to get the r,g and b values seperatly <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/gImC5lM.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/gImC5lM.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/gImC5lM.png 2x" /> <p dir="auto">As shown in the documentation the function to set the color "LogiLedSetLighting" of the keyboard takes values from 0 to 100 (% of brightness instead of rgb values). So we have to convert them.<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/7O1ScB9.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/7O1ScB9.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/7O1ScB9.png 2x" /> <p dir="auto">Before be able to work with the keyboard the "SetDllDirectoryA" function is called with the "path" parameter read from the txt file before. So now everytime a function from the LogitechLed.dll is called and the dll hasn't been loaded already it checks the "path" first. <p dir="auto">  <h2>Start controlling the keyboard <p dir="auto">First the program initialises the keyboard. <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/5MbpVmk.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/5MbpVmk.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/5MbpVmk.png 2x" /> <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/WAIqWUC.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/WAIqWUC.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/WAIqWUC.png 2x" /> <p dir="auto"><em>Main blink logic. Pseudocode describes what it does exactly <p dir="auto">At the end the connection is shut down and the program gets closed.<br /> <img src="https://images.hive.blog/768x0/https://i.imgur.com/rliAddz.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/rliAddz.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/rliAddz.png 2x" /> <p dir="auto">The hole code as one piece can be seen and downloaded on my <a href="https://github.com/flash4yard/blinkit-logitechRGB-integration" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">github page <p dir="auto">  <h2>Testing the code while developing it <p dir="auto">I own the Logitech G510 RGB keyboard and tested it only with this model while creating the software. <p dir="auto">But the Logitech Gaming Software features a virtual keyboard: <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/Q5vTyxd.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/Q5vTyxd.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/Q5vTyxd.png 2x" /> <ol> <li><p dir="auto">rgb keyboard where every single key can be set to a specific color. <li><p dir="auto">normal rgb keyboard (all keys have the same color) <li><p dir="auto">monochrome keyboard (it features only one color and three different levels of brightness)<br /> -> LogiLedSetLighting works with this kind of keyboards too. (See documentation) <p dir="auto">If you have this window open and run the program the changes can be seen on all different keyboards. So even if you dont own all different kinds of keyboards you can test the program. <p dir="auto">  <h2>Collaboration, and testing tuning <p dir="auto">To make sure the made code is working as expected the final work is tested on 4 different systems and with 3 different keyboards.<br /><span> One of them was from <a href="/@dmxmaster">@dmxmaster. Thanks to him. <p dir="auto"><span>The blink values presented to the user are tested and adjusted in collaboration with <a href="/@techtek">@techtek to have logical and usefull values. The RGB colors are tuned to present the most real colour acording to there name. <p dir="auto">It took us quite some time to get everything working (frontend, backend testing supported devices, fixing bugs).<br /> In a previous post <a href="https://steemit.com/utopian-io/@flash4yard/blinkit-or-logitech-rgb-keyboard-preparation" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here I made the first attempt to get it working.<br /> But now around one month later I made it almost completely new.<br /> Added all functions needed and the feature to control the color, no. of blinks and the delay as required for this integration. And this is not where we will stop more is on the planning already suchs as, display text on the already supported logitech devices that have a display, add a color picker, and a fading effect. <p dir="auto">  <h2>The following files where added to my repository <ul> <li><a href="https://github.com/flash4yard/blinkit-logitechRGB-integration/blob/master/Logitechblink.exe" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Logitechblink.exe <li><a href="https://github.com/flash4yard/blinkit-logitechRGB-integration/tree/master/config" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">config <li><a href="https://github.com/flash4yard/blinkit-logitechRGB-integration/blob/master/README.md" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">readme <li><a href="https://github.com/flash4yard/blinkit-logitechRGB-integration/blob/master/LICENSE" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">license <li><a href="https://github.com/flash4yard/blinkit-logitechRGB-integration/tree/master/LogitechBlinkit%20Project%20files" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">source code/ project files <p dir="auto"><a href="https://github.com/techtek/Blinkit" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">repository<span>The logitechblink.exe code is also used and compiled by <a href="/@techtek">@techtek and added to his Blinkit <h2>The new interface <p dir="auto"><img src="https://images.hive.blog/768x0/https://i.imgur.com/RBAbOxO.png" srcset="https://images.hive.blog/768x0/https://i.imgur.com/RBAbOxO.png 1x, https://images.hive.blog/1536x0/https://i.imgur.com/RBAbOxO.png 2x" /> <h2>Example blink (looped) <p dir="auto"><img src="https://images.hive.blog/0x0/https://i.imgur.com/HHimTgI.gif" />
Sort: